Static Value-Flow Analysis
Public Member Functions | Private Attributes | List of all members
SVF::ReaderPtrPool< T > Class Template Reference

Reverse of WriterPtrPool where T is object type without ID field. More...

#include <SVFFileSystem.h>

Public Member Functions

void reserve (size_t size)
 
template<typename Creator >
void createObjs (const cJSON *objArrayJson, Creator creator)
 
T * getPtr (size_t id) const
 
template<typename FillFunc >
void fillObjs (FillFunc fillFunc)
 
size_t size () const
 
template<typename Set >
void saveToSet (Set &set) const
 

Private Attributes

std::vector< const cJSON * > jsonArray
 
std::vector< T * > ptrPool
 

Detailed Description

template<typename T>
class SVF::ReaderPtrPool< T >

Reverse of WriterPtrPool where T is object type without ID field.

Template Parameters
T

Definition at line 751 of file SVFFileSystem.h.

Member Function Documentation

◆ createObjs()

template<typename T >
template<typename Creator >
void SVF::ReaderPtrPool< T >::createObjs ( const cJSON objArrayJson,
Creator  creator 
)
inline
Template Parameters
Creator
Parameters
objArrayJson
creator

Definition at line 769 of file SVFFileSystem.h.

770  {
771  assert(jsonArray.empty() &&
772  "jsonArray should be empty when creating objects");
773  ABORT_IFNOT(jsonIsArray(objArrayJson), "expects an array");
774 
775  jsonForEach(objJson, objArrayJson)
776  {
777  ABORT_IFNOT(jsonIsObject(objJson), "expects objects in array");
778  const cJSON* objFieldJson = objJson->child;
779  T* obj = creator(objFieldJson);
780  jsonArray.push_back(objFieldJson);
781  ptrPool.push_back(obj);
782  }
783  }
#define jsonForEach(field, array)
#define ABORT_IFNOT(condition, reason)
Definition: SVFFileSystem.h:39
std::vector< T * > ptrPool
std::vector< const cJSON * > jsonArray
bool jsonIsArray(const cJSON *item)
bool jsonIsObject(const cJSON *item)
Definition: cJSON.h:104
struct cJSON * child
Definition: cJSON.h:109

◆ fillObjs()

template<typename T >
template<typename FillFunc >
void SVF::ReaderPtrPool< T >::fillObjs ( FillFunc  fillFunc)
inline

Definition at line 792 of file SVFFileSystem.h.

793  {
794  assert(jsonArray.size() == ptrPool.size() &&
795  "jsonArray and ptrPool should have same size");
796  for (size_t i = 0; i < jsonArray.size(); ++i)
797  {
798  const cJSON*& objFieldJson = jsonArray[i];
799  fillFunc(objFieldJson, ptrPool[i]);
800  ABORT_IFNOT(!objFieldJson, "json should be consumed by filler, but "
801  << objFieldJson->string << " left");
802  }
803  jsonArray.clear();
804  jsonArray.shrink_to_fit();
805  }
char * string
Definition: cJSON.h:122

◆ getPtr()

template<typename T >
T* SVF::ReaderPtrPool< T >::getPtr ( size_t  id) const
inline

Definition at line 785 of file SVFFileSystem.h.

786  {
787  ABORT_IFNOT(id <= ptrPool.size(),
788  "Invalid ID " << id << ". Max ID = " << ptrPool.size());
789  return id ? ptrPool[id - 1] : nullptr;
790  }

◆ reserve()

template<typename T >
void SVF::ReaderPtrPool< T >::reserve ( size_t  size)
inline

Definition at line 758 of file SVFFileSystem.h.

759  {
760  jsonArray.reserve(size);
761  ptrPool.reserve(size);
762  }
size_t size() const

◆ saveToSet()

template<typename T >
template<typename Set >
void SVF::ReaderPtrPool< T >::saveToSet ( Set set) const
inline

Definition at line 812 of file SVFFileSystem.h.

813  {
814  for (T* obj : ptrPool)
815  {
816  set.insert(obj);
817  }
818  }
set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) add_llvm_executable(wpa wpa.cpp) target_link_libraries(wpa PUBLIC $
Definition: CMakeLists.txt:1

◆ size()

template<typename T >
size_t SVF::ReaderPtrPool< T >::size ( ) const
inline

Definition at line 807 of file SVFFileSystem.h.

808  {
809  return ptrPool.size();
810  }

Member Data Documentation

◆ jsonArray

template<typename T >
std::vector<const cJSON*> SVF::ReaderPtrPool< T >::jsonArray
private

Definition at line 754 of file SVFFileSystem.h.

◆ ptrPool

template<typename T >
std::vector<T*> SVF::ReaderPtrPool< T >::ptrPool
private

Definition at line 755 of file SVFFileSystem.h.


The documentation for this class was generated from the following file: