Graphite Version 3
An experimental 3D geometry processing program
Loading...
Searching...
No Matches
meta_struct.h
1/*
2 * GXML/Graphite: Geometry and Graphics Programming Library + Utilities
3 * Copyright (C) 2000 Bruno Levy
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 * If you modify this software, you should include a notice giving the
20 * name of the person performing the modification, the date of modification,
21 * and the reason for such modification.
22 *
23 * Contact: Bruno Levy
24 *
25 * levy@loria.fr
26 *
27 * ISA Project
28 * LORIA, INRIA Lorraine,
29 * Campus Scientifique, BP 239
30 * 54506 VANDOEUVRE LES NANCY CEDEX
31 * FRANCE
32 *
33 * Note that the GNU General Public License does not permit incorporating
34 * the Software into proprietary programs.
35 */
36
37#ifndef H_OGF_META_TYPES_META_STRUCT_H
38#define H_OGF_META_TYPES_META_STRUCT_H
39
43
44#include <typeinfo>
45
46namespace OGF {
47
48
52 gom_class GOM_API MetaStruct : public MetaClass {
53 public:
58 MetaStruct(const std::string& struct_name);
59
63 ~MetaStruct() override;
64
71 size_t offset(const MetaProperty* mprop) const;
72
79 index_t field_index(const MetaProperty* mprop) const;
80 };
81
83
84 /********************************************************************/
85
89 gom_class GOM_API MetaBuiltinStruct : public MetaBuiltinType {
90 public:
95 MetaBuiltinStruct(const std::string& struct_name);
96
101
102
103 gom_properties:
104
109 MetaStruct* get_meta_struct() const {
110 return meta_struct_;
111 }
112
113
114 public:
125 template <class T> MetaBuiltinStruct* add_field(
126 const std::string& name, T* offset
127 ) {
128 MetaProperty* mprop =
129 add_property_by_typeid_name(name, typeid(T).name());
131 "offset", String::to_string(size_t(offset))
132 );
133 return this;
134 }
135
147 const std::string& name, const std::string& type_name,
148 size_t offset
149 ) {
150 MetaProperty* mprop = new MetaProperty(
151 name, meta_struct_, type_name
152 );
154 "offset", String::to_string(size_t(offset))
155 );
156 return this;
157 }
158
159 protected:
167 const std::string& property_name,
168 const std::string& typeid_name
169 );
170
171
172 private:
173 MetaStruct* meta_struct_;
174 };
175
176 /********************************************************************/
177
183 gom_class GOM_API StructPropertyRef : public Object {
184 public:
191 StructPropertyRef(Object* object, const std::string& prop_name);
192
197 Object* object() const {
198 return object_;
199 }
200
205 const std::string& property_name() const {
206 return property_name_;
207 }
208
213 const std::string& name, const std::string& value
214 ) override;
215
220 const std::string& name, std::string& value
221 ) const override;
222
226 bool set_property(const std::string& name, const Any& value) override;
227
231 bool get_property(const std::string& name, Any& value) const override;
232
236 std::string to_string() const;
237
238 private:
239 Object* object_;
240 const std::string property_name_;
241 };
242
243 /********************************************************************/
244}
245
246#endif
A smart pointer with reference-counted copy semantics.
A class that stores a variable of arbitrary type.
Definition any.h:62
MetaType for raw C++ structs.
Definition meta_struct.h:89
MetaBuiltinStruct(const std::string &struct_name)
Constructs a new MetaStruct.
MetaProperty * add_property_by_typeid_name(const std::string &property_name, const std::string &typeid_name)
Adds a new property to this MetaBuiltinStruct.
~MetaBuiltinStruct() override
MetaStruct destructor.
MetaBuiltinStruct * add_field(const std::string &name, const std::string &type_name, size_t offset)
Declares a new field of this MetaBuiltinStruct.
MetaBuiltinStruct * add_field(const std::string &name, T *offset)
Declares a new field of this MetaBuiltinStruct.
MetaType for builting types.
The representation of a class in the Meta repository.
Definition meta_class.h:64
void create_custom_attribute(const std::string &name, const std::string &value)
Creates a new custom attribute.
The representation of a property in the Meta repository.
MetaType for GOM struct objects, such as StructPropertyRef.
Definition meta_struct.h:52
index_t field_index(const MetaProperty *mprop) const
Finds the index of a field.
size_t offset(const MetaProperty *mprop) const
Finds the offset of a field.
MetaStruct(const std::string &struct_name)
Constructs a new MetaStruct.
~MetaStruct() override
MetaStruct destructor.
Base class for all objects in the GOM system.
Definition object.h:65
A reference to a property in an object with a struct type.
bool get_property(const std::string &name, Any &value) const override
Gets a property.
bool get_property(const std::string &name, std::string &value) const override
Gets a property.
bool set_property(const std::string &name, const Any &value) override
Sets an individual property.
StructPropertyRef(Object *object, const std::string &prop_name)
StructPropertyRef constructor.
bool set_property(const std::string &name, const std::string &value) override
Sets an individual property.
const std::string & property_name() const
Gets the name of the struct property.
Object * object() const
Gets the object that contains the struct property.
std::string to_string() const
Gets a string representation of this struct.
MetaType for builting types.
MetaType for classes.
geo_index_t index_t
The type for storing and manipulating indices.
Definition numeric.h:330
Global Graphite namespace.
Definition common.h:76
Definitions common to all include files in the gom library.