/* * file: ssstore.cpp * * Created on: Oct 3, 2009 * Author: mike */ #include #include "stringstore.hpp" StringStore* StringStore::instance = NULL; // initialization // Gets unique instance of the string store, creating it // if it doesn't already exist StringStore& StringStore::getStore() { if (instance==NULL) instance = new StringStore; return *instance; } //---------------------------------------------------------------------------- // Constructs new const null-terminated string from first len characters of s, // places it in the StringStore repository, and returns pointer to it. // Repository owns the new string and is responsible for its eventual deletion. const char* StringStore::put(const char* s, int len) { len++; // number of characters including '\0'. if (len > remain) throw "Sorry, string too long for string store"; char* where = &letters[next]; next += len; remain -= len; strncpy(where, s, len - 1); where[len - 1] = '\0'; return where; }