PLY reader/writer  1.2.0
 All Classes Namespaces Functions Variables Enumerations Enumerator
unknown.h
1 // A C++ reader/writer of .ply files.
2 // Undescribed data objects.
3 // These contain the actual data.
4 // Generally, the user will implement subclasses
5 // for their own object types.
6 //
7 //Copyright (C) 2013 INRIA - Sophia Antipolis
8 //
9 //This program is free software: you can redistribute it and/or modify
10 //it under the terms of the GNU General Public License as published by
11 //the Free Software Foundation, either version 3 of the License, or
12 //(at your option) any later version.
13 //
14 //This program is distributed in the hope that it will be useful,
15 //but WITHOUT ANY WARRANTY; without even the implied warranty of
16 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 //GNU General Public License for more details.
18 //
19 //You should have received a copy of the GNU General Public License
20 //along with this program. If not, see <http://www.gnu.org/licenses/>.
21 //
22 // Author(s): Thijs van Lankveld
23 
24 
25 #ifndef __PLY_UNKNOWN_H__
26 #define __PLY_UNKNOWN_H__
27 
28 
29 #include "object.h"
30 
31 namespace PLY {
33  struct AnyValue: public Value {
34  char* data;
35 
36  AnyValue(): data(0) {}
37  ~AnyValue() { deinit(); }
38 
39  bool get_scalar(const Property& prop, double& value) const;
40  bool set_scalar(const Property& prop, const double& value);
41  bool get_size(const Property& prop, size_t& size) const;
42  bool get_item(const Property& prop, const size_t& num, double& value) const;
43  bool set_size(const Property& prop, const size_t& size);
44  bool set_item(const Property& prop, const size_t& num, const double& value);
45  bool get_string(const Property& prop, char* str) const;
46  bool set_string(const Property& prop, const char* str);
47 
48  private:
49  AnyValue(const AnyValue&) {}
50 
52  void deinit() { if (data) { delete[] data; data = 0; } }
53 
55 
60  bool to_value(const char* ptr, const Scalar_type& type, double& value) const;
61 
63 
70  bool to_pointer(const double& value, const Scalar_type& type, char* ptr) const;
71 
73  void copy(const char* from, char* to, const size_t& num) const;
74  }; // struct AnyValue
75 
76 
78  struct AnyObject: public Object {
80 
82  AnyObject(): values(0) {}
83  ~AnyObject() { deinit(); }
84 
85  void prepare(const Element& elem);
86  Value* get_value(const Element& elem, const Property& prop);
87 
88  private:
89  AnyObject(const AnyObject&) {} // Private copy constructor to protect the values.
90 
91  void init(size_t size); // Initialize the objects.
92  void deinit(); // Deinitialize the objects.
93 
94  size_t num; // The number of values.
95  }; // struct AnyObject
96 
97 
99  struct AnyArray: public Array {
101  size_t incr;
102 
104  AnyArray(): objects(0), incr(0), num(0) {}
105  virtual ~AnyArray() { deinit(); }
106 
107  virtual size_t size() { return num; }
108  virtual void prepare(const size_t& size);
109  virtual void clear();
110  virtual void restart() { incr = 0; }
111  virtual Object& next_object();
112 
113  private:
114  AnyArray(const AnyArray&) {} // Private copy constructor to protect the objects.
115 
116  void init(size_t size); // Initialize the objects.
117  void deinit(); // Deinitialize the objects.
118 
119  size_t num; // The number of objects.
120  }; // struct AnyArray
121 } // namespace PLY
122 
123 #endif // __PLY_UNKNOWN_H__