]> 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/14 10:47:51 $
7   Version:   $Revision: 1.5 $
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 <iostream>
41 #include <fstream>
42 #include <sstream>
43 #include <vector>
44
45
46 namespace bbtk
47 {
48   //==========================================================================
49   class BBTK_EXPORT  ConfigurationException
50   {
51   public:
52     ConfigurationException(const std::string& message) : mMessage(message) {}
53     
54     std::string mMessage;
55   };
56   //==========================================================================
57   
58   //==========================================================================
59   class BBTK_EXPORT ConfigurationFile
60   {
61   public:
62     
63     static ConfigurationFile const &GetInstance()
64     {
65       static ConfigurationFile f;
66       return f;
67     }
68     
69     ~ConfigurationFile();
70     
71   private:
72     ConfigurationFile();
73     void InstallPath ();
74     
75   public:
76     void GetHelp(int level) const;
77
78     inline const std::string& Get_description() const
79     { return mDescription;}
80     //    inline const std::string& Get_url() const
81     //    { return mUrl;}
82     inline const std::string& Get_data_path() const
83     { return mData_path;}  
84     inline const std::string& Get_file_separator() const
85     { return mFile_separator;}
86     
87     inline const std::string& Get_bin_path() const
88     { return mBin_path;}
89     inline const std::string& Get_install_path() const
90     { return mInstall_path;}
91     inline const std::string& Get_doc_path() const
92     { return mDoc_path;}
93     inline const std::string& Get_rsc_path() const
94     { return mRsc_path;}
95     
96     inline const std::vector<std::string>& Get_bbs_paths() const
97     { return mBbs_paths;}
98     inline const std::vector<std::string>& Get_package_paths() const
99     { return mPackage_paths;}
100     inline const std::string& Get_config_xml_full_path() const
101     { return mConfig_xml_full_path;}
102     inline const std::string& Get_default_temp_dir() const
103     { return mDefault_temp_dir;}
104     
105   private:
106     void Read(const std::string& fileName);
107      std::string GetExecutablePath();
108      void CreateConfigXML( char *rootDirectory );
109     
110     // Attributes :
111   private :
112     std::string mDescription; 
113     /// Where is the file bbtk_config.xml
114     std::string mConfig_xml_full_path;  
115     
116     /// Set automatically :
117     /// The path to the executable (usually bbi)
118     std::string mBin_path;
119     /// The path to the install prefix (=mBinPath+"/..")
120     std::string mInstall_path;
121     /// The relative path to the doc folder (=BBTK_DOC_REL_PATH)
122     std::string mDoc_rel_path;
123     /// The path to the doc folder (=mInstall_path+"/"+mDoc_rel_path)
124     std::string mDoc_path;
125     /// The relative path to the doc folder (=BBTK_BBS_REL_PATH)
126     std::string mBbs_rel_path;
127     /// The path to the bbs folder (=mInstall_path+"/"+mBbs_rel_path)
128     std::string mBbs_path;
129     /// The relative path to the rsc folder (=BBTK_RSC_REL_PATH)
130     std::string mRsc_rel_path;
131     /// The path to the rsc folder (=mInstall_path+"/"+mRsc_rel_path)
132     std::string mRsc_path;
133     /// The path to the bbtk data folder 
134     /// Initialized to mInstall_path+"/"+BBTK_DATA_REL_PATH
135     /// But can be overriden by value read from bbtk_config.xml
136     std::string mData_path;
137     
138     /// / or \, depending on the OS
139     std::string mFile_separator;
140     
141     /// Read from bbtk_config.xml file
142     /// Where the doc is
143     std::string mUrl;
144     /// Scripts  
145     std::vector<std::string> mBbs_paths; 
146     /// Package dlls    
147     std::vector<std::string> mPackage_paths;
148     /// If Packages link against extern dlls
149     std::vector<std::string> mExt_dll_paths;
150     /// Temp directory for generated data
151     std::string mDefault_temp_dir;       
152   };
153   
154   
155 }// namespace bbtk
156
157
158
159 #endif
160