]> Creatis software - bbtk.git/blob - kernel/src/bbtkConfigurationFile.h
e6dd488f78df23676b67fb072931693d12d23cfa
[bbtk.git] / kernel / src / bbtkConfigurationFile.h
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkConfigurationFile.h,v $
4   Language:  C++
5   Date:      $Date: 2009/01/27 14:22:56 $
6   Version:   $Revision: 1.11 $
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     void GetHelp(int level) const;
86
87     /// Returns true iff the directory .bbtk has been created on construction
88     inline bool DotBbtkIsNew() { return mDot_bbtk_is_new; }
89
90     inline const std::string& Get_description() const
91     { return mDescription;}
92
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_dot_bbtk_path() const
99     { return mDot_bbtk_path;}
100     inline const std::string& Get_bin_path() const
101     { return mBin_path;}
102     inline const std::string& Get_install_path() const
103     { return mInstall_path;}
104     inline const std::string& Get_doc_path() const
105     { return mDoc_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 mTemp_path;}
117
118     bool AddPackagePathsAndWrite( const std::string& package_root_path );
119     
120   private:
121     ConfigurationFile();
122     void InstallPath ();
123     void Read(const std::string& fileName);
124     void CreateConfigXML( char *rootDirectory );
125     void InitializeDotBbtkStructure();
126     // Attributes :
127   private :
128     std::string mDescription; 
129     /// Where is the file bbtk_config.xml
130     std::string mConfig_xml_full_path;  
131     
132     /// Set automatically :
133     /// The path to the executable (usually bbi)
134     std::string mBin_path;
135     /// The path to the .bbtk user's dir (e.g. /home/username/.bbtk)
136     std::string mDot_bbtk_path;
137     /// The path to the install prefix (=mBinPath+"/..")
138     std::string mInstall_path;
139     /// The path to the doc folder (=mDot_bbtk_path+"/doc")
140     std::string mDoc_path;
141     /// Temp directory for generated data (=mDot_bbtk_path+"/tmp")
142     std::string mTemp_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 path to the bbtk data folder 
148     /// Initialized to mInstall_path+"/"+BBTK_DATA_REL_PATH
149     /// But can be overriden by value read from bbtk_config.xml
150     std::string mData_path;
151     
152     /// / or \, depending on the OS
153     std::string mFile_separator;
154     
155     /// Read from bbtk_config.xml file
156     /// Where the doc is
157     std::string mUrl;
158     /// Scripts  
159     std::vector<std::string> mBbs_paths; 
160     /// Package dlls    
161     std::vector<std::string> mPackage_paths;
162     /// If Packages link against extern dlls
163     std::vector<std::string> mExt_dll_paths;
164
165
166     /// Set to true by InitializeDotBbtkStructure() if .bbtk has been newly
167     /// created
168     bool mDot_bbtk_is_new;
169    };
170   
171   
172 }// namespace bbtk
173
174
175
176 #endif
177