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