00001 /**** 00002 Hierarchical Data Objects 00003 Copyright (C) 2005-2010 Werner Van Belle 00004 http://flow.yellowcouch.org/data/ 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 ****/ 00020 #ifndef __loaded__symbol_h__ 00021 #define __loaded__symbol_h__ 00022 using namespace std; 00023 #line 1 "symbol.h++" 00024 #include <Qt/qstring.h> 00025 #include "data.h" 00026 00027 //--------------------------------------------------------------- 00028 // Symbol 00029 //--------------------------------------------------------------- 00030 // symbols are represented as strings. Their 00031 // unique quality is to be found in the quick 00032 // comparators due to storing all symbols in a 00033 // symbol table. The actual order might not be 00034 // alphabetically. 00035 class symbolLesser; 00036 class Symbol: public DataClass 00037 { 00038 private: 00039 QString text; 00040 void init(const QString& s); 00041 protected: 00042 virtual DataClass* shallow_copy() const 00043 { 00044 return new Symbol(*this); 00045 }; 00046 virtual QString type_name() const 00047 { 00048 return type(); 00049 }; 00050 virtual void visit(DataVisitor& v); 00051 public: 00052 static QString type() 00053 { 00054 return "Symbol"; 00055 } 00056 Symbol() : text(NULL) 00057 { 00058 }; 00059 Symbol(const QString &s) 00060 { 00061 init(s); 00062 } 00063 Symbol(const Symbol& s) : DataClass(), text(s.text) 00064 { 00065 }; 00066 Symbol &operator =(const Symbol &s) 00067 { 00068 text=s.text; 00069 return *this; 00070 }; 00071 const QString& operator ()() const 00072 { 00073 return text; 00074 }; 00075 operator const QString&() const 00076 { 00077 return text; 00078 } 00079 operator QString() const 00080 { 00081 return text; 00082 } 00083 int length() const 00084 { 00085 return text.length(); 00086 }; 00087 bool operator < (const Symbol & other) 00088 { 00089 return text < other.text; 00090 } 00091 bool operator == (const Symbol & other) 00092 { 00093 return text < other.text; 00094 } 00095 }; 00096 00097 struct symbolLesser 00098 { 00099 bool operator()(Symbol s1, Symbol s2) const 00100 { 00101 return s1<s2; 00102 }; 00103 }; 00104 #endif // __loaded__symbol_h__