00001 #ifndef __LOUT_OBJECT_HH__ 00002 #define __LOUT_OBJECT_HH__ 00003 00004 #include <stdlib.h> 00005 #include <string.h> 00006 00007 #include "misc.hh" 00008 00013 namespace lout { 00014 00015 namespace object { 00016 00024 class Object 00025 { 00026 public: 00027 virtual ~Object(); 00028 virtual bool equals(Object *other); 00029 virtual int hashValue(); 00030 virtual Object *clone(); 00031 virtual void intoStringBuffer(misc::StringBuffer *sb); 00032 const char *toString(); 00033 virtual size_t sizeOf(); 00034 }; 00035 00039 class Pointer: public Object 00040 { 00041 private: 00042 void *value; 00043 00044 public: 00045 Pointer(void *value) { this->value = value; } 00046 bool equals(Object *other); 00047 int hashValue(); 00048 void intoStringBuffer(misc::StringBuffer *sb); 00049 inline void *getValue() { return value; } 00050 }; 00051 00055 template <class T> class TypedPointer: public Pointer 00056 { 00057 public: 00058 inline TypedPointer(T *value) : Pointer ((void*)value) { } 00059 inline T *getTypedValue() { return (T*)getValue(); } 00060 }; 00061 00062 00066 class Integer: public Object, misc::Comparable 00067 { 00068 int value; 00069 00070 public: 00071 Integer(int value) { this->value = value; } 00072 bool equals(Object *other); 00073 int hashValue(); 00074 void intoStringBuffer(misc::StringBuffer *sb); 00075 int compareTo(Comparable *other); 00076 inline int getValue() { return value; } 00077 }; 00078 00079 00085 class ConstString: public Object, misc::Comparable 00086 { 00087 protected: 00088 const char *str; 00089 00090 public: 00091 ConstString(const char *str) { this->str = str; } 00092 bool equals(Object *other); 00093 int hashValue(); 00094 int compareTo(Comparable *other); 00095 void intoStringBuffer(misc::StringBuffer *sb); 00096 00097 inline const char *chars() { return str; } 00098 00099 static int hashValue(const char *str); 00100 }; 00101 00102 00108 class String: public ConstString 00109 { 00110 public: 00111 String(const char *str); 00112 ~String(); 00113 }; 00114 00118 class PairBase: public Object 00119 { 00120 protected: 00121 Object *first, *second; 00122 00123 public: 00124 PairBase(Object *first, Object *second); 00125 ~PairBase(); 00126 00127 bool equals(Object *other); 00128 int hashValue(); 00129 void intoStringBuffer(misc::StringBuffer *sb); 00130 size_t sizeOf(); 00131 }; 00132 00136 class Pair: public PairBase 00137 { 00138 public: 00139 Pair(Object *first, Object *second): PairBase (first, second) { } 00140 00141 inline Object *getFirst () { return first; } 00142 inline Object *getSecond () { return second; } 00143 }; 00144 00148 template <class F, class S> class TypedPair: public PairBase 00149 { 00150 public: 00151 TypedPair(F *first, S *second): PairBase (first, second) { } 00152 00153 inline F *getFirst () { return first; } 00154 inline S *getSecond () { return second; } 00155 }; 00156 00157 } // namespace object 00158 00159 } // namespace lout 00160 00161 #endif // __LOUT_OBJECT_HH__
1.5.9