Salome HOME
Merge from BR_V7_main_Field branch (02/09/2013)
[modules/geom.git] / src / XAO / XAO_Group.hxx
1 // Copyright (C) 2013  CEA/DEN, EDF R&D
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 // Author : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade)
20
21 #ifndef __XAO_GROUP_HXX__
22 #define __XAO_GROUP_HXX__
23
24 #include <string>
25 #include <set>
26
27 #include "XAO_XaoUtils.hxx"
28
29 namespace XAO
30 {
31     /**
32      * \class Group
33      * Class to represent a Geometrical Group.
34      */
35     class Group
36     {
37     public:
38         /**
39          * Constructor.
40          * @param dim the dimension of the group.
41          * @param nbElements the number of geometrical elements for the dimension in the geometry.
42          * @param name the name of the group.
43          */
44         Group(const XAO::Dimension& dim, const int& nbElements, const std::string& name = std::string(""))
45         throw (XAO_Exception);
46
47         /**
48          * Destructor.
49          */
50         virtual ~Group();
51
52         /**
53         * Gets the name of the group.
54         * \return the name of the group.
55         */
56        const std::string getName()
57        {
58            return m_name;
59        }
60         /**
61          * Sets the name of the group.
62          * \param name the name to set.
63          */
64         void setName(const std::string& name)
65         {
66             m_name = name;
67         }
68
69         /**
70          * Gets the dimension of the group.
71          * \return the dimension of the group.
72          */
73         const XAO::Dimension getDimension()
74         {
75             return m_dimension;
76         }
77
78         /**
79          * Gets the numbers of elements in the geometry of the same type than the group.
80          * \return the number of elements in the associated geometry.
81          */
82         const int getNbElements()
83         {
84             return m_nbElements;
85         }
86
87         /**
88          * Gets the number of elements in the group.
89          * \return the number of elements.
90          */
91         const int count() const
92         {
93             return m_elements.size();
94         }
95
96         /**
97          * Gets the reference of an element.
98          * \param index the index of the element.
99          * \return the reference of the element.
100          * \note use begin() and end() if you need to iterate.
101          */
102         const int get(const int& index)
103         {
104             checkIndex(index);
105             std::set<int>::iterator it = m_elements.begin();
106             std::advance(it, index);
107             return (*it);
108         }
109
110         /**
111          * Adds an element to the group.
112          * \param value the index of the element to add.
113          */
114         void add(const int& value);
115
116         /**
117          * Removes an element from the group.
118          * \param value the index of the element to remove.
119          */
120         void remove(const int& value);
121
122         /**
123          * Gets an iterator on the first element in the group.
124          * @return an iterator on the first element.
125          */
126         std::set<int>::iterator begin() { return m_elements.begin(); }
127
128         /**
129          * Gets an iterator on the last element in the group.
130          * @return an iterator on the last element.
131          */
132         std::set<int>::iterator end() { return m_elements.end(); }
133
134     private:
135         /**
136          * Ensures that the given element is valid.
137          * @param element
138          * @throw XAO_Exception if element is bigger than the number of elements.
139          */
140         void checkIndex(const int& element)
141         throw (XAO_Exception);
142
143     private:
144         /** The name of the group. */
145         std::string m_name;
146         /** The number of elements in the associated geometry. */
147         int m_nbElements;
148         /** The dimension of the group. */
149         XAO::Dimension m_dimension;
150         /** The number of elements in the group. */
151         int m_count;
152         /** The elements of the group. */
153         std::set<int> m_elements;
154     };
155 }
156
157 #endif