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/File.h"
00022 #include "EDoc/PersistenceIFace.h"
00023 #include "EDoc/Dictionary.h"
00024 #include "EDoc/exceptions.h"
00025 #include "EDoc/PStack.h"
00026 #include "EDoc/StackRef.h"
00027
00028 #include "EDoc/persistence_data.h"
00029 #include "IndexedDictionary.h"
00030
00031 namespace EDoc
00032 {
00033
00034 uint8_t File::GetRecordType() const
00035 {
00036 return VALUE_RECORD_TYPE_FILE;
00037 }
00038
00039 File::File(Dictionary& dict_in, std::string key_name_in) :
00040 StringIdentifiedObject(dict_in, key_name_in)
00041 {
00042 }
00043
00044 File::File(Dictionary& dict_in, int32_t index_in) :
00045 StringIdentifiedObject(dict_in, index_in)
00046 {
00047 }
00048
00049 File& File::operator=(const File& right)
00050 {
00051
00052 if (this == &right)
00053 {
00054 return *this;
00055 }
00056
00057 name = right.name;
00058 return *this;
00059 }
00060
00061 void File::Read(PersistenceIFace& file, IndexedDictionary& EDOC_UNUSED(idict))
00062 {
00063 name = file.ReadString(KEY_NAME);
00064 populated = true;
00065 SetKeyName(name);
00066 }
00067
00068 void File::Write(PersistenceIFace& file) const
00069 {
00070 file.WriteString(KEY_NAME, name);
00071 }
00072
00073
00074
00075 #define EDOC_MERGE_ERROR(Message) \
00076 EDOC_Error(Message); \
00077 EDOC_THROW_EXCEPTION(MergeException, "Failed merging file.", Message);
00078
00079 void File::Merge(const StringIdentifiedObject& right_in)
00080 {
00081 const File& right(dynamic_cast<const File&>(right_in));
00082
00083 if (!name.size())
00084 {
00085 *this = right;
00086 return;
00087 }
00088
00089 if (name != right.name)
00090 {
00091 EDOC_MERGE_ERROR("Unable to merge two files with different names.");
00092 }
00093
00094 if (!populated)
00095 {
00096 populated = right.populated;
00097 }
00098 }
00099
00100 std::ostream& File::Print(std::ostream& out, std::string prefix) const
00101 {
00102 out << prefix << "Name: " << name << std::endl;
00103 return out;
00104 }
00105
00106 size_t File::ReplaceReferences(PStack& EDOC_UNUSED(stack),
00107 void* EDOC_UNUSED(remove), void* EDOC_UNUSED(replace))
00108 {
00109 return 0;
00110 }
00111
00112 void File::Validate(PStack& stack, const Dictionary& dict_in) const
00113 {
00114 StackRef ref(stack, this);
00115 if (!ref)
00116 {
00117 return;
00118 }
00119
00120 EDOC_ASSERT(&dict == &dict_in,
00121 "Current dict: " << &dict
00122 << "\nRequired dict: " << &dict_in
00123 << "\nKey: " << key_name
00124 << "\nIndex: " << index);
00125
00126
00127 EDOC_ASSERT(dict_in.files.Get(GetKeyName()) == this, "");
00128
00129
00130
00131
00132 }
00133
00134 }