00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "config.h"
00020
00021 #include "EDoc/TypeLoc.h"
00022 #include "EDoc/Type.h"
00023 #include "EDoc/Dictionary.h"
00024 #include "EDoc/PStack.h"
00025 #include "EDoc/StackRef.h"
00026
00027 #include "EDoc/PersistenceIFace.h"
00028 #include "IndexedDictionary.h"
00029 #include "EDoc/persistence_data.h"
00030
00031 namespace EDoc
00032 {
00033
00034 TypeLoc::TypeLoc(Dictionary* dict_in) :
00035 DictionarySpecific(dict_in),
00036 loc(dict_in),
00037 value(NULL)
00038 {
00039 }
00040
00041 TypeLoc::TypeLoc(const TypeLoc& right) :
00042 DictionarySpecific(&right.dict),
00043 loc(right.loc),
00044 value(right.value)
00045 {
00046 }
00047
00048 TypeLoc::TypeLoc(const TypeLoc& right, Dictionary& dict_in) :
00049 DictionarySpecific(&dict_in),
00050 loc(right.loc, dict_in),
00051 value(NULL)
00052 {
00053 if (right.value)
00054 {
00055 value = dict.types.AlwaysGet(*right.value);
00056 }
00057 }
00058
00059 TypeLoc& TypeLoc::operator=(const TypeLoc& right)
00060 {
00061 if (this == &right)
00062 {
00063 return *this;
00064 }
00065
00066 value = NULL;
00067 if (right.value)
00068 {
00069 value = dict.types.AlwaysGet(*right.value);
00070 }
00071
00072 return *this;
00073 }
00074
00075 void TypeLoc::Read(PersistenceIFace& file, IndexedDictionary& idict)
00076 {
00077
00078 value = idict.types.AlwaysGet(file.ReadUInt32(KEY_TYPE));
00079
00080 loc.Read(file, idict);
00081 }
00082
00083 void TypeLoc::Write(PersistenceIFace& file) const
00084 {
00085
00086 file.WriteUInt32Debug(KEY_TYPE,
00087 value->GetIndex(), value->GetDeclaredName());
00088
00089 loc.Write(file);
00090 }
00091
00092 bool TypeLoc::operator==(const TypeLoc& right) const
00093 {
00094 return (loc == right.loc) &&
00095 (value->GetNormalisedName() == right.value->GetNormalisedName());
00096 }
00097
00098
00099 #define EDOC_REPLACE(DataType, Data, From, To, Count) \
00100 if ((void*)Data == From) {Data = (DataType*)To; Count++;}
00101
00102 size_t TypeLoc::ReplaceReferences(PStack& stack, void* remove,
00103 void* replace)
00104 {
00105 size_t count = 0;
00106 if (!stack.Push(this))
00107 {
00108 return count;
00109 }
00110
00111
00112 EDOC_REPLACE(Type, value, remove, replace, count);
00113
00114 count += loc.ReplaceReferences(stack, remove, replace);
00115
00116 return count;
00117 }
00118
00119 void TypeLoc::Validate(PStack& stack, const Dictionary& dict_in) const
00120 {
00121 StackRef ref(stack, this);
00122 if (!ref)
00123 {
00124 return;
00125 }
00126
00127 EDOC_ASSERT(&dict == &dict_in, "");
00128
00129 loc.Validate(stack, dict_in);
00130 value->Validate(stack, dict_in);
00131 }
00132
00133 std::ostream& TypeLoc::Print(std::ostream& out, std::string prefix) const
00134 {
00135
00136 loc.Print(out, prefix);
00137
00138
00139 out << prefix << "Type: " << value->GetKeyName() << std::endl;
00140 return out;
00141 }
00142
00143 }
00144
00145