OMToolkit 1.0 The polygonal mesh processing tool.

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
OMFormatExt.hxx
Go to the documentation of this file.
1 //==============================================================================
15 #ifndef OM_FORMAT_EXT_HXX
16 #define OM_FORMAT_EXT_HXX
17
18
19 namespace OpenMesh {
20 namespace IO {
21
23 // Helper to store a an integer
24 // @param _os Output MDSTk channel
25 // @param _val Value to store
26 // @param _b Integer size
27 // @param _swap Swap byte flag
28 // @param t_signed Signed flag
29 // @return Number of saved bytes
31 template< typename T > size_t store( mds::mod::CChannel& _os, const T& _val, OMFormat::Chunk::Integer_Size _b, bool _swap, t_signed)
32 {
33 assert( OMFormat::is_integer( _val ) );
34
35 switch( _b )
36 {
37 case OMFormat::Chunk::Integer_8:
38 {
39 OMFormat::int8 v = static_cast<OMFormat::int8>(_val);
40 return store( _os, v, _swap );
41 }
42 case OMFormat::Chunk::Integer_16:
43 {
44 OMFormat::int16 v = static_cast<OMFormat::int16>(_val);
45 return store( _os, v, _swap );
46 }
47 case OMFormat::Chunk::Integer_32:
48 {
49 OMFormat::int32 v = static_cast<OMFormat::int32>(_val);
50 return store( _os, v, _swap );
51 }
52 case OMFormat::Chunk::Integer_64:
53 {
54 OMFormat::int64 v = static_cast<OMFormat::int64>(_val);
55 return store( _os, v, _swap );
56 }
57 }
58 return 0;
59 }
60
62 // Helper to store a an unsigned integer
63 // @param _os Output MDSTk channel
64 // @param _val Value to store
65 // @param _b Integer size
66 // @param _swap Swap byte flag
67 // @param t_unsigned Unsigned flag
68 // @return Number of saved bytes
70 template< typename T > size_t store( mds::mod::CChannel& _os, const T& _val, OMFormat::Chunk::Integer_Size _b, bool _swap, t_unsigned)
71 {
72 assert( OMFormat::is_integer( _val ) );
73
74 switch( _b )
75 {
76 case OMFormat::Chunk::Integer_8:
77 {
78 OMFormat::uint8 v = static_cast<OMFormat::uint8>(_val);
79 return store( _os, v, _swap );
80 }
81 case OMFormat::Chunk::Integer_16:
82 {
83 OMFormat::uint16 v = static_cast<OMFormat::uint16>(_val);
84 return store( _os, v, _swap );
85 }
86 case OMFormat::Chunk::Integer_32:
87 {
88 OMFormat::uint32 v = static_cast<OMFormat::uint32>(_val);
89 return store( _os, v, _swap );
90 }
91 case OMFormat::Chunk::Integer_64:
92 {
93 OMFormat::uint64 v = static_cast<OMFormat::uint64>(_val);
94 return store( _os, v, _swap );
95 }
96 }
97 return 0;
98 }
99
101 // Helper to restore a an integer
102 // @param _is Input MDSTk channel
103 // @param _val Value to restore
104 // @param _b Integer size
105 // @param _swap Swap byte flag
106 // @param t_signed Signed flag
107 // @return Number of restored bytes
109 template< typename T > size_t restore( mds::mod::CChannel& _is, T& _val, OMFormat::Chunk::Integer_Size _b, bool _swap, t_signed)
110 {
111 assert( OMFormat::is_integer( _val ) );
112 size_t bytes = 0;
113
114 switch( _b )
115 {
116 case OMFormat::Chunk::Integer_8:
117 {
118 OMFormat::int8 v;
119 bytes = restore( _is, v, _swap );
120 _val = static_cast<T>(v);
121 break;
122 }
123 case OMFormat::Chunk::Integer_16:
124 {
125 OMFormat::int16 v;
126 bytes = restore( _is, v, _swap );
127 _val = static_cast<T>(v);
128 }
129 case OMFormat::Chunk::Integer_32:
130 {
131 OMFormat::int32 v;
132 bytes = restore( _is, v, _swap );
133 _val = static_cast<T>(v);
134 }
135 case OMFormat::Chunk::Integer_64:
136 {
137 OMFormat::int64 v;
138 bytes = restore( _is, v, _swap );
139 _val = static_cast<T>(v);
140 }
141 }
142 return bytes;
143 }
144
146 // Helper to restore a an unsigned integer
147 // @param _is Input MDSTk channel
148 // @param _val Value to restore
149 // @param _b Integer size
150 // @param _swap Swap byte flag
151 // @param t_unsigned unsigned flag
152 // @return Number of restored bytes
154 template< typename T > size_t restore( mds::mod::CChannel& _is, T& _val, OMFormat::Chunk::Integer_Size _b, bool _swap, t_unsigned)
155 {
156 assert( OMFormat::is_integer( _val ) );
157 size_t bytes = 0;
158
159 switch( _b )
160 {
161 case OMFormat::Chunk::Integer_8:
162 {
163 OMFormat::uint8 v;
164 bytes = restore( _is, v, _swap );
165 _val = static_cast<T>(v);
166 break;
167 }
168 case OMFormat::Chunk::Integer_16:
169 {
170 OMFormat::uint16 v;
171 bytes = restore( _is, v, _swap );
172 _val = static_cast<T>(v);
173 break;
174 }
175 case OMFormat::Chunk::Integer_32:
176 {
177 OMFormat::uint32 v;
178 bytes = restore( _is, v, _swap );
179 _val = static_cast<T>(v);
180 break;
181 }
182 case OMFormat::Chunk::Integer_64:
183 {
184 OMFormat::uint64 v;
185 bytes = restore( _is, v, _swap );
186 _val = static_cast<T>(v);
187 break;
188 }
189 }
190 return bytes;
191 }
192
193 } // namespace IO
194 } // namespace OpenMesh
195
196 #endif