]> Creatis software - bbtk.git/blob - kernel/src/bbtkConfigurationFile.h
Fixed :
[bbtk.git] / kernel / src / bbtkConfigurationFile.h
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbtkConfigurationFile.h,v $
5   Language:  C++
6   Date:      $Date: 2008/03/26 08:27:19 $
7   Version:   $Revision: 1.7 $
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     // file separator
47 #if defined(_WIN32)
48 #define VALID_FILE_SEPARATOR "\\"
49 #define INVALID_FILE_SEPARATOR "/"
50 #else
51 #define INVALID_FILE_SEPARATOR "\\"
52 #define VALID_FILE_SEPARATOR "/"
53 #endif
54
55
56
57 namespace bbtk
58 {
59   //==========================================================================
60   class BBTK_EXPORT  ConfigurationException
61   {
62   public:
63     ConfigurationException(const std::string& message) : mMessage(message) {}
64     
65     std::string mMessage;
66   };
67   //==========================================================================
68   
69   //==========================================================================
70   class BBTK_EXPORT ConfigurationFile
71   {
72   public:
73     
74     static ConfigurationFile const &GetInstance()
75     {
76       static ConfigurationFile f;
77       return f;
78     }
79     
80     ~ConfigurationFile();
81     
82   private:
83     ConfigurationFile();
84     void InstallPath ();
85     
86   public:
87     void GetHelp(int level) const;
88
89     inline const std::string& Get_description() const
90     { return mDescription;}
91     //    inline const std::string& Get_url() const
92     //    { return mUrl;}
93     inline const std::string& Get_data_path() const
94     { return mData_path;}  
95     inline const std::string& Get_file_separator() const
96         { return mFile_separator;}
97     
98     inline const std::string& Get_bin_path() const
99     { return mBin_path;}
100     inline const std::string& Get_install_path() const
101     { return mInstall_path;}
102     inline const std::string& Get_doc_path() const
103     { return mDoc_path;}
104     inline const std::string& Get_rsc_path() const
105     { return mRsc_path;}
106     
107     inline const std::string& Get_root_bbs_path() const
108     { return mBbs_path;}
109     inline const std::vector<std::string>& Get_bbs_paths() const
110     { return mBbs_paths;}
111     inline const std::vector<std::string>& Get_package_paths() const
112     { return mPackage_paths;}
113     inline const std::string& Get_config_xml_full_path() const
114     { return mConfig_xml_full_path;}
115     inline const std::string& Get_default_temp_dir() const
116     { return mDefault_temp_dir;}
117     
118   private:
119     void Read(const std::string& fileName);
120      std::string GetExecutablePath();
121      void CreateConfigXML( char *rootDirectory );
122     
123     // Attributes :
124   private :
125     std::string mDescription; 
126     /// Where is the file bbtk_config.xml
127     std::string mConfig_xml_full_path;  
128     
129     /// Set automatically :
130     /// The path to the executable (usually bbi)
131     std::string mBin_path;
132     /// The path to the install prefix (=mBinPath+"/..")
133     std::string mInstall_path;
134     /// The relative path to the doc folder (=BBTK_DOC_REL_PATH)
135     std::string mDoc_rel_path;
136     /// The path to the doc folder (=mInstall_path+"/"+mDoc_rel_path)
137     std::string mDoc_path;
138     /// The relative path to the doc folder (=BBTK_BBS_REL_PATH)
139     std::string mBbs_rel_path;
140     /// The path to the bbs folder (=mInstall_path+"/"+mBbs_rel_path)
141     std::string mBbs_path;
142     /// The relative path to the rsc folder (=BBTK_RSC_REL_PATH)
143     std::string mRsc_rel_path;
144     /// The path to the rsc folder (=mInstall_path+"/"+mRsc_rel_path)
145     std::string mRsc_path;
146     /// The path to the bbtk data folder 
147     /// Initialized to mInstall_path+"/"+BBTK_DATA_REL_PATH
148     /// But can be overriden by value read from bbtk_config.xml
149     std::string mData_path;
150     
151     /// / or \, depending on the OS
152     std::string mFile_separator;
153     
154     /// Read from bbtk_config.xml file
155     /// Where the doc is
156     std::string mUrl;
157     /// Scripts  
158     std::vector<std::string> mBbs_paths; 
159     /// Package dlls    
160     std::vector<std::string> mPackage_paths;
161     /// If Packages link against extern dlls
162     std::vector<std::string> mExt_dll_paths;
163     /// Temp directory for generated data
164     std::string mDefault_temp_dir;       
165   };
166   
167   
168 }// namespace bbtk
169
170
171
172 #endif
173