The Sparta Modeling Framework
Loading...
Searching...
No Matches
sparta::StringManager Class Reference

Manages string internment for SPARTA. This allows strings to be compared by pointer once interned. More...

#include <StringManager.hpp>

Public Types

using StringUniquePtr = std::unique_ptr< std::string, Deleter >
 Mapping of strings to their addresses.
 
typedef std::map< std::string, StringUniquePtrStringMap
 

Public Member Functions

 StringManager ()
 Constructor.
 
std::string * internString (const std::string &s)
 Stores a string in shared space within this manager unless it is already stored.
 
std::string * findString (const std::string &s) const
 Find a string in this manager.
 
bool hasString (const std::string &s) const
 Checks to see if a string is present without adding it.
 
bool isInterned (const std::string *s) const
 Determines if a string is interned in this string manager by its pointer.
 
void dumpStrings (std::ostream &o, bool pretty=false) const
 Write all strings interned in the string manager to an ostream.
 
uint32_t getNumStrings () const
 Gets the number of strings in this StringManager.
 

Static Public Member Functions

static StringManagergetStringManager ()
 Returns the StringManager singleton.
 

Public Attributes

StringMap string_map_
 Mapping of ID to string for getting the string associated with this ID. Allows lookup with a string from anywhere to see if any equivalent string are in this manager.
 
uint32_t max_string_len_
 Maximum string length held by the StringManager.
 
const uint64_t is_constructed
 Has this singleton been constructed yet. Yes if equal to IS_CONSTRUCTED_CONST.
 
const std::string *const EMPTY
 Holds interned empty strings.
 

Static Public Attributes

static const uint64_t IS_CONSTRUCTED_CONST = 0x0123456789abcdef
 Value of is_constructed after construction.
 

Friends

class SpartaStaticInitializer
 Allow initialization of statics through this helper.
 

Detailed Description

Manages string internment for SPARTA. This allows strings to be compared by pointer once interned.

Definition at line 22 of file StringManager.hpp.

Member Typedef Documentation

◆ StringMap

typedef std::map<std::string, StringUniquePtr> sparta::StringManager::StringMap

Definition at line 98 of file StringManager.hpp.

◆ StringUniquePtr

using sparta::StringManager::StringUniquePtr = std::unique_ptr<std::string, Deleter>

Mapping of strings to their addresses.

Definition at line 97 of file StringManager.hpp.

Constructor & Destructor Documentation

◆ StringManager()

sparta::StringManager::StringManager ( )
inline

Constructor.

Definition at line 122 of file StringManager.hpp.

Member Function Documentation

◆ dumpStrings()

void sparta::StringManager::dumpStrings ( std::ostream &  o,
bool  pretty = false 
) const
inline

Write all strings interned in the string manager to an ostream.

Definition at line 195 of file StringManager.hpp.

◆ findString()

std::string * sparta::StringManager::findString ( const std::string &  s) const
inline

Find a string in this manager.

Returns
Pointer to the interned string if present. If not already interned, returns nullptr

Definition at line 157 of file StringManager.hpp.

◆ getNumStrings()

uint32_t sparta::StringManager::getNumStrings ( ) const
inline

Gets the number of strings in this StringManager.

Definition at line 213 of file StringManager.hpp.

◆ getStringManager()

static StringManager & sparta::StringManager::getStringManager ( )
inlinestatic

Returns the StringManager singleton.

Note
This method is valid until static destruction

Definition at line 224 of file StringManager.hpp.

◆ hasString()

bool sparta::StringManager::hasString ( const std::string &  s) const
inline

Checks to see if a string is present without adding it.

Returns
true if string is interned and false if not.

Definition at line 171 of file StringManager.hpp.

Here is the call graph for this function:

◆ internString()

std::string * sparta::StringManager::internString ( const std::string &  s)
inline

Stores a string in shared space within this manager unless it is already stored.

Returns
pointer to interned string equivalent to the given string string. Never returns nullptr;
Parameters
sstring to intern. Can be anything
Postcondition
s will be interned if not already interned.

Definition at line 138 of file StringManager.hpp.

Here is the call graph for this function:

◆ isInterned()

bool sparta::StringManager::isInterned ( const std::string *  s) const
inline

Determines if a string is interned in this string manager by its pointer.

Returns
true if string is interned with this pointer
Note
this is a slow method since it iterates the entire internal map

Definition at line 181 of file StringManager.hpp.

Friends And Related Symbol Documentation

◆ SpartaStaticInitializer

friend class SpartaStaticInitializer
friend

Allow initialization of statics through this helper.

Definition at line 92 of file StringManager.hpp.

Member Data Documentation

◆ EMPTY

const std::string* const sparta::StringManager::EMPTY

Holds interned empty strings.

Definition at line 218 of file StringManager.hpp.

◆ is_constructed

const uint64_t sparta::StringManager::is_constructed

Has this singleton been constructed yet. Yes if equal to IS_CONSTRUCTED_CONST.

Definition at line 112 of file StringManager.hpp.

◆ IS_CONSTRUCTED_CONST

const uint64_t sparta::StringManager::IS_CONSTRUCTED_CONST = 0x0123456789abcdef
static

Value of is_constructed after construction.

Definition at line 117 of file StringManager.hpp.

◆ max_string_len_

uint32_t sparta::StringManager::max_string_len_

Maximum string length held by the StringManager.

Definition at line 106 of file StringManager.hpp.

◆ string_map_

StringMap sparta::StringManager::string_map_

Mapping of ID to string for getting the string associated with this ID. Allows lookup with a string from anywhere to see if any equivalent string are in this manager.

Definition at line 105 of file StringManager.hpp.


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