00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __UT_ThingList__
00020 #define __UT_ThingList__
00021
00022 #include "UT_API.h"
00023 #include <stdio.h>
00024 #include "UT_Defines.h"
00025 #include "UT_Thing.h"
00026 #include "UT_Hash.h"
00027 #include "UT_SmallObject.h"
00028
00029 class UT_API UT_ThingEntry
00030 : public UT_SmallObject<UT_ThingEntry,
00031 UT_SMALLOBJECT_CLEANPAGES_DEFAULT,
00032 UT_SMALLOBJECT_PAGESIZE_DEFAULT,
00033 UT_SMALLOBJECT_THREADSAFE_DEFAULT>
00034 {
00035 public:
00036 UT_Thing data;
00037 UT_Hash *name;
00038 UT_ThingEntry *next;
00039 };
00040
00041 class UT_API UT_ThingList {
00042 public:
00043 UT_ThingList();
00044 ~UT_ThingList();
00045
00046
00047
00048 int insertEntry(const UT_Hash &name, const UT_Thing & value,
00049 bool ordered = false);
00050 int findEntry(const UT_Hash &name, UT_Thing *valuep,
00051 bool ordered = false) const;
00052 int findEntry(const UT_Hash &name, UT_Thing *valuep,
00053 const UT_Hash **namep, bool ordered = false) const;
00054 UT_Thing &getEntry(const UT_Hash &name, int *created = 0,
00055 bool ordered = false);
00056 int deleteEntry(const UT_Hash &name,
00057 bool ordered = false);
00058
00059 const UT_Hash & getHashReference(const UT_Hash &name, int *created = 0,
00060 bool ordered = false);
00061
00062 int count() const;
00063 int traverse(int (*function)(UT_Thing &, const UT_Hash &, void *),
00064 void *data) const;
00065
00066 unsigned entries(void) const;
00067 unsigned empty(void) const;
00068
00069 int64 getMemUsage(bool only_this) const;
00070
00071
00072
00073 UT_ThingEntry *removeFirstThingEntry();
00074
00075
00076 UT_ThingEntry *removeFirstThingEntry(const UT_Hash &name,
00077 bool ordered);
00078
00079 void insertThingEntry(UT_ThingEntry &thing_entry,
00080 bool ordered);
00081
00082 class UT_API traverser
00083 {
00084 public:
00085 traverser()
00086 : myCurrEntry(0) { }
00087 traverser(const traverser &src)
00088 { *this = src; }
00089 ~traverser() { }
00090
00091 UT_Thing &thing() { return myCurrEntry->data; }
00092 UT_Hash *hash() { return myCurrEntry->name; }
00093
00094 int operator==(const traverser &cmp)
00095 { return (myCurrEntry == cmp.myCurrEntry); }
00096 int operator!=(const traverser &cmp)
00097 { return !(*this == cmp); }
00098
00099 traverser &operator++()
00100 {
00101 myCurrEntry = myCurrEntry->next;
00102 return *this;
00103 }
00104
00105 const traverser &operator=(const traverser &src)
00106 {
00107 myCurrEntry = src.myCurrEntry;
00108 return *this;
00109 }
00110
00111 private:
00112 traverser(UT_ThingEntry *sym)
00113 : myCurrEntry(sym) { }
00114
00115 UT_ThingEntry *myCurrEntry;
00116
00117 friend class UT_ThingList;
00118 };
00119
00120 traverser begin() const { return traverser(symbols); }
00121 traverser end() const { return traverser(); }
00122
00123 private:
00124 UT_ThingEntry *findOrCreate(const UT_Hash &name, int *created,
00125 bool ordered);
00126 UT_ThingEntry *symbols;
00127 };
00128
00129 #endif