Salome HOME
Update copyrights 2014.
[tools/simanio.git] / src / SimanIO_Configuration.hxx
1 // Copyright (C) 2013-2014  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, or (at your option) any later version.
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.hxx"
24
25 #include "SimanIO_Activity.hxx"
26
27 #include <fstream>
28 #include <iostream>
29
30 /**
31  * \brief Class for storage and store CFG file information.
32  */
33
34 class SIMANIO_EXPORT SimanIO_Configuration {
35   std::map<int, SimanIO_Activity> myActivities; ///< map of Id of activity t othe activity instance
36   
37   // fileds that are used for file parsing
38   char* myBuffer; // container for one configuration file line
39   std::ifstream* myF; // opened configuration file
40   bool myReuseLine; // if true instead of the next line reading from the file, it must be the current buffer reused
41 public:
42   /**
43    * Creates the configuration with no initial data inside (for filling).
44    */
45   SimanIO_Configuration();
46
47   /**
48    * Fills the configuration, by the input file content (for retrieving).
49    * \param theConfFileName name of the file to be parsed and data retrieved.
50    * \returns true if file was correctly parsed.
51    */
52   bool Parse(const char* theConfFileName);
53
54   /**
55    * Creates ne wactivity section.
56    * \param theActivity activity data
57    * \param theId identifier of the activity (>0), or zero if identifier must be generated
58    * \returns integer identifier of activity
59    */
60   int AddActivity(const SimanIO_Activity& theActivity, const int theId = 0);
61   
62   /**
63    * Creates or returns existing activity with the given Id.
64    * \param theId identifier of the activity
65    * \return reference to activity, already stored in the configuration
66    */
67   SimanIO_Activity& GetOrCreateActivity(const int theId);
68
69   /**
70    * Iterator for actifities.
71    */
72   class SIMANIO_EXPORT ActivitiesIterator {
73     std::map<int, SimanIO_Activity>::iterator myIter; // activities iterator
74     std::map<int, SimanIO_Activity>::iterator myEnd;  // end if activities identifier
75   public:
76     ///! Initializes iterator of the activities of the certain configuration.
77     ActivitiesIterator(SimanIO_Configuration& theConf);
78     ///! Iterates to the next activity of the Configuration.
79     void Next();
80     ///! Returns tru if the current activity exists.
81     bool More();
82     ///! Returns the current activity identifier.
83     const int ActivityId(); 
84     ///! Returns the current activity.
85     SimanIO_Activity& Activity(); 
86   };
87   
88 private:
89   //! Stores in the buffer the next line from the CFG file
90   void ReadLine();
91   //! Parses the activity section
92   bool ParseActivity(char* aName);
93   //! Parses the document section
94   bool ParseDocument(char* aName, SimanIO_Activity& theActivity);
95   //! Parses the file section
96   bool ParseFile(SimanIO_Document& theDocument);
97 };
98
99 #endif