libs/EDoc/File.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 
00003    Copyright (C) 2007 by Brendon Costa
00004 
00005    This library is free software; you can redistribute it and/or modify 
00006    it under the terms of the "LGPL Like" License defined in the file COPYING 
00007    that should have been distributed along with this source.
00008 
00009    This library is distributed in the hope that it will be useful, 
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of 
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013    You should have received a copy of the "LGPL Like" License 
00014    along with this library; see the file COPYING. if not, it can be 
00015    obtained from the EDoc++ website: 
00016    http://edoc.sourceforge.net/license.html
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       // @@@Brendon Do i need to assign the StringIdentifiedObject parts too?
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    /** \brief define a small macro that is called upon a merge error.
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       //EDOC_ASSERT(populated, "");
00127       EDOC_ASSERT(dict_in.files.Get(GetKeyName()) == this, "");
00128       
00129       // @@@Brendon Validate that the keyname from StringIdentifiedObject is the
00130       // same as what we would calculate the keyname to be from our internal
00131       // data. Mismatches may occur from assignment operator.
00132    }
00133    //===========================================================================
00134 }

Generated on Tue Jan 20 18:26:07 2009 for EDoc-0.2.1 by  doxygen 1.5.1