Skip to content

Commit

Permalink
code-format (large diff because of code moved to a namespace)
Browse files Browse the repository at this point in the history
  • Loading branch information
smorovic committed May 16, 2024
1 parent 1617a60 commit 0d93dfb
Show file tree
Hide file tree
Showing 10 changed files with 3,124 additions and 3,124 deletions.
2 changes: 1 addition & 1 deletion EventFilter/Utilities/interface/EvFDaqDirector.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace jsoncollector {
namespace Json {
class Value;
}
}
} // namespace jsoncollector

namespace edm {
class ConfigurationDescriptions;
Expand Down
34 changes: 17 additions & 17 deletions EventFilter/Utilities/interface/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,40 @@
#include "forwards.h"

namespace jsoncollector {
namespace Json {
namespace Json {

/** \brief Configuration passed to reader and writer.
/** \brief Configuration passed to reader and writer.
* This configuration object can be used to force the Reader or Writer
* to behave in a standard conforming way.
*/
class JSON_API Features {
public:
/** \brief A configuration that allows all features and assumes all strings are UTF-8.
class JSON_API Features {
public:
/** \brief A configuration that allows all features and assumes all strings are UTF-8.
* - C & C++ comments are allowed
* - Root object can be any JSON value
* - Assumes Value strings are encoded in UTF-8
*/
static Features all();
static Features all();

/** \brief A configuration that is strictly compatible with the JSON specification.
/** \brief A configuration that is strictly compatible with the JSON specification.
* - Comments are forbidden.
* - Root object must be either an array or an object value.
* - Assumes Value strings are encoded in UTF-8
*/
static Features strictMode();
static Features strictMode();

/** \brief Initialize the configuration like JsonConfig::allFeatures;
/** \brief Initialize the configuration like JsonConfig::allFeatures;
*/
Features();
Features();

/// \c true if comments are allowed. Default: \c true.
bool allowComments_;
/// \c true if comments are allowed. Default: \c true.
bool allowComments_;

/// \c true if root must be either an array or an object value. Default: \c false.
bool strictRoot_;
};
/// \c true if root must be either an array or an object value. Default: \c false.
bool strictRoot_;
};

} // namespace Json
} // namespace jsoncollector
} // namespace Json
} // namespace jsoncollector

#endif // CPPTL_JSON_FEATURES_H_INCLUDED
58 changes: 29 additions & 29 deletions EventFilter/Utilities/interface/forwards.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@
#include "config.h"

namespace jsoncollector {
namespace Json {

// writer.h
class FastWriter;
class StyledWriter;

// reader.h
class Reader;

// features.h
class Features;

// value.h
typedef int Int;
typedef unsigned int UInt;
class StaticString;
class Path;
class PathArgument;
class Value;
class ValueIteratorBase;
class ValueIterator;
class ValueConstIterator;
namespace Json {

// writer.h
class FastWriter;
class StyledWriter;

// reader.h
class Reader;

// features.h
class Features;

// value.h
typedef int Int;
typedef unsigned int UInt;
class StaticString;
class Path;
class PathArgument;
class Value;
class ValueIteratorBase;
class ValueIterator;
class ValueConstIterator;
#ifdef JSON_VALUE_USE_INTERNAL_MAP
class ValueAllocator;
class ValueMapAllocator;
class ValueInternalLink;
class ValueInternalArray;
class ValueInternalMap;
class ValueAllocator;
class ValueMapAllocator;
class ValueInternalLink;
class ValueInternalArray;
class ValueInternalMap;
#endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP

} // namespace Json
} // namespace jsoncollector
} // namespace Json
} // namespace jsoncollector

#endif // JSON_FORWARDS_H_INCLUDED
162 changes: 81 additions & 81 deletions EventFilter/Utilities/interface/json_batchallocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION

namespace jsoncollector {
namespace Json {
namespace Json {

/* Fast memory allocator.
/* Fast memory allocator.
*
* This memory allocator allocates memory for a batch of object (specified by
* the page size, the number of object in each page).
Expand All @@ -21,93 +21,93 @@ namespace Json {
* The in-place new operator must be used to construct the object using the pointer
* returned by allocate.
*/
template <typename AllocatedType, const unsigned int objectPerAllocation>
class BatchAllocator {
public:
typedef AllocatedType Type;

BatchAllocator(unsigned int objectsPerPage = 255) : freeHead_(0), objectsPerPage_(objectsPerPage) {
// printf( "Size: %d => %s\n", sizeof(AllocatedType), typeid(AllocatedType).name() );
assert(sizeof(AllocatedType) * objectPerAllocation >=
sizeof(AllocatedType *)); // We must be able to store a slist in the object free space.
assert(objectsPerPage >= 16);
batches_ = allocateBatch(0); // allocated a dummy page
currentBatch_ = batches_;
}

~BatchAllocator() {
for (BatchInfo *batch = batches_; batch;) {
BatchInfo *nextBatch = batch->next_;
free(batch);
batch = nextBatch;
template <typename AllocatedType, const unsigned int objectPerAllocation>
class BatchAllocator {
public:
typedef AllocatedType Type;

BatchAllocator(unsigned int objectsPerPage = 255) : freeHead_(0), objectsPerPage_(objectsPerPage) {
// printf( "Size: %d => %s\n", sizeof(AllocatedType), typeid(AllocatedType).name() );
assert(sizeof(AllocatedType) * objectPerAllocation >=
sizeof(AllocatedType *)); // We must be able to store a slist in the object free space.
assert(objectsPerPage >= 16);
batches_ = allocateBatch(0); // allocated a dummy page
currentBatch_ = batches_;
}
}

/// allocate space for an array of objectPerAllocation object.
/// @warning it is the responsability of the caller to call objects constructors.
AllocatedType *allocate() {
if (freeHead_) // returns node from free list.
{
AllocatedType *object = freeHead_;
freeHead_ = *(AllocatedType **)object;
return object;

~BatchAllocator() {
for (BatchInfo *batch = batches_; batch;) {
BatchInfo *nextBatch = batch->next_;
free(batch);
batch = nextBatch;
}
}
if (currentBatch_->used_ == currentBatch_->end_) {
currentBatch_ = currentBatch_->next_;
while (currentBatch_ && currentBatch_->used_ == currentBatch_->end_)
currentBatch_ = currentBatch_->next_;

if (!currentBatch_) // no free batch found, allocate a new one
/// allocate space for an array of objectPerAllocation object.
/// @warning it is the responsability of the caller to call objects constructors.
AllocatedType *allocate() {
if (freeHead_) // returns node from free list.
{
currentBatch_ = allocateBatch(objectsPerPage_);
currentBatch_->next_ = batches_; // insert at the head of the list
batches_ = currentBatch_;
AllocatedType *object = freeHead_;
freeHead_ = *(AllocatedType **)object;
return object;
}
if (currentBatch_->used_ == currentBatch_->end_) {
currentBatch_ = currentBatch_->next_;
while (currentBatch_ && currentBatch_->used_ == currentBatch_->end_)
currentBatch_ = currentBatch_->next_;

if (!currentBatch_) // no free batch found, allocate a new one
{
currentBatch_ = allocateBatch(objectsPerPage_);
currentBatch_->next_ = batches_; // insert at the head of the list
batches_ = currentBatch_;
}
}
AllocatedType *allocated = currentBatch_->used_;
currentBatch_->used_ += objectPerAllocation;
return allocated;
}
AllocatedType *allocated = currentBatch_->used_;
currentBatch_->used_ += objectPerAllocation;
return allocated;
}

/// Release the object.
/// @warning it is the responsability of the caller to actually destruct the object.
void release(AllocatedType *object) {
assert(object != 0);
*(AllocatedType **)object = freeHead_;
freeHead_ = object;
}

// disabled copy constructor and assignement operator.
BatchAllocator(const BatchAllocator &) = delete;
void operator=(const BatchAllocator &) = delete;

private:
struct BatchInfo {
BatchInfo *next_;
AllocatedType *used_;
AllocatedType *end_;
AllocatedType buffer_[objectPerAllocation];

/// Release the object.
/// @warning it is the responsability of the caller to actually destruct the object.
void release(AllocatedType *object) {
assert(object != 0);
*(AllocatedType **)object = freeHead_;
freeHead_ = object;
}

// disabled copy constructor and assignement operator.
BatchAllocator(const BatchAllocator &) = delete;
void operator=(const BatchAllocator &) = delete;

private:
struct BatchInfo {
BatchInfo *next_;
AllocatedType *used_;
AllocatedType *end_;
AllocatedType buffer_[objectPerAllocation];
};

static BatchInfo *allocateBatch(unsigned int objectsPerPage) {
const unsigned int mallocSize = sizeof(BatchInfo) - sizeof(AllocatedType) * objectPerAllocation +
sizeof(AllocatedType) * objectPerAllocation * objectsPerPage;
BatchInfo *batch = static_cast<BatchInfo *>(malloc(mallocSize));
batch->next_ = 0;
batch->used_ = batch->buffer_;
batch->end_ = batch->buffer_ + objectsPerPage;
return batch;
}

BatchInfo *batches_;
BatchInfo *currentBatch_;
/// Head of a single linked list within the allocated space of freeed object
AllocatedType *freeHead_;
unsigned int objectsPerPage_;
};

static BatchInfo *allocateBatch(unsigned int objectsPerPage) {
const unsigned int mallocSize = sizeof(BatchInfo) - sizeof(AllocatedType) * objectPerAllocation +
sizeof(AllocatedType) * objectPerAllocation * objectsPerPage;
BatchInfo *batch = static_cast<BatchInfo *>(malloc(mallocSize));
batch->next_ = 0;
batch->used_ = batch->buffer_;
batch->end_ = batch->buffer_ + objectsPerPage;
return batch;
}

BatchInfo *batches_;
BatchInfo *currentBatch_;
/// Head of a single linked list within the allocated space of freeed object
AllocatedType *freeHead_;
unsigned int objectsPerPage_;
};

} // namespace Json
} //namespace jsoncollector
} // namespace Json
} //namespace jsoncollector

#endif // ifndef JSONCPP_DOC_INCLUDE_IMPLEMENTATION

Expand Down
Loading

0 comments on commit 0d93dfb

Please sign in to comment.