2013-12-15 18:30:16 -05:00
|
|
|
#ifndef _STRINGCACHE_H_
|
|
|
|
|
#define _STRINGCACHE_H_
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A simple cache that allows for caching the mapping of one string to another calculated one
|
2014-09-24 14:09:08 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @author Mitchell
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
class StringCache {
|
|
|
|
|
private:
|
2014-09-24 14:09:08 -04:00
|
|
|
std::map<std::string, std::string> cache;
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param input
|
|
|
|
|
* @return the value for a given input
|
|
|
|
|
*/
|
|
|
|
|
public:
|
|
|
|
|
StringCache();
|
|
|
|
|
virtual ~StringCache();
|
2014-09-24 14:09:08 -04:00
|
|
|
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
std::string& Get(const std::string& input);
|
2014-09-24 14:09:08 -04:00
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
|
|
|
|
* Will only be called if a value has not already been calculated
|
|
|
|
|
* @param input
|
|
|
|
|
* @return the calculated value for a given input
|
|
|
|
|
*/
|
|
|
|
|
virtual std::string Calc(const std::string& input) = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|