Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(DAQ) jsoncpp moved to a namespace (14_0_X backport) #44990

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions EventFilter/Utilities/interface/EvFDaqDirector.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ namespace edm {
class ProcessContext;
} // namespace edm

namespace Json {
class Value;
}

namespace jsoncollector {
class DataPointDefinition;
}

namespace Json {
class Value;
}
} // namespace jsoncollector

namespace edm {
class ConfigurationDescriptions;
Expand Down
34 changes: 18 additions & 16 deletions EventFilter/Utilities/interface/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,41 @@

#include "forwards.h"

namespace Json {
namespace jsoncollector {
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 Json
} // namespace jsoncollector

#endif // CPPTL_JSON_FEATURES_H_INCLUDED
58 changes: 30 additions & 28 deletions EventFilter/Utilities/interface/forwards.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,38 @@

#include "config.h"

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 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;
#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 Json
} // namespace jsoncollector

#endif // JSON_FORWARDS_H_INCLUDED
162 changes: 82 additions & 80 deletions EventFilter/Utilities/interface/json_batchallocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION

namespace Json {
namespace jsoncollector {
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 @@ -20,92 +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 Json
} //namespace jsoncollector

#endif // ifndef JSONCPP_DOC_INCLUDE_IMPLEMENTATION

Expand Down
Loading