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