00001
00002 #ifndef __UPF_TYPEINFO_H__
00003 #define __UPF_TYPEINFO_H__
00004
00005 #include "upf/upf.h"
00006 #ifdef HAVE_CONFIG_H
00007 #include "config.h"
00008 #endif
00009 #include "upf/ITypeInfo.h"
00010
00011 #include <list>
00012
00013 namespace upf { namespace impl {
00014
00015
00016 using std::string;
00017 using std::pair;
00018 using std::list;
00019
00020
00021
00022
00023
00024 class TypeInfoStreamReader;
00025
00026 template<class Parent> class _TypeInfo : public Parent
00027 {
00028 public:
00029 void init(TypeInfoStreamReader& stream);
00030 virtual ~_TypeInfo() {}
00031
00032 ITypeInfo::Kind getKind() { return m_kind; }
00033 string getName() { return m_name; }
00034
00035 protected:
00036 ITypeInfo::Kind m_kind;
00037 string m_name;
00038 };
00039
00040 class TypeInfo : public _TypeInfo<ITypeInfo>
00041 {
00042 public:
00043 void init(TypeInfoStreamReader& stream)
00044 { _TypeInfo<ITypeInfo>::init(stream); }
00045 UPF_DECLARE_CLASS(TypeInfo)
00046 };
00047
00048
00049 class InterfaceInfo : public _TypeInfo<IInterfaceInfo>
00050 {
00051 public:
00052 void init(TypeInfoStreamReader& stream);
00053 IID getIID() { return m_iid; }
00054
00055 protected:
00056 IID m_iid;
00057
00058 UPF_DECLARE_CLASS(InterfaceInfo)
00059 };
00060
00061
00062 class TypedefInfo : public _TypeInfo<ITypedefInfo>
00063 {
00064 public:
00065 void init(TypeInfoStreamReader& stream);
00066 string getType() { return m_type; }
00067 bool isSequence() { return m_seq; }
00068
00069 protected:
00070 string m_type;
00071 bool m_seq;
00072
00073 UPF_DECLARE_CLASS(TypedefInfo)
00074 };
00075
00076 class NativeTypeInfo : public _TypeInfo<INativeTypeInfo>
00077 {
00078 UPF_DECLARE_CLASS(NativeTypeInfo)
00079 };
00080
00081
00082
00083
00084
00085
00086
00087 typedef list< pair<IID,string> > IIDMappingData;
00088
00089 class TypeInfoRegistry
00090 {
00091 public:
00092 TypeInfoRegistry() {}
00093 ~TypeInfoRegistry() {}
00094
00096 Ptr<ITypeInfo> createTypeInfo(const string& name);
00097
00108 bool registerType(const string& id, const upf_uint8_t *chunk, size_t len);
00109
00111 void rollback();
00112
00116 void commit();
00117
00118 private:
00119 struct TypeData
00120 {
00121 TypeData() {}
00122 TypeData(const upf_uint8_t *_stream, size_t _len) : stream(_stream), len(_len) {}
00123 const upf_uint8_t *stream;
00124 size_t len;
00125 };
00126
00127 struct JournalData
00128 {
00129 JournalData() {}
00130 JournalData(const string& _id, const TypeData& _data) : id(_id), data(_data) {}
00131 string id;
00132 TypeData data;
00133 };
00134
00135 typedef StringHash<TypeData> Registry;
00136 typedef list<JournalData> Journal;
00137
00138 Registry m_registry;
00139 Journal m_journal;
00140 };
00141
00142
00143 } }
00144
00145 #endif