Hi Fons,
On Mon, 2006-10-30 at 17:50 +0100, Fons Rademakers wrote:
> Hi Valeri,
>
> yes I can expose the content of config.h via TROOT.
I suggest, if you do that, that you make a dedicated singleton class (perhaps with interfaces from TROOT) that looks something like
class TROOTSourceConfig { public: static TROOTSourceConfig& Instance() { if (!fgInstance) fgInstance = new TROOTSourceConfig; return *fgInstance; } const char* GetBinDir() const { return GetEnvOrFixed(fBinDir, "ROOTBINDIR", "bin", ROOTBINDIR"); } // .. More like this protected: TROOTSourceConfig() {} TROOTSourceConfig(const TROOTSourceConfig&) {} TROOTSourceConfig& operator=(const TROOTSourceConfig&) { return *this; } const char* GetEnvOrFixed(TString& var, const char* env, const char* postfix, const char* fixed) const { if (var.IsNull()) { const char* tmp = 0; if ((tmp = gROOT->Getenv(env))) var = tmp; else if ((tmp = gROOT->Getenv("ROOTSYS"))) var = Form("%s/%s", tmp, postfix); else var = fixed; if (tmp) delete tmp; } return var.Data(); } mutable TString fBinDir; // ... more like this
In this way, the same compiled code can be used for both an environment driven install and a fixed location install. If TString is substituded with `std::string', the TROOT::Getenv calls are substituted with `std::getenv' calls, and the Form call is substituted with an internal function, this code could also be used in start=up programs like `root', `rootd', etc. - that is, programs that may not load `libCore' immediately.
If a function like
bool ReadFromFile(const char* file) { std::ifstream in(file); if (!in) return false; while (true) { std::string line; bool done = false; while (true) { char c = in.peek(); switch (c) { case ' ': // Leading white space case '\t': case '\n': in.get(); break; case '#': // Comment line std::getline(in, line); break; default: done = true; break; } if (done) break; } // Get key std::string key; in >> key; if (key[key.size()-1] == ':') key.erase(key.size()-1); // Read white space, and optional `:' while (true) { bool done = false; while (true) { char c = in.peek(); switch (c) { case ' ': // Leading white space case '\t': case '\n': // Allow broken lines case ':': in.get(); break; case '#': // Comment line std::getline(in, line); break; default: done = true; break; } if (done) break; } std::string val; in >> val; if (key == "BinDir") fBinDir = val; else if (key == "LibDir") fLibDir = val; ... } return true; }
This would allow programs to read fixed settings from a (user specified) file, making it easier to make the code relocatable (there's still a problem with the dynamic library path though). For example, one could add a command line switch to `root' that allowed the user to select which file to read from. All this could of course be done via TEnv if it didn't depend on `libCore'.
Yours,
-- ___ | Christian Holm Christensen |_| | ------------------------------------------------------------- | | Address: Sankt Hansgade 23, 1. th. Phone: (+45) 35 35 96 91 _| DK-2200 Copenhagen N Cell: (+45) 24 61 85 91 _| Denmark Office: (+45) 353 25 404 ____| Email: cholm_at_nbi.dk Web: www.nbi.dk/~cholm | |Received on Tue Oct 31 2006 - 09:24:32 MET
This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:32:01 MET