OpenVolumeMeshBaseProperty.hh 5.63 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*===========================================================================*\
 *                                                                           *
 *                            OpenVolumeMesh                                 *
 *        Copyright (C) 2011 by Computer Graphics Group, RWTH Aachen         *
 *                        www.openvolumemesh.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenVolumeMesh.                                     *
 *                                                                           *
 *  OpenVolumeMesh is free software: you can redistribute it and/or modify   *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenVolumeMesh is distributed in the hope that it will be useful,        *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenVolumeMesh.  If not,                              *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

#ifndef OPENVOLUMEMESHBASEPROPERTY_HH
#define OPENVOLUMEMESHBASEPROPERTY_HH

38
#include <iosfwd>
39
#include <string>
40
#include <vector>
41

42
43
#include "OpenVolumeMeshHandle.hh"

44
namespace OpenVolumeMesh {
45
46
47
48
49
50
51
52
53
54

/** \class OpenVolumeMeshBaseProperty

 Abstract class defining the basic interface of a dynamic property.

 **/

class OpenVolumeMeshBaseProperty {
public:

55
56
57
    friend class ResourceManager;
    template <class PropT, class HandleT> friend class PropertyPtr;

58
59
60
61
62
	/// Indicates an error when a size is returned by a member.
	static const size_t UnknownSize;

public:

63
64
65
66
67
68
69
70
	explicit OpenVolumeMeshBaseProperty(
            const std::string& _name = "<unknown>",
            const std::string& _internal_type_name = "<unknown>")
        : name_(_name),
          internal_type_name_(_internal_type_name),
          persistent_(false),
          handle_(-1)
    {}
71

72
	OpenVolumeMeshBaseProperty(const OpenVolumeMeshBaseProperty& _rhs) = default;
73
74
75
76
77
78
79
80
81
82
83

	virtual ~OpenVolumeMeshBaseProperty() {}

public:

	/// Reserve memory for n elements.
	virtual void reserve(size_t _n) = 0;

	/// Resize storage to hold n elements.
	virtual void resize(size_t _n) = 0;

84
85
86
	/// Return underlying container size
	virtual size_t size() const = 0;

87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
	/// Clear all elements and free memory.
	virtual void clear() = 0;

	/// Extend the number of elements by one.
	virtual void push_back() = 0;

	/// Let two elements swap their storage place.
	virtual void swap(size_t _i0, size_t _i1) = 0;

	/// Erase an element of the vector
	virtual void delete_element(size_t _idx) = 0;

	/// Return a deep copy of self.
	virtual OpenVolumeMeshBaseProperty* clone() const = 0;

	/// Return the name of the property
	const std::string& name() const {
		return name_;
	}

107
108
109
110
	const std::string& internal_type_name() const {
		return internal_type_name_;
	}

111
	// Function to serialize a property
112
	virtual void serialize(std::ostream& /*_ostr*/) const {}
113

Mike Kremer's avatar
Mike Kremer committed
114
	// Function to deserialize a property
115
    virtual void deserialize(std::istream& /*_istr*/) {}
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
	// I/O support

	void set_persistent(bool _persistent) { persistent_ = _persistent; }

	bool persistent() const { return persistent_; }

	/// Number of elements in property
	virtual size_t n_elements() const = 0;

	/// Size of one element in bytes or UnknownSize if not known.
	virtual size_t element_size() const = 0;

	/// Return size of property in bytes
	virtual size_t size_of() const {
		return size_of(n_elements());
	}

	/// Estimated size of property if it has _n_elem elements.
	/// The member returns UnknownSize if the size cannot be estimated.
	virtual size_t size_of(size_t _n_elem) const {
		return (element_size() != UnknownSize) ? (_n_elem * element_size())
				: UnknownSize;
	}

140
141
142
143
	const OpenVolumeMeshHandle& handle() const { return handle_; }

	void set_handle(const OpenVolumeMeshHandle& _handle) { handle_.idx(_handle.idx()); }

144
145
146
147
148
protected:

	/// Delete multiple entries in list
    virtual void delete_multiple_entries(const std::vector<bool>&) = 0;

149
150
151
private:

	std::string name_;
152
	std::string internal_type_name_;
153
154

	bool persistent_;
155
156

	OpenVolumeMeshHandle handle_;
157
158
159
160
161
162
};

} // Namespace OpenVolumeMesh

#endif //OPENVOLUMEMESHBASEPROPERTY_HH