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/FunctionTypeLoc.h"
00022 #include "EDoc/FunctionType.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    FunctionTypeLoc::FunctionTypeLoc(Dictionary& dict_in, 
00035          FunctionType* value_in, const Location& loc_in) :
00036 
00037       DictionarySpecific(&dict_in),
00038       loc(loc_in, dict_in),
00039       value(NULL)
00040    {
00041       if (value_in)
00042       {
00043          value = dict.function_types.AlwaysGet(*value_in);
00044       }
00045    }
00046    
00047    FunctionTypeLoc::FunctionTypeLoc(Dictionary* dict_in) :
00048       DictionarySpecific(dict_in),
00049       loc(dict_in),
00050       value(NULL)
00051    {
00052    }
00053    
00054    FunctionTypeLoc::FunctionTypeLoc(const FunctionTypeLoc& right) :
00055       DictionarySpecific(&right.dict),
00056       loc(right.loc),
00057       value(right.value)
00058    {
00059    }
00060    
00061    FunctionTypeLoc::FunctionTypeLoc(const FunctionTypeLoc& right, 
00062          Dictionary& dict_in) :
00063 
00064       DictionarySpecific(&dict_in),
00065       loc(right.loc, dict_in),
00066       value(NULL)
00067    {
00068       if (right.value)
00069       {
00070          value = dict.function_types.AlwaysGet(*right.value);
00071       }
00072    }
00073    
00074    FunctionTypeLoc& FunctionTypeLoc::operator=(const FunctionTypeLoc& right)
00075    {
00076       if (this == &right)
00077       {
00078          return *this;
00079       }
00080       
00081       value = NULL;
00082       if (right.value)
00083       {
00084          value = dict.function_types.AlwaysGet(*right.value);
00085       }
00086       
00087       return *this;
00088    }
00089    
00090    void FunctionTypeLoc::Read(PersistenceIFace& file, IndexedDictionary& idict)
00091    {
00092       
00093       value = idict.function_types.AlwaysGet(
00094          file.ReadUInt32(KEY_FUNCTION_TYPE));
00095       
00096       loc.Read(file, idict);
00097    }
00098    
00099    void FunctionTypeLoc::Write(PersistenceIFace& file) const
00100    {
00101       
00102       file.WriteUInt32Debug(KEY_FUNCTION_TYPE, 
00103          value->GetIndex(), value->GetDeclaredName());
00104       
00105       loc.Write(file);
00106    }
00107    
00108    bool FunctionTypeLoc::operator==(const FunctionTypeLoc& right) const
00109    {
00110       return (loc == right.loc) && 
00111          (value->GetNormalisedName() == right.value->GetNormalisedName());
00112    }
00113    
00114    
00115    #define EDOC_REPLACE(DataType, Data, From, To, Count) \
00116       if ((void*)Data == From) {Data = (DataType*)To; Count++;}
00117    
00118    size_t FunctionTypeLoc::ReplaceReferences(PStack& stack, void* remove, 
00119       void* replace)
00120    {
00121       size_t count = 0;
00122       if (!stack.Push(this))
00123       {
00124          return count;
00125       }
00126 
00127       
00128       EDOC_REPLACE(FunctionType, value, remove, replace, count);
00129 
00130       count += loc.ReplaceReferences(stack, remove, replace);
00131       
00132       return count;
00133    }
00134    
00135    void FunctionTypeLoc::Validate(PStack& stack, 
00136       const Dictionary& dict_in) const
00137    {
00138       StackRef ref(stack, this);
00139       if (!ref)
00140       {
00141          return;
00142       }
00143       
00144       EDOC_ASSERT(&dict == &dict_in, "");
00145       
00146       loc.Validate(stack, dict_in);
00147       value->Validate(stack, dict_in);
00148    }
00149    
00150    std::ostream& FunctionTypeLoc::Print(std::ostream& out, 
00151       std::string prefix) const
00152    {
00153       
00154       loc.Print(out, prefix);
00155       
00156       
00157       out << prefix << "Function Type: " << value->GetKeyName() << std::endl;
00158       return out;
00159    }
00160    
00161 }
00162