1 #ifndef __JGIZMO__JMANAGER__
2 #define __JGIZMO__JMANAGER__
39 template<
class JKey_t,
class JValue_t = TObject>
42 public std::map<JKey_t, JPointer<JValue_t> >
68 std::ios::fmtflags format = std::ios::fmtflags()) :
81 master->SetDirectory(0);
83 if (
string(master->GetName()).find(
wc) == string::npos) {
84 THROW(
JException,
"JManager: Missing wildcard " << master->GetName() <<
' ' <<
wc);
108 this->
set((JValue_t*) manager.
get()->Clone());
110 this->
get()->Reset();
111 this->
get()->SetDirectory(0);
113 if (
string(this->
get()->GetName()).find(
wc) == string::npos) {
125 for (
typename map_type::iterator i = this->begin(); i != this->end(); ++i) {
129 static_cast<map_type&>(*this).clear();
143 typename map_type::iterator i = this->find(key);
145 if (i == this->end()) {
147 string buffer = this->
get()->GetName();
148 string::size_type ipos = buffer.find(
wc);
156 buffer.replace(ipos, 1, os.str());
158 JValue_t* p = (JValue_t*) this->
get()->Clone(buffer.c_str());
163 this->insert(make_pair(key,p));
182 static JManager Read(TDirectory& in,
const char*
const master,
const char wildcard)
188 TString buffer = master;
190 const Ssiz_t pos = buffer.Index(wildcard);
192 const TString a = buffer(0, pos);
193 const TString b = buffer(pos+1, buffer.Length());
195 buffer.ReplaceAll(
"[",
"\\[");
196 buffer.ReplaceAll(
"]",
"\\]");
198 buffer.ReplaceAll(wildcard,
".*");
200 const TRegexp regexp(buffer);
202 TIter iter(in.GetListOfKeys());
204 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
206 const TString tag(key->GetName());
210 if (tag.Index(regexp) != -1) {
212 JValue_t* p = dynamic_cast<JValue_t*>(key->ReadObj());
218 string buffer = p->GetName();
220 if (a.Length() != 0) { buffer.replace(buffer.find(a), a.Length(),
""); }
221 if (b.Length() != 0) { buffer.replace(buffer.find(b), b.Length(),
""); }
225 istringstream(buffer) >> key;
227 manager.insert(make_pair(key, p));
258 void Write(TDirectory& out,
const bool wm =
false)
260 for (
typename map_type::iterator i = this->begin(); i != this->end(); ++i) {
261 out.WriteTObject(i->second);
265 out.WriteTObject(this->
get());
276 void Write(
const char* file_name,
const bool wm =
false)
278 TFile out(file_name,
"RECREATE");
280 this->
Write(out, wm) ;