#include "TKeyXML.h"
#include "TBufferXML.h"
#include "TXMLFile.h"
#include "TClass.h"
#include "TROOT.h"
#include "TBrowser.h"
ClassImp(TKeyXML);
TKeyXML::TKeyXML() :
TKey(),
fKeyNode(0),
fKeyId(0),
fSubdir(kFALSE)
{
}
TKeyXML::TKeyXML(TDirectory* mother, Long64_t keyid, const TObject* obj, const char* name, const char* title) :
TKey(mother),
fKeyNode(0),
fKeyId(keyid),
fSubdir(kFALSE)
{
if (name)
SetName(name);
else
if (obj!=0) {
SetName(obj->GetName());
fClassName=obj->ClassName();
} else
SetName("Noname");
if (title) SetTitle(title);
fCycle = GetMotherDir()->AppendKey(this);
TXMLEngine* xml = XMLEngine();
if (xml!=0)
fKeyNode = xml->NewChild(0, 0, xmlio::Xmlkey, 0);
fDatime.Set();
StoreObject((void*)obj, obj ? obj->IsA() : 0);
}
TKeyXML::TKeyXML(TDirectory* mother, Long64_t keyid, const void* obj, const TClass* cl, const char* name, const char* title) :
TKey(mother),
fKeyNode(0),
fKeyId(keyid),
fSubdir(kFALSE)
{
if (name && *name) SetName(name);
else SetName(cl ? cl->GetName() : "Noname");
if (title) SetTitle(title);
fCycle = GetMotherDir()->AppendKey(this);
TXMLEngine* xml = XMLEngine();
if (xml!=0)
fKeyNode = xml->NewChild(0, 0, xmlio::Xmlkey, 0);
fDatime.Set();
StoreObject(obj, cl);
}
TKeyXML::TKeyXML(TDirectory* mother, Long64_t keyid, XMLNodePointer_t keynode) :
TKey(mother),
fKeyNode(keynode),
fKeyId(keyid),
fSubdir(kFALSE)
{
TXMLEngine* xml = XMLEngine();
SetName(xml->GetAttr(keynode, xmlio::Name));
if (xml->HasAttr(keynode, xmlio::Title))
SetTitle(xml->GetAttr(keynode, xmlio::Title));
fCycle = xml->GetIntAttr(keynode, xmlio::Cycle);
if (xml->HasAttr(keynode, xmlio::CreateTm)) {
TDatime tm(xml->GetAttr(keynode, xmlio::CreateTm));
fDatime = tm;
}
XMLNodePointer_t objnode = xml->GetChild(keynode);
xml->SkipEmpty(objnode);
fClassName = xml->GetAttr(objnode, xmlio::ObjClass);
}
TKeyXML::~TKeyXML()
{
TXMLEngine* xml = XMLEngine();
if (fKeyNode && xml)
xml->FreeNode(fKeyNode);
}
void TKeyXML::Delete(Option_t * )
{
TXMLEngine* xml = XMLEngine();
if (fKeyNode && xml) {
xml->FreeNode(fKeyNode);
fKeyNode = 0;
}
fMotherDir->GetListOfKeys()->Remove(this);
}
void TKeyXML::StoreKeyAttributes()
{
TXMLEngine* xml = XMLEngine();
TXMLFile* f = (TXMLFile*) GetFile();
if ((f==0) || (xml==0) || (fKeyNode==0)) return;
xml->NewAttr(fKeyNode, 0, xmlio::Name, GetName());
xml->NewIntAttr(fKeyNode, xmlio::Cycle, fCycle);
if (f->GetIOVersion()>1) {
if (strlen(GetTitle())>0)
xml->NewAttr(fKeyNode, 0, xmlio::Title, GetTitle());
xml->NewAttr(fKeyNode, 0, xmlio::CreateTm, fDatime.AsSQLString());
}
}
void TKeyXML::StoreObject(const void* obj, const TClass* cl)
{
TXMLFile* f = (TXMLFile*) GetFile();
TXMLEngine* xml = XMLEngine();
if ((f==0) || (xml==0) || (fKeyNode==0)) return;
StoreKeyAttributes();
TBufferXML buffer(TBuffer::kWrite, f);
if (f->GetIOVersion()==1)
buffer.SetBit(TBuffer::kCannotHandleMemberWiseStreaming, kFALSE);
XMLNodePointer_t node = buffer.XmlWriteAny(obj, cl);
if (node!=0)
xml->AddChildFirst(fKeyNode, node);
buffer.XmlWriteBlock(fKeyNode);
if (cl) fClassName = cl->GetName();
}
void TKeyXML::UpdateAttributes()
{
TXMLEngine* xml = XMLEngine();
if ((xml==0) || (fKeyNode==0)) return;
xml->FreeAllAttr(fKeyNode);
StoreKeyAttributes();
}
void TKeyXML::UpdateObject(TObject* obj)
{
TXMLFile* f = (TXMLFile*) GetFile();
TXMLEngine* xml = XMLEngine();
if ((f==0) || (xml==0) || (obj==0) || (fKeyNode==0)) return;
XMLNodePointer_t objnode = xml->GetChild(fKeyNode);
xml->SkipEmpty(objnode);
if (objnode==0) return;
xml->UnlinkNode(objnode);
xml->FreeNode(objnode);
xml->FreeAllAttr(fKeyNode);
StoreObject(obj, obj->IsA());
}
Int_t TKeyXML::Read(TObject* tobj)
{
if (tobj==0) return 0;
void* res = XmlReadAny(tobj, 0);
return res==0 ? 0 : 1;
}
TObject* TKeyXML::ReadObj()
{
TObject* tobj = (TObject*) XmlReadAny(0, TObject::Class());
if (tobj!=0) {
if (gROOT->GetForceStyle()) tobj->UseCurrentStyle();
if (tobj->IsA() == TDirectory::Class()) {
TDirectory *dir = (TDirectory*) tobj;
dir->SetName(GetName());
dir->SetTitle(GetTitle());
dir->SetSeekDir(GetKeyId());
dir->SetMother(fMotherDir);
dir->ReadKeys();
fMotherDir->Append(dir);
fSubdir = kTRUE;
}
}
return tobj;
}
void* TKeyXML::ReadObjectAny(const TClass *expectedClass)
{
return XmlReadAny(0, expectedClass);
}
void* TKeyXML::XmlReadAny(void* obj, const TClass* expectedClass)
{
if (fKeyNode==0) return obj;
TXMLFile* f = (TXMLFile*) GetFile();
TXMLEngine* xml = XMLEngine();
if ((f==0) || (xml==0)) return obj;
TBufferXML buffer(TBuffer::kRead, f);
if (f->GetIOVersion()==1)
buffer.SetBit(TBuffer::kCannotHandleMemberWiseStreaming, kFALSE);
XMLNodePointer_t blocknode = xml->GetChild(fKeyNode);
xml->SkipEmpty(blocknode);
while (blocknode!=0) {
if (strcmp(xml->GetNodeName(blocknode), xmlio::XmlBlock)==0) break;
xml->ShiftToNext(blocknode);
}
buffer.XmlReadBlock(blocknode);
XMLNodePointer_t objnode = xml->GetChild(fKeyNode);
xml->SkipEmpty(objnode);
TClass* cl = 0;
void* res = buffer.XmlReadAny(objnode, obj, &cl);
if ((cl==0) || (res==0)) return obj;
Int_t delta = 0;
if (expectedClass!=0) {
delta = cl->GetBaseClassOffset(expectedClass);
if (delta<0) {
if (obj==0) cl->Destructor(res);
return 0;
}
if (cl->GetClassInfo() && !expectedClass->GetClassInfo()) {
Warning("XmlReadAny",
"Trying to read an emulated class (%s) to store in a compiled pointer (%s)",
cl->GetName(),expectedClass->GetName());
}
}
return ((char*)res) + delta;
}
TXMLEngine* TKeyXML::XMLEngine()
{
TXMLFile* f = (TXMLFile*) GetFile();
return f==0 ? 0 : f->XML();
}
ROOT page - Class index - Class Hierarchy - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.