]> Creatis software - bbtk.git/blob - kernel/src/bbtkConfigurationFile.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkConfigurationFile.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkConfigurationFile.h,v $
5   Language:  C++
6   Date:      $Date: 2008/02/13 14:08:25 $
7   Version:   $Revision: 1.3 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See doc/license.txt or
11   http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
12
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16
17 =========================================================================*/
18 /**
19  *\file
20  *\brief Class bbtk::ConfigurationFile
21  */
22 /**
23  *\class bbtk::ConfigurationFile
24  *\brief DDD
25  *
26  */
27
28 #ifndef __bbtkConfigurationFile_h__
29 #define __bbtkConfigurationFile_h__
30
31 #include "bbtkSystem.h"
32 #include <string>
33
34
35 #ifdef WIN32
36 #define _CRT_SECURE_NO_DEPRECATE
37 #endif
38
39 #include <stdio.h>
40 #include "xmlParser.h"
41 #include <iostream>
42 #include <fstream>
43 #include <sstream>
44 #include <vector>
45
46
47 namespace bbtk
48 {
49 //==========================================================================
50 class BBTK_EXPORT  ConfigurationException
51 {
52 public:
53   ConfigurationException(const std::string& message) : mMessage(message) {}
54
55   std::string mMessage;
56 };
57
58
59 //==========================================================================
60 class BBTK_EXPORT ConfigurationFile
61 {
62 public:
63
64   static ConfigurationFile const &GetInstance()
65   {
66     static ConfigurationFile f;
67     return f;
68   }
69
70   ~ConfigurationFile();
71
72 private:
73   ConfigurationFile();
74   void InstallPath ();
75
76 public:
77   inline const std::string& Get_description() const
78      { return mDescription;}
79   inline const std::string& Get_url() const
80      { return mUrl;}
81   inline const std::string& Get_data_path() const
82      { return mData_path;}  
83   inline const std::string& Get_file_separator() const
84      { return mFile_separator;}
85
86   inline const std::string& Get_bin_path() const
87      { return mBin_path;}
88   inline const std::string& Get_install_path() const
89      { return mInstall_path;}
90   inline const std::string& Get_doc_path() const
91      { return mDoc_path;}
92   inline const std::string& Get_rsc_path() const
93      { return mRsc_path;}
94
95   inline const std::vector<std::string>& Get_bbs_paths() const
96      { return mBbs_paths;}
97   inline const std::vector<std::string>& Get_package_paths() const
98      { return mPackage_paths;}
99   inline const std::string& Get_config_xml_full_path() const
100      { return mConfig_xml_full_path;}
101   inline const std::string& Get_default_temp_dir() const
102      { return mDefault_temp_dir;}
103            
104   private:
105   void Read(const std::string& fileName);
106   void GetTextOrClear(const XMLNode& node, std::string& var); 
107   char *GetExecutablePath();
108   bool FileExists(std::string strFilename);
109   void CreateConfigXML( char *rootDirectory );
110     
111 // Attributes :
112   private :
113   std::string mDescription; 
114   /// Where is the file bbtk_config.xml
115   std::string mConfig_xml_full_path;  
116
117   /// Set automatically :
118   /// The path to the executable (usually bbi)
119   std::string mBin_path;
120   /// The path to the install prefix (=mBinPath+"/..")
121   std::string mInstall_path;
122   /// The relative path to the doc folder (=BBTK_DOC_REL_PATH)
123   std::string mDoc_rel_path;
124   /// The path to the doc folder (=mInstall_path+"/"+mDoc_rel_path)
125   std::string mDoc_path;
126   /// The relative path to the doc folder (=BBTK_BBS_REL_PATH)
127   std::string mBbs_rel_path;
128   /// The path to the bbs folder (=mInstall_path+"/"+mBbs_rel_path)
129   std::string mBbs_path;
130   /// The relative path to the rsc folder (=BBTK_RSC_REL_PATH)
131   std::string mRsc_rel_path;
132   /// The path to the rsc folder (=mInstall_path+"/"+mRsc_rel_path)
133   std::string mRsc_path;
134   /// The path to the bbtk data folder 
135   /// Initialized to mInstall_path+"/"+BBTK_DATA_REL_PATH
136   /// But can be overriden by value read from bbtk_config.xml
137   std::string mData_path;
138
139   /// / or \, depending on the OS
140   std::string mFile_separator;
141
142   /// Read from bbtk_config.xml file
143   /// Where the doc is
144   std::string mUrl;
145   /// Scripts  
146   std::vector<std::string> mBbs_paths; 
147   /// Package dlls    
148   std::vector<std::string> mPackage_paths;
149   /// If Packages link against extern dlls
150   std::vector<std::string> mExt_dll_paths;
151   /// Default directory for generating Graph
152   std::string mDefault_temp_dir;       
153   };
154
155
156 }// namespace bbtk
157
158
159
160 #endif
161