00001 #include "TGraphStreamer_v1.h"
00002 #include "TGraph.h"
00003 #include "../RootStreamableAdapter.h"
00004
00005 using namespace Sct;
00006
00007 namespace SctData {
00008 namespace IO {
00009
00010
00011 unsigned TGraphStreamer_v1::s_version=1;
00012
00013 bool TGraphStreamer_v1::inMap = IOManager::addToMap(TGraph::Class()->GetName(), auto_ptr<Streamer>(new TGraphStreamer_v1()));
00014
00015 TGraphStreamer_v1::TGraphStreamer_v1() throw() {}
00016
00017 void TGraphStreamer_v1::write(OStream& out, const Streamable& ob, const IOManager& manager) const throw(LogicError, IoError) {
00018 const RootStreamableAdapter& ad = dynamic_cast<const RootStreamableAdapter&>(ob);
00019 TGraph* graph = (TGraph*)ad.getObject();
00020 out << static_cast<unsigned int> ( graph->GetN() );
00021 out.put(graph->GetX(), graph->GetN() );
00022 out.put(graph->GetY(), graph->GetN() );
00023 }
00024
00025 shared_ptr<Streamable> TGraphStreamer_v1::read(IStream& in, const IOManager& manager) const throw(LogicError, IoError) {
00026 shared_ptr<Streamable> ad (new RootStreamableAdapter(*new TGraph()));
00027 read(in, *ad, manager);
00028 return ad;
00029 }
00030
00031 void TGraphStreamer_v1::read(IStream& in, Streamable& ob, const IOManager& manager) const throw(LogicError, IoError) {
00032 RootStreamableAdapter& ad = dynamic_cast<RootStreamableAdapter&>(ob);
00033 TGraph* graph = (TGraph*)ad.getObject();
00034 unsigned int n = 0;
00035 in >> n;
00036 double x[n], y[n];
00037 in.get(x, n);
00038 in.get(y, n);
00039 if (n>0) graph->Set(n);
00040 for (unsigned int i=0; i<n; ++i)
00041 graph->SetPoint(i, x[i], y[i]);
00042 }
00043 }
00044 }