|
|
6e237b |
#pragma once
|
|
|
6e237b |
|
|
|
6e237b |
#ifndef TSTRINGID_INCLUDED
|
|
|
6e237b |
#define TSTRINGID_INCLUDED
|
|
|
6e237b |
|
|
|
6e237b |
#include <tcommon.h></tcommon.h>
|
|
|
6e237b |
|
|
|
6e237b |
#include <string></string>
|
|
|
6e237b |
#include <vector></vector>
|
|
|
6e237b |
#include <map></map>
|
|
|
6e237b |
|
|
|
6e237b |
#undef DVAPI
|
|
|
6e237b |
#undef DVVAR
|
|
|
6e237b |
#ifdef TSTRINGID_EXPORTS
|
|
|
6e237b |
#define DVAPI DV_EXPORT_API
|
|
|
6e237b |
#define DVVAR DV_EXPORT_VAR
|
|
|
6e237b |
#else
|
|
|
6e237b |
#define DVAPI DV_IMPORT_API
|
|
|
6e237b |
#define DVVAR DV_IMPORT_VAR
|
|
|
6e237b |
#endif
|
|
|
6e237b |
|
|
|
6e237b |
//-------------------------------------------------------------------
|
|
|
6e237b |
|
|
|
6e237b |
class DVAPI TStringId {
|
|
|
6e237b |
public:
|
|
|
6e237b |
typedef std::map<std::string, int=""> Map;</std::string,>
|
|
|
6e237b |
typedef Map::iterator Iterator;
|
|
|
6e237b |
|
|
|
6e237b |
struct StaticData;
|
|
|
6e237b |
static const Iterator& none();
|
|
|
6e237b |
static Iterator genIter(const std::string &str);
|
|
|
6e237b |
static Iterator findIter(int id);
|
|
|
6e237b |
static Iterator findIter(const std::string &str);
|
|
|
6e237b |
|
|
|
6e237b |
private:
|
|
|
6e237b |
Iterator iter;
|
|
|
6e237b |
|
|
|
6e237b |
inline explicit TStringId(const Iterator &iter):
|
|
|
6e237b |
iter(iter) { }
|
|
|
6e237b |
|
|
|
6e237b |
public:
|
|
|
6e237b |
inline TStringId():
|
|
|
6e237b |
iter(none()) { }
|
|
|
6e237b |
inline explicit TStringId(const std::string &str):
|
|
|
6e237b |
iter(genIter(str)) { }
|
|
|
6e237b |
inline void reset()
|
|
|
6e237b |
{ iter = none(); }
|
|
|
6e237b |
inline void set(const std::string &str)
|
|
|
6e237b |
{ if (iter->first != str) iter = genIter(str); }
|
|
|
6e237b |
|
|
|
6e237b |
inline int id() const
|
|
|
6e237b |
{ return iter->second; }
|
|
|
6e237b |
inline const std::string& str() const
|
|
|
6e237b |
{ return iter->first; }
|
|
|
6e237b |
|
|
|
6e237b |
inline operator bool () const
|
|
|
16421e |
{ return id() != 0; }
|
|
|
6e237b |
inline bool operator== (const TStringId &other) const
|
|
|
6e237b |
{ return id() == other.id(); }
|
|
|
6e237b |
inline bool operator!= (const TStringId &other) const
|
|
|
6e237b |
{ return id() != other.id(); }
|
|
|
6e237b |
inline bool operator< (const TStringId &other) const
|
|
|
6e237b |
{ return id() < other.id(); }
|
|
|
6e237b |
|
|
|
6e237b |
inline static TStringId find(int id)
|
|
|
6e237b |
{ return TStringId(findIter(id)); }
|
|
|
6e237b |
inline static TStringId find(const std::string &str)
|
|
|
6e237b |
{ return TStringId(findIter(str)); }
|
|
|
6e237b |
};
|
|
|
6e237b |
|
|
|
6e237b |
#endif
|