00001 #ifndef __UT_Sym__
00002 #define __UT_Sym__
00003
00004 #include "UT_API.h"
00005 #include <stdio.h>
00006 #include "UT_Defines.h"
00007 #include "UT_Thing.h"
00008 #include "UT_SmallObject.h"
00009
00010 class UT_API UT_SymList {
00011 public:
00012 UT_SymList();
00013 ~UT_SymList();
00014
00015 int insertEntry(const char *name, const UT_Thing &value);
00016 int findEntry(const char *name, UT_Thing *valuep) const;
00017 UT_Thing &getEntry(const char *name, int *created = 0);
00018 int deleteEntry(const char *name);
00019
00020
00021
00022 bool findOrCreate(const char *name, UT_Thing **valuep);
00023
00024 const char *insertEntryAndGetReference(const char *name,
00025 const UT_Thing &value, int &created);
00026
00027 const char *getStringReference(const char *name, int *created = 0);
00028
00029 int count() const;
00030 int traverse(int (*function)(UT_Thing &, const char *, void *),
00031 void *data) const;
00032
00033 void dump(FILE *output, const char *format) const;
00034
00035 unsigned entries(void) const;
00036 unsigned empty(void) const;
00037
00038 class UT_Sym;
00039 public:
00040 class UT_API traverser
00041 {
00042 public:
00043 traverser()
00044 : myCurrSym(0) { }
00045 traverser(const traverser &src)
00046 { *this = src; }
00047 ~traverser() { }
00048
00049 UT_Thing &thing() { return myCurrSym->data; }
00050 const char *name() const { return myCurrSym->name; }
00051
00052 int operator==(const traverser &cmp) const
00053 { return (myCurrSym == cmp.myCurrSym); }
00054 int operator!=(const traverser &cmp) const
00055 { return !(*this == cmp); }
00056
00057 traverser &operator++()
00058 {
00059 myCurrSym = myCurrSym->next;
00060 return *this;
00061 }
00062
00063 const traverser &operator=(const traverser &src)
00064 {
00065 myCurrSym = src.myCurrSym;
00066 return *this;
00067 }
00068
00069 private:
00070 traverser(UT_Sym *sym)
00071 : myCurrSym(sym) { }
00072
00073 UT_Sym *myCurrSym;
00074
00075 friend class UT_SymList;
00076 };
00077
00078 traverser begin() const { return traverser(symbols); }
00079 traverser end() const { return traverser(); }
00080
00081 int64 getMemUsage(bool only_this) const;
00082
00083 class UT_API UT_Sym : public UT_SmallObject<UT_Sym,
00084 UT_SMALLOBJECT_CLEANPAGES_DEFAULT,
00085 UT_SMALLOBJECT_PAGESIZE_DEFAULT,
00086 UT_SMALLOBJECT_THREADSAFE_DEFAULT>
00087 {
00088 public:
00089 UT_Thing data;
00090 char *name;
00091 UT_Sym *next;
00092 };
00093
00094 UT_Sym *symbols;
00095
00096
00097 UT_Sym *removeFirstSym();
00098 void insertSym(UT_Sym &sym);
00099 UT_Sym *findOrCreate(const char *name, int *created);
00100
00101 friend class traverser;
00102 };
00103
00104 #endif