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

Keeps a map from IDs to T objects, such as XXNode. More...

#include <SVFFileSystem.h>

Public Member Functions

template<typename IdObjCreator >
void createObjs (const cJSON *idObjArrayJson, IdObjCreator idObjCreator)
 idObjcreator : (const cJSON*) -> (id, T*) with id set More...
 
T * getPtr (unsigned id) const
 
template<typename FillFunc >
void fillObjs (FillFunc fillFunc)
 
size_t size () const
 
template<typename Map >
void saveToIDToObjMap (Map &idToObjMap) const
 

Private Types

using IDToPairMapTy = OrderedMap< unsigned, std::pair< const cJSON *, T * > >
 

Private Attributes

IDToPairMapTy idMap
 

Detailed Description

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

Keeps a map from IDs to T objects, such as XXNode.

Template Parameters
TThe type of the objects.

Definition at line 684 of file SVFFileSystem.h.

Member Typedef Documentation

◆ IDToPairMapTy

template<typename T >
using SVF::ReaderIDToObjMap< T >::IDToPairMapTy = OrderedMap<unsigned, std::pair<const cJSON*, T*> >
private

Definition at line 687 of file SVFFileSystem.h.

Member Function Documentation

◆ createObjs()

template<typename T >
template<typename IdObjCreator >
void SVF::ReaderIDToObjMap< T >::createObjs ( const cJSON idObjArrayJson,
IdObjCreator  idObjCreator 
)
inline

idObjcreator : (const cJSON*) -> (id, T*) with id set

Definition at line 693 of file SVFFileSystem.h.

694  {
695  assert(idMap.empty() &&
696  "idToObjMap should be empty when creating objects");
697  ABORT_IFNOT(jsonIsArray(idObjArrayJson), "expects an array");
698 
699  jsonForEach(objJson, idObjArrayJson)
700  {
701  ABORT_IFNOT(jsonIsObject(objJson), "expects an object");
702  const cJSON* objFieldJson = objJson->child;
703  // creator is allowed to change objFieldJson
704  auto idObj = idObjCreator(objFieldJson);
705  auto pair = std::pair<const cJSON*, T*>(objFieldJson, idObj.second);
706  bool inserted = idMap.emplace(idObj.first, pair).second;
707  ABORT_IFNOT(inserted, "ID " << idObj.first << " duplicated in "
708  << idObjArrayJson->string);
709  }
710  }
#define jsonForEach(field, array)
#define ABORT_IFNOT(condition, reason)
Definition: SVFFileSystem.h:39
bool jsonIsArray(const cJSON *item)
bool jsonIsObject(const cJSON *item)
Definition: cJSON.h:104
struct cJSON * child
Definition: cJSON.h:109
char * string
Definition: cJSON.h:122

◆ fillObjs()

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

Definition at line 719 of file SVFFileSystem.h.

720  {
721  for (auto& pair : idMap)
722  {
723  const cJSON* objFieldJson = pair.second.first;
724  T* obj = pair.second.second;
725  fillFunc(objFieldJson, obj);
726 
727  ABORT_IFNOT(!objFieldJson, "json should be consumed by filler, but "
728  << objFieldJson->string << " left");
729  }
730  }

◆ getPtr()

template<typename T >
T* SVF::ReaderIDToObjMap< T >::getPtr ( unsigned  id) const
inline

Definition at line 712 of file SVFFileSystem.h.

713  {
714  auto it = idMap.find(id);
715  ABORT_IFNOT(it != idMap.end(), "ID " << id << " not found");
716  return it->second.second;
717  }

◆ saveToIDToObjMap()

template<typename T >
template<typename Map >
void SVF::ReaderIDToObjMap< T >::saveToIDToObjMap ( Map idToObjMap) const
inline

Definition at line 737 of file SVFFileSystem.h.

738  {
739  for (auto& pair : idMap)
740  {
741  unsigned id = pair.first;
742  T* obj = pair.second.second;
743  assert(obj && "obj should not be null");
744  idToObjMap.insert(std::make_pair(id, obj));
745  }
746  }

◆ size()

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

Definition at line 732 of file SVFFileSystem.h.

733  {
734  return idMap.size();
735  }

Member Data Documentation

◆ idMap

template<typename T >
IDToPairMapTy SVF::ReaderIDToObjMap< T >::idMap
private

Definition at line 688 of file SVFFileSystem.h.


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