00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef LWH_TreeFactory_H
00010 #define LWH_TreeFactory_H
00011
00012
00013
00014
00015 #include "AITreeFactory.h"
00016 #include <string>
00017 #include <stdexcept>
00018 #include "Tree.h"
00019
00020 namespace LWH {
00021
00022 using namespace AIDA;
00023
00027 class TreeFactory: public ITreeFactory {
00028
00029 public:
00030
00032 virtual ~TreeFactory() {
00033 clear();
00034 }
00035
00039 ITree * create() {
00040 Tree * tree = new Tree;
00041 trees.insert(tree);
00042 return tree;
00043 }
00044
00053 Tree * createTree(const std::string & storeName) {
00054 return new Tree(storeName);
00055 }
00056
00068 ITree * create(const std::string & storeName,
00069 const std::string & storeType = "",
00070 bool readOnly = false, bool createNew = false,
00071 const std::string & = "") {
00072 if ( storeType != "xml" && storeType != "" && storeType != "flat" )
00073 throw std::runtime_error("Can only store trees in xml or flat format.");
00074 if ( readOnly || !createNew )
00075 throw std::runtime_error("Cannot read in trees.");
00076 return new Tree(storeName, storeType != "flat");
00077 }
00078
00079 private:
00080
00082 void clear() {
00083 for ( std::set<Tree *>::iterator it = trees.begin();
00084 it != trees.end(); ++it ) delete *it;
00085 trees.clear();
00086 }
00087
00089 std::set<Tree *> trees;
00090
00091 };
00092
00093 }
00094
00095 #endif