Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

XmlController Class Reference

#include <XmlController.h>

Inheritance diagram for XmlController:

Inheritance graph
[legend]
Collaboration diagram for XmlController:

Collaboration graph
[legend]
List of all members.

Detailed Description

A base class that is the interface between GUI and the XML serialization and deserialization.

It implements the application logic which should not be in the GUI. Following the template pattern, several pure virtual member functions must be implemented in a derived class to provide a concrete implementation. The derived class will probably use an extern XML C++ tool kit, while this class is independent of any XML implementation.

Author:
Paul F. Kunz <Paul_Kunz@slac.stanford.edu>

Definition at line 52 of file XmlController.h.

Public Types

enum  Status { Success, OpenError, ParseError, NTupleError }
 Return codes of opening file. More...

Public Member Functions

virtual XmlElementaddDataSource (const DataSource *ntuple)
 Adds the DataSource to the document if it doesn't already exist.
void addViews (const std::vector< const ViewBase * > &views)
 Adds ViewBase elements to the root of the document.
bool areDataSourcesSaved (const std::vector< const ViewBase * > &views)
 Returns true if all the NTuple objects used by the views have been saved to or read from a file.
PlotterBasecreateDisplay ()
 Creates a new empty display and makes it the curent one.
virtual void createDocument (const std::string &doc_name)
 Creates an DOM Document with name doc_name.
FontBasecreateFont () const
 Creates a empty QtFont object.
ViewBasecreateView (PlotterBase *)
 Creates a new view for the current PlotterBase object and adds it to the list of views.
virtual bool fileExists (const std::string &filename) const =0
 Returns true if the specified file exists.
DataRepgetDataRep (int ref)
 Returns a pointer to the DataRep from the xml reference Id.
const DataSourcegetDataSource (int ref_id)
 Returns pointer to data source from the xml reference ID.
const std::list< ViewBase * > & getFromPasteboard (ViewFactory *factory, const std::vector< const ViewBase * > &views)
 Creates and eturns a list of objects that was copied to the pasteboard.
const std::list< ViewBase * > & getFromSelectionCopy (ViewFactory *factory, const std::vector< const ViewBase * > &views)
 Creates and returns objects that were copied to the selcection copy.
int getId (const void *address)
 Returns the unique integer identifier for given address.
PlotterBasegetPlotter (int ref)
 Returns a pointer to the PlotterBase object from the XML referend Id.
const TupleCutgetTupleCut (int ref_id)
 Returns pointer to the TupleCut from the xml reference Id.
virtual const std::list< ViewBase * > & getViews (ViewFactory *)
 Returns the list of views in the current document.
bool isPasteboardEmpty ()
 Returns true if global pasteboard is empty.
Status openFile (const std::string &filename)
 Attempts to open and parse the specified HippoDraw document.
void registerPlotter (int id, PlotterBase *plotter)
 Registers the plotter with id.
Status saveToFile (const std::vector< const ViewBase * > &views, const std::string &filename)
 Saves the document represented by list of ViewBase objects to file with name filename.
void saveToPasteboard (const std::vector< const ViewBase * > &)
 Saves the document represented by the list of ViewBase objects to the pasteboard.
void saveToSelectionCopy (const std::vector< const ViewBase * > &views)
 Saves the document represented by the list of ViewBase objects to the selection copy.
virtual bool serializeViews (const std::vector< const ViewBase * > &views)
 Serializes the ViewBase objects in views and their appropriate subcomponents.
virtual ~XmlController ()
 The destructor.

Static Public Attributes

static XmlDocumentm_xml_doc = 0
 The current document being generated or read.

Protected Member Functions

 XmlController ()
 A default constructor for avoiding creation except by itself or with derived classes.

Private Types

typedef std::map< const void *,
int >::iterator 
AddrMapIterator_t
 The iterator for memory address to unique integer identifier.

Private Member Functions

void fillNTupleMap ()
 Fills the NTuple map with NTuple objects currently in memory.
void fillTupleCutMap (const std::vector< const ViewBase * > &views)
 Fills the TupleCut map with TupleCut objecs contained in one in the list of views.
void getDataReps ()
 Creates all the DataRep objects and fills the reference map.
const std::list< ViewBase * > & getFromDocument (ViewFactory *facotry, const std::vector< const ViewBase * > &views)
 Restores the views in the current document.
void getTupleCuts ()
 Creates all the TupleCut objects and fills the reference map.
void getViews (const XmlElement *root)
 Creates the ViewBase objects described in the root XML element.
virtual void getViews ()
 Deserializes the ViewBase objects.
virtual void newDocument (const std::string &name)=0
 Creates a new document.
virtual Status openDocument (const std::string &filename)
 Opens an existing DOM Document file filename.
virtual Status openNTuples ()
 Attempts to open ntuple files in the current document and put them into the map.
void saveToDocument (const std::vector< const ViewBase * > &selviews)
 Save the ViewBase objects in selview to a XML in memory document.
 XmlController (const XmlController &)
 A private copy constructor in order to avoid copying.

Private Attributes

std::map< const void *, int > m_addr_map
 The map of memory address to unique integer identifier.
std::map< const DataSource *,
XmlElement * > 
m_data
 The map of ntuples to XmlElements for the current document.
std::map< int, DataRep * > m_datarep_map
 A mapping from DataRep Id to created DataRep.
DataRepXMLm_datarep_xml
 The singleton instance of the DataRepXML object.
XmlElementm_element
 The XmlElement object used to parse the DOM tree.
int m_id
 The next integer identifier to be generated.
std::list< std::stringm_missing_tuples
HiNTupleXMLm_ntuple
 The singleton instance of the XML handler for data source.
XmlDocumentm_pasteboard
 The pasteboard object.
std::map< int, PlotterBase * > m_plotter_map
 The mapping from PlotterBase Id to created PlotterBase.
XmlDocumentm_selectboard
 A copy of a selection.
std::map< int, const TupleCut * > m_tuple_cut_map
 A mapping from XML id to created TupleCut.
TupleCutXMLm_tuple_cut_xml
 The singleton instance of the XML handler for TupleCut objects.
std::map< int, const DataSource * > m_tuple_map
 A mapping from XML id to created ntuple.
ViewBaseXMLm_view
 The singleton instance of a ViewBaseXML object.
ViewFactorym_view_factory
 The factory to be used for creating views.
std::list< ViewBase * > m_views
 A list of reconstructoed views.


Member Typedef Documentation

typedef std::map< const void *, int >::iterator XmlController::AddrMapIterator_t [private]
 

The iterator for memory address to unique integer identifier.

Definition at line 104 of file XmlController.h.


Member Enumeration Documentation

enum XmlController::Status
 

Return codes of opening file.

Enumerator:
Success 
OpenError 
ParseError 
NTupleError 

Definition at line 58 of file XmlController.h.


Constructor & Destructor Documentation

XmlController::XmlController const XmlController  )  [private]
 

A private copy constructor in order to avoid copying.

XmlController::XmlController  )  [protected]
 

A default constructor for avoiding creation except by itself or with derived classes.

Definition at line 41 of file XmlController.cxx.

References m_datarep_xml, m_ntuple, m_tuple_cut_xml, and m_view.

XmlController::~XmlController  )  [virtual]
 

The destructor.

Definition at line 52 of file XmlController.cxx.

References m_pasteboard, and m_view.


Member Function Documentation

XmlElement * XmlController::addDataSource const DataSource ntuple  )  [virtual]
 

Adds the DataSource to the document if it doesn't already exist.

Returns the Dom element corresponding to the DataSource.

Definition at line 282 of file XmlController.cxx.

References XmlNode::appendChild(), HiNTupleXML::createElement(), XmlDocument::documentElement(), m_data, m_ntuple, and m_xml_doc.

Referenced by NTupleProjectorXML::createElement().

void XmlController::addViews const std::vector< const ViewBase * > &  views  ) 
 

Adds ViewBase elements to the root of the document.

Definition at line 255 of file XmlController.cxx.

References XmlNode::appendChild(), ViewBaseXML::createElement(), XmlDocument::documentElement(), m_view, and m_xml_doc.

Referenced by serializeViews().

bool XmlController::areDataSourcesSaved const std::vector< const ViewBase * > &  views  ) 
 

Returns true if all the NTuple objects used by the views have been saved to or read from a file.

Definition at line 180 of file XmlController.cxx.

References ViewBaseXML::areDataSourcesSaved(), and m_view.

Referenced by CanvasWindow::areDataSourcesSaved().

PlotterBase* XmlController::createDisplay  ) 
 

Creates a new empty display and makes it the curent one.

void XmlController::createDocument const std::string doc_name  )  [virtual]
 

Creates an DOM Document with name doc_name.

The document becomes the current document.

Definition at line 60 of file XmlController.cxx.

References XmlDocument::appendChild(), XmlDocument::createElement(), m_xml_doc, and newDocument().

Referenced by serializeViews().

FontBase * XmlController::createFont  )  const
 

Creates a empty QtFont object.

Definition at line 277 of file XmlController.cxx.

References m_view_factory.

ViewBase * XmlController::createView PlotterBase  ) 
 

Creates a new view for the current PlotterBase object and adds it to the list of views.

Definition at line 267 of file XmlController.cxx.

References ViewFactory::createView(), m_view_factory, and m_views.

Referenced by ViewBaseXML::getObjects().

virtual bool XmlController::fileExists const std::string filename  )  const [pure virtual]
 

Returns true if the specified file exists.

Implemented in QtXMLController.

void XmlController::fillNTupleMap  )  [private]
 

Fills the NTuple map with NTuple objects currently in memory.

Definition at line 358 of file XmlController.cxx.

References DataSourceController::getDataSources(), getId(), DataSourceController::instance(), and m_tuple_map.

Referenced by getFromDocument().

void XmlController::fillTupleCutMap const std::vector< const ViewBase * > &  views  )  [private]
 

Fills the TupleCut map with TupleCut objecs contained in one in the list of views.

Definition at line 375 of file XmlController.cxx.

References CutController::fillTupleCutList(), getId(), CutController::instance(), and m_tuple_cut_map.

Referenced by getFromDocument().

DataRep * XmlController::getDataRep int  ref  ) 
 

Returns a pointer to the DataRep from the xml reference Id.

Definition at line 327 of file XmlController.cxx.

References m_datarep_map.

Referenced by DataRepXML::createObject(), PlotterBaseXML::getCutTargets(), PlotterBaseXML::getObject(), PlotterBaseXML::handleFunction(), and PlotterBaseXML::handleTextPlotter().

void XmlController::getDataReps  )  [private]
 

Creates all the DataRep objects and fills the reference map.

Definition at line 392 of file XmlController.cxx.

References DataRepXML::createObject(), XmlDocument::documentElement(), BaseXML::fillNodeList(), XmlElement::getID(), m_datarep_map, m_datarep_xml, and m_xml_doc.

Referenced by getViews().

const DataSource * XmlController::getDataSource int  ref_id  ) 
 

Returns pointer to data source from the xml reference ID.

Definition at line 299 of file XmlController.cxx.

References m_tuple_map.

Referenced by DataRepXML::createDataRep().

const list< ViewBase * > & XmlController::getFromDocument ViewFactory facotry,
const std::vector< const ViewBase * > &  views
[private]
 

Restores the views in the current document.

Definition at line 153 of file XmlController.cxx.

References CutController::connectDataRep(), fillNTupleMap(), fillTupleCutMap(), getViews(), CutController::instance(), m_view_factory, and m_views.

Referenced by getFromPasteboard(), and getFromSelectionCopy().

const list< ViewBase * > & XmlController::getFromPasteboard ViewFactory factory,
const std::vector< const ViewBase * > &  views
 

Creates and eturns a list of objects that was copied to the pasteboard.

The parameter views is used when the an object makes a reference to object already on the canvas. For example, if an object was a DataRep with a TupleCut applied, then newly created object needs to have a reference to that TupleCut.

Definition at line 133 of file XmlController.cxx.

References getFromDocument(), m_pasteboard, and m_xml_doc.

Referenced by CanvasView::addFromPasteboard(), and CanvasView::copyFromPasteboard().

const list< ViewBase * > & XmlController::getFromSelectionCopy ViewFactory factory,
const std::vector< const ViewBase * > &  views
 

Creates and returns objects that were copied to the selcection copy.

See also:
getFromPasteboard.

Definition at line 143 of file XmlController.cxx.

References getFromDocument(), m_selectboard, and m_xml_doc.

Referenced by CanvasView::restoreFromSelectCopy().

int XmlController::getId const void *  address  ) 
 

Returns the unique integer identifier for given address.

Definition at line 467 of file XmlController.cxx.

References m_addr_map, and m_id.

Referenced by fillNTupleMap(), and fillTupleCutMap().

PlotterBase * XmlController::getPlotter int  ref  ) 
 

Returns a pointer to the PlotterBase object from the XML referend Id.

Definition at line 339 of file XmlController.cxx.

References m_plotter_map.

const TupleCut * XmlController::getTupleCut int  ref_id  ) 
 

Returns pointer to the TupleCut from the xml reference Id.

Definition at line 310 of file XmlController.cxx.

References m_tuple_cut_map.

Referenced by NTupleProjectorXML::addCuts(), and PlotterBaseXML::handleCutPlotter().

void XmlController::getTupleCuts  )  [private]
 

Creates all the TupleCut objects and fills the reference map.

Definition at line 414 of file XmlController.cxx.

References XmlDocument::documentElement(), BaseXML::fillNodeList(), TupleCutXML::getObject(), m_tuple_cut_map, m_tuple_cut_xml, and m_xml_doc.

Referenced by getViews().

const list< ViewBase * > & XmlController::getViews ViewFactory  )  [virtual]
 

Returns the list of views in the current document.

The views are created using the specified view factory.

Definition at line 169 of file XmlController.cxx.

References getViews(), m_view_factory, m_views, and m_xml_doc.

void XmlController::getViews const XmlElement root  )  [private]
 

Creates the ViewBase objects described in the root XML element.

void XmlController::getViews  )  [private, virtual]
 

Deserializes the ViewBase objects.

Definition at line 442 of file XmlController.cxx.

References XmlDocument::documentElement(), BaseXML::fillNodeList(), getDataReps(), ViewBaseXML::getObjects(), getTupleCuts(), m_view, m_views, and m_xml_doc.

Referenced by getFromDocument(), getViews(), and CanvasView::initFromFile().

bool XmlController::isPasteboardEmpty  ) 
 

Returns true if global pasteboard is empty.

Definition at line 126 of file XmlController.cxx.

References m_pasteboard.

virtual void XmlController::newDocument const std::string name  )  [private, pure virtual]
 

Creates a new document.

A derived class should set the member m_xml_doc to point to a concrete class derived from the abstract class XmlDocument.

Implemented in QtXMLController.

Referenced by createDocument(), and openDocument().

XmlController::Status XmlController::openDocument const std::string filename  )  [private, virtual]
 

Opens an existing DOM Document file filename.

The application's current directory will be set to the path to the file.

Returns:
XmlController::Success if successful, otherwise returns another member of the Status enumeration.

Definition at line 70 of file XmlController.cxx.

References m_xml_doc, newDocument(), OpenError, XmlDocument::OpenError, ParseError, XmlDocument::ParseError, XmlDocument::setContent(), and Success.

Referenced by openFile().

XmlController::Status XmlController::openFile const std::string filename  ) 
 

Attempts to open and parse the specified HippoDraw document.

Returns Success if successful, otherwise returns another member of the OpenStatus enumeration.

Definition at line 83 of file XmlController.cxx.

References m_tuple_cut_map, m_tuple_map, m_views, openDocument(), openNTuples(), and Success.

Referenced by CanvasView::initFromFile().

XmlController::Status XmlController::openNTuples  )  [private, virtual]
 

Attempts to open ntuple files in the current document and put them into the map.

Returns Success if successful, otherwise returns NTupleError.

Definition at line 97 of file XmlController.cxx.

References XmlDocument::documentElement(), BaseXML::fillNodeList(), XmlElement::getID(), HiNTupleXML::getName(), HiNTupleXML::getObject(), m_missing_tuples, m_ntuple, m_tuple_map, m_xml_doc, NTupleError, and Success.

Referenced by openFile().

void XmlController::registerPlotter int  id,
PlotterBase plotter
 

Registers the plotter with id.

Definition at line 351 of file XmlController.cxx.

References m_plotter_map.

void XmlController::saveToDocument const std::vector< const ViewBase * > &  selviews  )  [private]
 

Save the ViewBase objects in selview to a XML in memory document.

If an ViewBase objects in allviews is an Observer of of one in selviews, then save it as well.

Definition at line 211 of file XmlController.cxx.

References m_data, and serializeViews().

Referenced by saveToPasteboard(), and saveToSelectionCopy().

XmlController::Status XmlController::saveToFile const std::vector< const ViewBase * > &  views,
const std::string filename
 

Saves the document represented by list of ViewBase objects to file with name filename.

Returns 0 if successful.

Definition at line 240 of file XmlController.cxx.

References m_data, m_xml_doc, OpenError, XmlDocument::saveToFile(), serializeViews(), Success, and XmlDocument::Success.

Referenced by CanvasView::saveAs().

void XmlController::saveToPasteboard const std::vector< const ViewBase * > &   ) 
 

Saves the document represented by the list of ViewBase objects to the pasteboard.

If any ViewBase objects in allviews is an Observer of selviews, then save it as well. Returns the list of ViewBase objects actually saved to pasteboard.

Definition at line 220 of file XmlController.cxx.

References m_pasteboard, m_xml_doc, and saveToDocument().

Referenced by CanvasView::copySelectedToPasteboard(), and CanvasView::deleteSelected().

void XmlController::saveToSelectionCopy const std::vector< const ViewBase * > &  views  ) 
 

Saves the document represented by the list of ViewBase objects to the selection copy.

If any ViewBase objects in allviews is an Observer of selviews, then save it as well. Returns the list of ViewBase objects actually saved to pasteboard.

Definition at line 230 of file XmlController.cxx.

References m_selectboard, m_xml_doc, and saveToDocument().

Referenced by CanvasView::contentsMousePressEvent().

bool XmlController::serializeViews const std::vector< const ViewBase * > &  views  )  [virtual]
 

Serializes the ViewBase objects in views and their appropriate subcomponents.

Returns true if successful, otherwise returns false.

Definition at line 198 of file XmlController.cxx.

References addViews(), createDocument(), and m_xml_doc.

Referenced by saveToDocument(), and saveToFile().


Member Data Documentation

std::map< const void *, int > XmlController::m_addr_map [private]
 

The map of memory address to unique integer identifier.

Definition at line 100 of file XmlController.h.

Referenced by getId().

std::map< const DataSource *, XmlElement * > XmlController::m_data [private]
 

The map of ntuples to XmlElements for the current document.

Definition at line 96 of file XmlController.h.

Referenced by addDataSource(), saveToDocument(), and saveToFile().

std::map< int, DataRep * > XmlController::m_datarep_map [private]
 

A mapping from DataRep Id to created DataRep.

Definition at line 117 of file XmlController.h.

Referenced by getDataRep(), and getDataReps().

DataRepXML* XmlController::m_datarep_xml [private]
 

The singleton instance of the DataRepXML object.

Definition at line 126 of file XmlController.h.

Referenced by getDataReps(), and XmlController().

XmlElement* XmlController::m_element [private]
 

The XmlElement object used to parse the DOM tree.

Definition at line 135 of file XmlController.h.

int XmlController::m_id [private]
 

The next integer identifier to be generated.

Definition at line 108 of file XmlController.h.

Referenced by getId().

std::list< std::string > XmlController::m_missing_tuples [private]
 

Definition at line 67 of file XmlController.h.

Referenced by openNTuples().

HiNTupleXML* XmlController::m_ntuple [private]
 

The singleton instance of the XML handler for data source.

Definition at line 129 of file XmlController.h.

Referenced by addDataSource(), openNTuples(), and XmlController().

XmlDocument* XmlController::m_pasteboard [private]
 

The pasteboard object.

Definition at line 87 of file XmlController.h.

Referenced by getFromPasteboard(), isPasteboardEmpty(), saveToPasteboard(), and ~XmlController().

std::map< int, PlotterBase * > XmlController::m_plotter_map [private]
 

The mapping from PlotterBase Id to created PlotterBase.

Definition at line 120 of file XmlController.h.

Referenced by getPlotter(), and registerPlotter().

XmlDocument* XmlController::m_selectboard [private]
 

A copy of a selection.

Definition at line 90 of file XmlController.h.

Referenced by getFromSelectionCopy(), and saveToSelectionCopy().

std::map< int, const TupleCut * > XmlController::m_tuple_cut_map [private]
 

A mapping from XML id to created TupleCut.

Definition at line 114 of file XmlController.h.

Referenced by fillTupleCutMap(), getTupleCut(), getTupleCuts(), and openFile().

TupleCutXML* XmlController::m_tuple_cut_xml [private]
 

The singleton instance of the XML handler for TupleCut objects.

Definition at line 132 of file XmlController.h.

Referenced by getTupleCuts(), and XmlController().

std::map< int, const DataSource * > XmlController::m_tuple_map [private]
 

A mapping from XML id to created ntuple.

Definition at line 111 of file XmlController.h.

Referenced by fillNTupleMap(), getDataSource(), openFile(), and openNTuples().

ViewBaseXML* XmlController::m_view [private]
 

The singleton instance of a ViewBaseXML object.

Definition at line 123 of file XmlController.h.

Referenced by addViews(), areDataSourcesSaved(), getViews(), XmlController(), and ~XmlController().

ViewFactory* XmlController::m_view_factory [private]
 

The factory to be used for creating views.

Definition at line 63 of file XmlController.h.

Referenced by createFont(), createView(), getFromDocument(), and getViews().

std::list< ViewBase * > XmlController::m_views [private]
 

A list of reconstructoed views.

Definition at line 93 of file XmlController.h.

Referenced by createView(), getFromDocument(), getViews(), and openFile().

XmlDocument * XmlController::m_xml_doc = 0 [static]
 

The current document being generated or read.

This member is made public so that element creator that need it do not need to have it passed as argument.

Definition at line 39 of file XmlController.cxx.

Referenced by addDataSource(), addViews(), NTupleProjectorXML::createChildren(), NTupleXML::createChildren2D(), NTupleXML::createChildren3D(), PlotterBaseXML::createCutChildren(), createDocument(), TupleCutXML::createElement(), BinToColorXML::createElement(), BaseXML::createElement(), DataRepXML::createFunctionTargetChild(), PlotterBaseXML::createTextChildren(), getDataReps(), getFromPasteboard(), getFromSelectionCopy(), getTupleCuts(), getViews(), QtXMLController::newDocument(), openDocument(), openNTuples(), saveToFile(), saveToPasteboard(), saveToSelectionCopy(), and serializeViews().


The documentation for this class was generated from the following files:
Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3