00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef RAUL_SYMBOL_HPP
00019 #define RAUL_SYMBOL_HPP
00020
00021 #include <iostream>
00022 #include <cctype>
00023 #include <string>
00024 #include <cstring>
00025 #include <cassert>
00026 #include <glib.h>
00027
00028 namespace Raul {
00029
00030
00042 class Symbol {
00043 public:
00049 Symbol(const std::basic_string<char>& symbol)
00050 : _str(g_intern_string(symbol.c_str()))
00051 {
00052 assert(is_valid(symbol));
00053 }
00054
00055
00061 Symbol(const char* csymbol)
00062 : _str(g_intern_string(csymbol))
00063 {
00064 assert(is_valid(csymbol));
00065 }
00066
00067 inline const char* c_str() const { return _str; }
00068
00069 inline bool operator==(const Symbol& other) const {
00070 return _str == other._str;
00071 }
00072
00073 inline bool operator!=(const Symbol& other) const {
00074 return _str != other._str;
00075 }
00076
00077 inline bool operator<(const Symbol& other) const {
00078 return strcmp(_str, other._str) < 0;
00079 }
00080
00081 static bool is_valid(const std::basic_string<char>& symbol);
00082
00083 static std::string symbolify(const std::basic_string<char>& str);
00084
00085 private:
00086 const char* _str;
00087 };
00088
00089
00090 }
00091
00092 static inline std::ostream& operator<<(std::ostream& os, const Raul::Symbol& symbol)
00093 {
00094 return (os << symbol.c_str());
00095 }
00096
00097 #endif // RAUL_SYMBOL_HPP