Salome HOME
Improve build procedure
[tools/simanio.git] / src / SimanIO_Configuration.hxx
1 // Copyright (C) 2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef SIMANIO_CONFIGURATION_H
21 #define SIMANIO_CONFIGURATION_H
22
23 #include "SimanIO_Activity.hxx"
24
25 #include <fstream>
26 #include <iostream>
27
28 /**
29  * \brief Class for storage and store CFG file information.
30  */
31
32 class SimanIO_Configuration {
33   std::map<int, SimanIO_Activity> myActivities; ///< map of Id of activity t othe activity instance
34   
35   // fileds that are used for file parsing
36   char* myBuffer; // container for one configuration file line
37   std::ifstream* myF; // opened configuration file
38   bool myReuseLine; // if true instead of the next line reading from the file, it must be the current buffer reused
39 public:
40   /**
41    * Creates the configuration with no initial data inside (for filling).
42    */
43   SimanIO_Configuration();
44
45   /**
46    * Fills the configuration, by the input file content (for retrieving).
47    * \param theConfFileName name of the file to be parsed and data retrieved.
48    * \returns true if file was correctly parsed.
49    */
50   bool Parse(const char* theConfFileName);
51
52   /**
53    * Creates ne wactivity section.
54    * \param theActivity activity data
55    * \param theId identifier of the activity (>0), or zero if identifier must be generated
56    * \returns integer identifier of activity
57    */
58   int AddActivity(const SimanIO_Activity& theActivity, const int theId = 0);
59   
60   /**
61    * Creates or returns existing activity with the given Id.
62    * \param theId identifier of the activity
63    * \return reference to activity, already stored in the configuration
64    */
65   SimanIO_Activity& GetOrCreateActivity(const int theId);
66
67   /**
68    * Iterator for actifities.
69    */
70   class ActivitiesIterator {
71     std::map<int, SimanIO_Activity>::iterator myIter; // activities iterator
72     std::map<int, SimanIO_Activity>::iterator myEnd;  // end if activities identifier
73   public:
74     ///! Initializes iterator of the activities of the certain configuration.
75     ActivitiesIterator(SimanIO_Configuration& theConf);
76     ///! Iterates to the next activity of the Configuration.
77     void Next();
78     ///! Returns tru if the current activity exists.
79     bool More();
80     ///! Returns the current activity identifier.
81     const int ActivityId(); 
82     ///! Returns the current activity.
83     SimanIO_Activity& Activity(); 
84   };
85   
86 private:
87   //! Stores in the buffer the next line from the CFG file
88   void ReadLine();
89   //! Parses the activity section
90   bool ParseActivity(char* aName);
91   //! Parses the document section
92   bool ParseDocument(char* aName, SimanIO_Activity& theActivity);
93   //! Parses the file section
94   bool ParseFile(SimanIO_Document& theDocument);
95 };
96
97 #endif