Salome HOME
a8c662d6c5d9e4281740c6e8481d423fd4f9c4e8
[modules/geom.git] / src / GEOM / GEOM_BaseDriver.hxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File      : GEOM_BaseDriver.hxx
24 // Created   : Thu Jun  6 15:27:50 2013
25 // Author    : Edward AGAPOV (eap)
26
27 #ifndef __GEOM_BaseDriver_HXX__
28 #define __GEOM_BaseDriver_HXX__
29
30 #include <TFunction_Driver.hxx>
31 #include <TopAbs_ShapeEnum.hxx>
32 #include <TopAbs_State.hxx>
33
34 #include <string>
35 #include <vector>
36 #include <sstream>
37
38 class Handle(GEOM_Function);
39 class Handle(TColStd_HSequenceOfTransient);
40 class Handle(TColStd_HArray1OfInteger);
41
42 struct GEOM_Param
43 {
44   std::string name;
45   std::string value;
46
47   Standard_EXPORT void Set(const char* nm) { name = nm; }
48   template <class T>
49   Standard_EXPORT void Set(const char* nm, const T& value) { name = nm; (*this)<<value; }
50
51   template <class T> Standard_EXPORT GEOM_Param & operator<<( const T &anything )
52   {
53     std::ostringstream str;
54     str << anything;
55     value += str.str() ;
56     return *this ;
57   }
58   Standard_EXPORT GEOM_Param & operator<<( const Handle(GEOM_Function)& fun );
59   Standard_EXPORT GEOM_Param & operator<<( const Handle(Standard_Transient)& fun );
60   Standard_EXPORT GEOM_Param & operator<<( const Handle(TColStd_HSequenceOfTransient)& funs );
61   Standard_EXPORT GEOM_Param & operator<<( const Handle(TColStd_HArray1OfInteger)& vals );
62   Standard_EXPORT GEOM_Param & operator<<( TopAbs_ShapeEnum type );
63   Standard_EXPORT GEOM_Param & operator<<( TopAbs_State state );
64 };
65
66
67 class GEOM_BaseDriver : public TFunction_Driver
68 {
69 public:
70   // Returns document id
71   Standard_EXPORT int GetDocID() const;
72   
73   // Returns a name of creation operation and names and values of creation parameters
74   // (Use AddParam() methods declared below to fill params vector while implementing
75   // this method in derived drivers)
76   Standard_EXPORT virtual
77   bool GetCreationInformation(std::string&             theOperationName,
78                               std::vector<GEOM_Param>& params) = 0;
79
80   // Adds GEOM_Param to params and sets its name
81   // This method is safer than resizing the params vector and accessing to its items
82   Standard_EXPORT GEOM_Param& AddParam(std::vector<GEOM_Param>& params,
83                                        const char*              name);
84
85   // Adds GEOM_Param to params vector and sets its name and value
86   // This method is safer than resizing the params vector and accessing to its items
87   template <class T>
88   Standard_EXPORT GEOM_Param& AddParam(std::vector<GEOM_Param>& params,
89                                        const char*              name,
90                                        const T&                 value,
91                                        const char*              dfltValue = 0)
92   {
93     GEOM_Param p;
94     p.Set( name, value );
95     if ( dfltValue && p.value.empty() )
96       p << dfltValue;
97     params.push_back( p );
98     return params.back();
99   }
100
101   DEFINE_STANDARD_RTTI (GEOM_BaseDriver)
102 };
103
104 DEFINE_STANDARD_HANDLE (GEOM_BaseDriver,TFunction_Driver);
105
106 #endif