]> Creatis software - bbtk.git/blob - kernel/src/bbtkConfigurationFile.h
Convert bbtk from GDCM to GDCM2 (cmakefiles and cxx files).
[bbtk.git] / kernel / src / bbtkConfigurationFile.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkConfigurationFile.h,v $
4   Language:  C++
5   Date:      $Date: 2010/11/22 16:44:27 $
6   Version:   $Revision: 1.12 $
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   #if __VISUALC__ < 1400
50         #define _CRT_SECURE_NO_DEPRECATE
51   #endif
52 #endif
53
54 #include <stdio.h>
55 #include <iostream>
56 #include <fstream>
57 #include <sstream>
58 #include <vector>
59
60
61
62 namespace bbtk
63 {
64   //==========================================================================
65   class BBTK_EXPORT  ConfigurationException
66   {
67   public:
68     ConfigurationException(const std::string& message) : mMessage(message) {}
69     
70     std::string mMessage;
71   };
72   //==========================================================================
73   
74   //==========================================================================
75   class BBTK_EXPORT ConfigurationFile
76   {
77   public:
78     
79     static ConfigurationFile& GetInstance()
80     {
81       static ConfigurationFile f;
82       return f;
83     }
84     
85     ~ConfigurationFile();
86     
87     void GetHelp(int level) const;
88
89     /// Returns true iff the directory .bbtk has been created on construction
90     inline bool DotBbtkIsNew() { return mDot_bbtk_is_new; }
91
92     inline const std::string& Get_description() const
93     { return mDescription;}
94
95     inline const std::string& Get_data_path() const
96     { return mData_path;}  
97     inline const std::string& Get_file_separator() const
98         { return mFile_separator;}
99     
100     inline const std::string& Get_dot_bbtk_path() const
101     { return mDot_bbtk_path;}
102     inline const std::string& Get_bin_path() const
103     { return mBin_path;}
104     inline const std::string& Get_install_path() const
105     { return mInstall_path;}
106     inline const std::string& Get_doc_path() const
107     { return mDoc_path;}
108       
109     inline const std::string& Get_root_bbs_path() const
110     { return mBbs_path;}
111     inline const std::vector<std::string>& Get_bbs_paths() const
112     { return mBbs_paths;}
113     inline const std::vector<std::string>& Get_package_paths() const
114     { return mPackage_paths;}
115     inline const std::string& Get_config_xml_full_path() const
116     { return mConfig_xml_full_path;}
117     inline const std::string& Get_default_temp_dir() const
118     { return mTemp_path;}
119
120     bool AddPackagePathsAndWrite( const std::string& package_root_path );
121     
122   private:
123     ConfigurationFile();
124     void InstallPath ();
125     void Read(const std::string& fileName);
126     void CreateConfigXML( char *rootDirectory );
127     void InitializeDotBbtkStructure();
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 .bbtk user's dir (e.g. /home/username/.bbtk)
138     std::string mDot_bbtk_path;
139     /// The path to the install prefix (=mBinPath+"/..")
140     std::string mInstall_path;
141     /// The path to the doc folder (=mDot_bbtk_path+"/doc")
142     std::string mDoc_path;
143     /// Temp directory for generated data (=mDot_bbtk_path+"/tmp")
144     std::string mTemp_path;      
145     /// The relative path to the doc folder (=BBTK_BBS_REL_PATH)
146     std::string mBbs_rel_path;
147     /// The path to the bbs folder (=mInstall_path+"/"+mBbs_rel_path)
148     std::string mBbs_path;
149     /// The path to the bbtk data folder 
150     /// Initialized to mInstall_path+"/"+BBTK_DATA_REL_PATH
151     /// But can be overriden by value read from bbtk_config.xml
152     std::string mData_path;
153     
154     /// / or \, depending on the OS
155     std::string mFile_separator;
156     
157     /// Read from bbtk_config.xml file
158     /// Where the doc is
159     std::string mUrl;
160     /// Scripts  
161     std::vector<std::string> mBbs_paths; 
162     /// Package dlls    
163     std::vector<std::string> mPackage_paths;
164     /// If Packages link against extern dlls
165     std::vector<std::string> mExt_dll_paths;
166
167
168     /// Set to true by InitializeDotBbtkStructure() if .bbtk has been newly
169     /// created
170     bool mDot_bbtk_is_new;
171    };
172   
173   
174 }// namespace bbtk
175
176
177
178 #endif
179