Salome HOME
Check-in operation without any modifications is possible
[tools/simanio.git] / src / SimanIO_Configuration.hxx
1 #ifndef SIMANIO_CONFIGURATION_H
2 #define SIMANIO_CONFIGURATION_H
3
4 #include <SimanIO_Activity.hxx>
5 #include <fstream>
6 #include <iostream>
7
8 /**
9  * \brief Class for storage and store CFG file information.
10  */
11
12 class SimanIO_Configuration {
13   std::map<int, SimanIO_Activity> myActivities; ///< map of Id of activity t othe activity instance
14   
15   // fileds that are used for file parsing
16   char* myBuffer; // container for one configuration file line
17   std::ifstream* myF; // opened configuration file
18   bool myReuseLine; // if true instead of the next line reading from the file, it must be the current buffer reused
19 public:
20   /**
21    * Creates the configuration with no initial data inside (for filling).
22    */
23   SimanIO_Configuration();
24
25   /**
26    * Fills the configuration, by the input file content (for retrieving).
27    * \param theConfFileName name of the file to be parsed and data retrieved.
28    * \returns true if file was correctly parsed.
29    */
30   bool Parse(const char* theConfFileName);
31
32   /**
33    * Creates ne wactivity section.
34    * \param theActivity activity data
35    * \param theId identifier of the activity (>0), or zero if identifier must be generated
36    * \returns integer identifier of activity
37    */
38   int AddActivity(const SimanIO_Activity& theActivity, const int theId = 0);
39   
40   /**
41    * Creates or returns existing activity with the given Id.
42    * \param theId identifier of the activity
43    * \return reference to activity, already stored in the configuration
44    */
45   SimanIO_Activity& GetOrCreateActivity(const int theId);
46
47   /**
48    * Iterator for actifities.
49    */
50   class ActivitiesIterator {
51     std::map<int, SimanIO_Activity>::iterator myIter; // activities iterator
52     std::map<int, SimanIO_Activity>::iterator myEnd;  // end if activities identifier
53   public:
54     ///! Initializes iterator of the activities of the certain configuration.
55     ActivitiesIterator(SimanIO_Configuration& theConf);
56     ///! Iterates to the next activity of the Configuration.
57     void Next();
58     ///! Returns tru if the current activity exists.
59     bool More();
60     ///! Returns the current activity identifier.
61     const int ActivityId(); 
62     ///! Returns the current activity.
63     SimanIO_Activity& Activity(); 
64   };
65   
66 private:
67   //! Stores in the buffer the next line from the CFG file
68   void ReadLine();
69   //! Parses the activity section
70   bool ParseActivity(char* aName);
71   //! Parses the document section
72   bool ParseDocument(char* aName, SimanIO_Activity& theActivity);
73   //! Parses the file section
74   bool ParseFile(SimanIO_Document& theDocument);
75 };
76
77 #endif