24 #include <boost/unordered_set.hpp> 25 #include <boost/thread/mutex.hpp> 26 #include <boost/thread/shared_mutex.hpp> 27 #include <boost/thread/locks.hpp> 46 :
public std::unary_function<StringStorageElement, std::size_t>
59 :
public std::binary_function<string, StringStorageElement, bool>
97 :
public boost::noncopyable
118 emptyString =
nullptr;
139 boost::upgrade_lock<boost::shared_mutex> guard(accessMutex);
141 auto it = storage.find(str, stringStorageElementHasher, stringComperator);
144 if(it == storage.end())
146 boost::upgrade_to_unique_lock<boost::shared_mutex> unique(guard);
159 emptyString = resolveString(
"");
171 boost::unordered_set<StringStorageElement, StringStorageElement::Hasher>
storage;
229 return str() == other;
466 return str() == other;
static StringStorage & Inst()
Returns the Storage.
MaybeCachedString & operator=(const string &str)
Assigns a non cached std string.
Hasher for the StringStorageElement.
bool operator==(const StringStorageElement &other) const
This file is part of alaCarte.
void assign(const string &str)
Assigns a non cached std string.
const StringStorageElement * getEmptyString() const
Returns the storage element for an empty string.
Comparator for comparing STringStorageELements with strings.
~MaybeCachedString()
Destroys this object.
void reset()
deletes rge internal string if it is not cached
const string & str() const
Returns the internal string.
std::size_t operator()(const StringStorageElement &sse) const
static void Shutdown()
Frees all internal memory used by the cache mechanism.
void assign(const string &str)
Assigns a std string.
~CachedString()
Tidies up the cached string.
Represents a string which could be cached into an internal cache.
CachedString()
Cretaes a new Cached string.
const string & str() const
Returns the internal string.
MaybeCachedString()
Returns the internal c string.
void shutdown()
Frees all memory allocated by this storage.
StringStorageElement::StringComparator stringComperator
The comparator for strings and storage elements.
bool equals(const string &other) const
Compares this string with a given std string.
const StringStorageElement * internalString
const StringStorageElement * emptyString
Pointer to the storage element holding the empty string.
const char * c_str() const
Returns the internal c string.
bool isCached() const
Returns weather this string is cached.
StringStorage()
Creates the StringStorage.
const StringStorageElement * resolveString(const string &str)
Returns the storage element for a given string.
boost::unordered_set< StringStorageElement, StringStorageElement::Hasher > storage
internal storage as an hash map
const StringStorageElement * internalString
boost::shared_mutex accessMutex
The mutex used to lock this class.
void clear()
Sets this string to the empty string.
std::size_t hash() const
Returns the internal hash.
bool operator()(const string &str, const StringStorageElement &sse) const
Represents a string which is cached into an internal cache.
const char * c_str() const
Returns the internal c string.
void clear()
Sets this string to be the empty string.
StringStorageElement::Hasher stringStorageElementHasher
The hasher used for StringStorageELements.
StringStorageElement(const string &str)
Creates a new StringStorageELement.
bool equals(const string &other) const
Compares this cached string with an non cached string.
CachedString::StringStorageElement StringStorageElement
Storage class for cached strings.
CachedString & operator=(const string &str)
Assigns a std string.