RINGMesh  Version 5.0.0
A programming library for geological model meshes
entity_type.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2017, Association Scientifique pour la Geologie et ses
3  * Applications (ASGA). All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of ASGA nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ASGA BE LIABLE FOR ANY DIRECT,
20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * http://www.ring-team.org
28  *
29  * RING Project
30  * Ecole Nationale Superieure de Geologie - GeoRessources
31  * 2 Rue du Doyen Marcel Roubault - TSA 70605
32  * 54518 VANDOEUVRE-LES-NANCY
33  * FRANCE
34  */
35 
36 #pragma once
37 
38 #include <ringmesh/basic/common.h>
39 
40 #include <vector>
41 
43 
44 namespace RINGMesh
45 {
46  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelMeshEntityAccess );
47  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelGeologicalEntityAccess );
48 } // namespace RINGMesh
49 
50 namespace RINGMesh
51 {
52  /*
53  * @brief Abstract class defining a Geomodel Entity Type
54  * This class encapsulate a string which contains the name of the entity
55  * type
56  * It contains useful operator to compare and display the type
57  * It is possible to do cast of an EntityType -> string
58  */
59  class RINGMESH_API EntityType
60  {
61  public:
62  bool operator==( const EntityType& type2 ) const
63  {
64  return type_ == type2.type_;
65  }
66  bool operator!=( const EntityType& type2 ) const
67  {
68  return type_ != type2.type_;
69  }
70  friend std::ostream& operator<<(
71  std::ostream& os, const EntityType& in )
72  {
73  os << in.type_;
74  return os;
75  }
76  bool operator<( const EntityType& rhs ) const
77  {
78  return type_ < rhs.type_;
79  }
80 
81  const std::string& string() const
82  {
83  return type_;
84  }
85 
86  private:
87  std::string type_{};
88 
89  protected:
90  explicit EntityType( std::string type ) : type_( std::move( type ) )
91  {
92  }
93  EntityType() : EntityType( default_entity_type_string() )
94  {
95  }
96 
97  void set_type( std::string type )
98  {
99  type_ = std::move( type );
100  }
101 
102  private:
104  {
105  return "No_entity_type";
106  }
107  };
108 
117  class RINGMESH_API MeshEntityType : public EntityType
118  {
119  public:
120  explicit MeshEntityType( std::string type )
121  : EntityType( std::move( type ) )
122  {
123  }
124  MeshEntityType() = default;
125  };
126 
137  class RINGMESH_API GeologicalEntityType : public EntityType
138  {
139  public:
140  explicit GeologicalEntityType( std::string type )
141  : EntityType( std::move( type ) )
142  {
143  }
144  GeologicalEntityType() = default;
145  };
146 
151  class RINGMESH_API ForbiddenMeshEntityType : public MeshEntityType
152  {
153  public:
155  {
156  static ForbiddenMeshEntityType entity_type;
157  return entity_type;
158  }
159 
160  private:
161  ForbiddenMeshEntityType() = default;
162  };
163 
168  class RINGMESH_API ForbiddenGeologicalEntityType
169  : public GeologicalEntityType
170  {
171  public:
173  {
174  static ForbiddenGeologicalEntityType entity_type;
175  return entity_type;
176  }
177 
178  private:
179  ForbiddenGeologicalEntityType() = default;
180  };
181 
188  template < class Entity_type_template >
189  struct gme_id
190  {
195 
196  public:
197  index_t index() const
198  {
199  return index_;
200  }
201 
202  Entity_type_template type() const
203  {
204  return type_;
205  }
206 
207  bool operator!=( const gme_id& rhs ) const
208  {
209  return type_ != rhs.type_ || index_ != rhs.index_;
210  }
211 
212  bool operator==( const gme_id& rhs ) const
213  {
214  return type_ == rhs.type_ && index_ == rhs.index_;
215  }
216 
217  friend std::ostream& operator<<( std::ostream& os, const gme_id& in )
218  {
219  os << in.type_ << " " << in.index_;
220  return os;
221  }
222 
223  bool operator<( const gme_id& rhs ) const
224  {
225  if( type_ != rhs.type_ )
226  {
229  return type_ < rhs.type_;
230  }
231  if( index_ == NO_ID )
232  {
233  return true;
234  }
235  if( rhs.index_ == NO_ID )
236  {
237  return false;
238  }
239  return index_ < rhs.index_;
240  }
241 
242  protected:
243  gme_id() = default;
244 
245  gme_id( Entity_type_template entity_type, index_t index )
246  : type_( std::move( entity_type ) ), index_( index )
247  {
248  }
249 
250  protected:
251  Entity_type_template type_;
255  index_t index_{ NO_ID };
256  };
257 
263  {
264  public:
266  {
268  }
269 
270  gmge_id( GeologicalEntityType entity_type, index_t index )
271  : gme_id< GeologicalEntityType >( std::move( entity_type ), index )
272  {
273  }
274 
275  bool is_defined() const
276  {
278  && index_ != NO_ID;
279  }
280  };
286  {
287  public:
289  : gme_id< MeshEntityType >(
290  ForbiddenMeshEntityType::type_name_static(), NO_ID )
291  {
292  }
293 
294  gmme_id( MeshEntityType entity_type, index_t index )
295  : gme_id< MeshEntityType >( std::move( entity_type ), index )
296  {
297  }
298 
299  bool is_defined() const
300  {
302  && index_ != NO_ID;
303  }
304  };
305 } // namespace RINGMesh
bool operator!=(const EntityType &type2) const
Definition: entity_type.h:66
friend std::ostream & operator<<(std::ostream &os, const gme_id &in)
Definition: entity_type.h:217
bool operator<(const EntityType &rhs) const
Definition: entity_type.h:76
The GeologicalEntityType described the type of the Geological entities User can defined there own Geo...
Definition: entity_type.h:137
bool operator!=(const gme_id &rhs) const
Definition: entity_type.h:207
static ForbiddenGeologicalEntityType & type_name_static()
Definition: entity_type.h:172
bool operator==(const EntityType &type2) const
Definition: entity_type.h:62
EntityType(std::string type)
Definition: entity_type.h:90
MeshEntityType(std::string type)
Definition: entity_type.h:120
Entity_type_template type() const
Definition: entity_type.h:202
GeologicalEntityType(std::string type)
Definition: entity_type.h:140
this is the GeologicalEntityType defined by default. It is mainly used to test the validity of a crea...
Definition: entity_type.h:168
this is the MeshEntityType defined by default. It is mainly used to test the validity of a created Me...
Definition: entity_type.h:151
Unique identification of a GeoModelEntity in a GeoModel It contains the EntityType and the index of t...
Definition: entity_type.h:189
bool operator<(const gme_id &rhs) const
Definition: entity_type.h:223
bool is_defined() const
Definition: entity_type.h:275
Entity_type_template type_
Definition: entity_type.h:251
gme_id(Entity_type_template entity_type, index_t index)
Definition: entity_type.h:245
void set_type(std::string type)
Definition: entity_type.h:97
gmge_id(GeologicalEntityType entity_type, index_t index)
Definition: entity_type.h:270
bool operator==(const gme_id &rhs) const
Definition: entity_type.h:212
friend std::ostream & operator<<(std::ostream &os, const EntityType &in)
Definition: entity_type.h:70
The MeshEntityType described the type of the meshed entities There are 4 MeshEntityTypes correspondin...
Definition: entity_type.h:117
This template is a specialization of a gme_id to the GeoModelGeologicalEntity.
Definition: entity_type.h:262
Classes to build GeoModel from various inputs.
Definition: algorithm.h:48
std::string type_
Definition: entity_type.h:87
static ForbiddenMeshEntityType & type_name_static()
Definition: entity_type.h:154
index_t index() const
Definition: entity_type.h:197
gmme_id(MeshEntityType entity_type, index_t index)
Definition: entity_type.h:294
This template is a specialization of a gme_id to the GeoModelMeshEntity.
Definition: entity_type.h:285
const std::string & string() const
Definition: entity_type.h:81
FORWARD_DECLARATION_DIMENSION_CLASS(GeoModelMeshEntityAccess)
bool is_defined() const
Definition: entity_type.h:299
std::string default_entity_type_string()
Definition: entity_type.h:103