Salome HOME
1d0d8df1169b3459ba35aa3393c7e87c2b6236da
[tools/simanio.git] / src / SimanIO_Document.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_DOCUMENT_H
21 #define SIMANIO_DOCUMENT_H
22
23 #include <string>
24 #include <list>
25
26 ///! Kinds of automatic actions, accessible for SIMAN file
27 enum AutomaticProcessing {
28   FILE_DOWNLOAD,
29   FILE_IMPORT
30 };
31
32 ///! Possible states of the SIMAN file
33 enum FileState {
34   FILE_ACTUAL,
35   FILE_OUTDATED
36 };
37 ///! Action document data
38 struct SimanIO_File {
39   std::string url;          ///< document url in SIMAN
40   bool result;              ///< if true, document is result, the source otherwise
41   AutomaticProcessing proc; ///< processing kind
42   FileState state;          ///< state of the document
43   int id;                   ///< identifier of the file
44 };
45
46 /**
47  * \brief Class for storage and store CFG file document information.
48  */
49 class SimanIO_Document {
50   std::string myName;   ///< name of the document
51   typedef std::list<SimanIO_File> DocumentFiles;
52   DocumentFiles myFiles; ///< files of the document
53 public:
54   /**
55    * Creates the empty, default document.
56    */
57   SimanIO_Document();
58   
59   /**
60    * Defines the document name.
61    * \param theName name of the document
62    */
63   void SetName(const char* theName);
64   
65   /**
66    * Returns the name of the document.
67    */
68   const char* Name() const;
69
70   /**
71    * Appends the file to this document.
72    * \param isResult if it is true, the document is resulting document, if false - the input document for the activity
73    * \param theURL path to the file
74    * \param theProc automatic processing kind
75    * \param theState file state
76    */
77   void AddFile(const bool isResult, const char* theURL,
78                    const AutomaticProcessing theProc, const FileState theState);
79
80   /**
81    * Appends the file to this document.
82    * \param theFile file with all fields filled
83    */
84   void AddFile(const SimanIO_File& theFile);
85   
86   /**
87    * Returns stored file or empty file.
88    * \param theId identifier of the file
89    * \returns reference to the file, located in the document
90    */
91   const SimanIO_File& File(const int theId) const;
92
93   //! Iterator for activity documents browsing
94   class FilesIterator {
95     DocumentFiles::iterator myIter; ///< iterator by the file of the document
96     DocumentFiles::const_iterator myEnd;  ///< end iteration indicator
97     public:
98     ///! Launches the iterator
99     FilesIterator(/*const*/ SimanIO_Document& theDocument);
100     ///! Iterates to the next file of the document.
101     void Next();
102     ///! Returns tru if the current file exists.
103     bool More();
104     ///! Returns true if the current file is resulting document.
105     const bool IsResult();
106     ///! Returns the current file URL.
107     const char* URL();
108     ///! Set the new URL of the file.
109     void SetURL(const char* theURL);
110     ///! Returns the processing kind
111     const AutomaticProcessing GetProcessing();
112     ///! Returns the file state
113     const FileState GetState();
114     ///! Returns the file Id
115     const int Id();
116   };
117 };
118
119 #endif