RAUL 0.8.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List

Symbol.hpp

    00001 /* This file is part of Raul.
    00002  * Copyright (C) 2008-2009 David Robillard <http://drobilla.net>
    00003  *
    00004  * Raul is free software; you can redistribute it and/or modify it under the
    00005  * terms of the GNU General Public License as published by the Free Software
    00006  * Foundation; either version 2 of the License, or (at your option) any later
    00007  * version.
    00008  *
    00009  * Raul is distributed in the hope that it will be useful, but WITHOUT ANY
    00010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00011  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for details.
    00012  *
    00013  * You should have received a copy of the GNU General Public License along
    00014  * with this program; if not, write to the Free Software Foundation, Inc.,
    00015  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
    00016  */
    00017
    00018 #ifndef RAUL_SYMBOL_HPP
    00019 #define RAUL_SYMBOL_HPP
    00020
    00021 #include <cassert>
    00022 #include <cctype>
    00023 #include <cstring>
    00024 #include <iostream>
    00025 #include <string>
    00026
    00027 #include <glib.h>
    00028
    00029 namespace Raul {
    00030
    00031
    00043 class Symbol {
    00044 public:
    00050     Symbol(const std::basic_string<char>& symbol)
    00051         : _str(g_intern_string(symbol.c_str()))
    00052     {
    00053         assert(is_valid(symbol));
    00054     }
    00055
    00056
    00062     Symbol(const char* csymbol)
    00063         : _str(g_intern_string(csymbol))
    00064     {
    00065         assert(is_valid(csymbol));
    00066     }
    00067
    00068     inline const char* c_str() const { return _str; }
    00069
    00070     inline bool operator==(const Symbol& other) const {
    00071         return _str == other._str;
    00072     }
    00073
    00074     inline bool operator!=(const Symbol& other) const {
    00075         return _str != other._str;
    00076     }
    00077
    00078     inline bool operator<(const Symbol& other) const {
    00079         return strcmp(_str, other._str) < 0;
    00080     }
    00081
    00082     static bool is_valid(const std::basic_string<char>& symbol);
    00083
    00084     static std::string symbolify(const std::basic_string<char>& str);
    00085
    00086 private:
    00087     const char* _str;
    00088 };
    00089
    00090
    00091 } // namespace Raul
    00092
    00093 static inline std::ostream& operator<<(std::ostream& os, const Raul::Symbol& symbol)
    00094 {
    00095     return (os << symbol.c_str());
    00096 }
    00097
    00098 #endif // RAUL_SYMBOL_HPP