]> Creatis software - bbtk.git/blob - kernel/src/bbtkConfigurationFile.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkConfigurationFile.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkConfigurationFile.h,v $
4   Language:  C++
5   Date:      $Date: 2008/10/17 08:18:13 $
6   Version:   $Revision: 1.10 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32  *\file
33  *\brief Class bbtk::ConfigurationFile
34  */
35 /**
36  *\class bbtk::ConfigurationFile
37  *\brief DDD
38  *
39  */
40
41 #ifndef __bbtkConfigurationFile_h__
42 #define __bbtkConfigurationFile_h__
43
44 #include "bbtkSystem.h"
45 #include <string>
46
47
48 #ifdef WIN32
49 #define _CRT_SECURE_NO_DEPRECATE
50 #endif
51
52 #include <stdio.h>
53 #include <iostream>
54 #include <fstream>
55 #include <sstream>
56 #include <vector>
57
58
59
60 namespace bbtk
61 {
62   //==========================================================================
63   class BBTK_EXPORT  ConfigurationException
64   {
65   public:
66     ConfigurationException(const std::string& message) : mMessage(message) {}
67     
68     std::string mMessage;
69   };
70   //==========================================================================
71   
72   //==========================================================================
73   class BBTK_EXPORT ConfigurationFile
74   {
75   public:
76     
77     static ConfigurationFile& GetInstance()
78     {
79       static ConfigurationFile f;
80       return f;
81     }
82     
83     ~ConfigurationFile();
84     
85   private:
86     ConfigurationFile();
87     void InstallPath ();
88     
89   public:
90     void GetHelp(int level) const;
91
92     inline const std::string& Get_description() const
93     { return mDescription;}
94     //    inline const std::string& Get_url() const
95     //    { return mUrl;}
96     inline const std::string& Get_data_path() const
97     { return mData_path;}  
98     inline const std::string& Get_file_separator() const
99         { return mFile_separator;}
100     
101     inline const std::string& Get_bin_path() const
102     { return mBin_path;}
103     inline const std::string& Get_install_path() const
104     { return mInstall_path;}
105     inline const std::string& Get_doc_path() const
106     { return mDoc_path;}
107     inline const std::string& Get_rsc_path() const
108     { return mRsc_path;}
109     
110     inline const std::string& Get_root_bbs_path() const
111     { return mBbs_path;}
112     inline const std::vector<std::string>& Get_bbs_paths() const
113     { return mBbs_paths;}
114     inline const std::vector<std::string>& Get_package_paths() const
115     { return mPackage_paths;}
116     inline const std::string& Get_config_xml_full_path() const
117     { return mConfig_xml_full_path;}
118     inline const std::string& Get_default_temp_dir() const
119     { return mDefault_temp_dir;}
120
121     bool AddPackagePathsAndWrite( const std::string& package_root_path );
122     
123   private:
124     void Read(const std::string& fileName);
125      std::string GetExecutablePath();
126      void CreateConfigXML( char *rootDirectory );
127     
128     // Attributes :
129   private :
130     std::string mDescription; 
131     /// Where is the file bbtk_config.xml
132     std::string mConfig_xml_full_path;  
133     
134     /// Set automatically :
135     /// The path to the executable (usually bbi)
136     std::string mBin_path;
137     /// The path to the install prefix (=mBinPath+"/..")
138     std::string mInstall_path;
139     /// The relative path to the doc folder (=BBTK_DOC_REL_PATH)
140     std::string mDoc_rel_path;
141     /// The path to the doc folder (=mInstall_path+"/"+mDoc_rel_path)
142     std::string mDoc_path;
143     /// The relative path to the doc folder (=BBTK_BBS_REL_PATH)
144     std::string mBbs_rel_path;
145     /// The path to the bbs folder (=mInstall_path+"/"+mBbs_rel_path)
146     std::string mBbs_path;
147     /// The relative path to the rsc folder (=BBTK_RSC_REL_PATH)
148     std::string mRsc_rel_path;
149     /// The path to the rsc folder (=mInstall_path+"/"+mRsc_rel_path)
150     std::string mRsc_path;
151     /// The path to the bbtk data folder 
152     /// Initialized to mInstall_path+"/"+BBTK_DATA_REL_PATH
153     /// But can be overriden by value read from bbtk_config.xml
154     std::string mData_path;
155     
156     /// / or \, depending on the OS
157     std::string mFile_separator;
158     
159     /// Read from bbtk_config.xml file
160     /// Where the doc is
161     std::string mUrl;
162     /// Scripts  
163     std::vector<std::string> mBbs_paths; 
164     /// Package dlls    
165     std::vector<std::string> mPackage_paths;
166     /// If Packages link against extern dlls
167     std::vector<std::string> mExt_dll_paths;
168     /// Temp directory for generated data
169     std::string mDefault_temp_dir;       
170   };
171   
172   
173 }// namespace bbtk
174
175
176
177 #endif
178