OpenCMISS-Zinc 3.0.0 Release C++ API Documentation
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Pages
stream.hpp
Go to the documentation of this file.
1 
4 /* OpenCMISS-Zinc Library
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 
10 #ifndef CMZN_STREAM_HPP__
11 #define CMZN_STREAM_HPP__
12 
13 #include "zinc/stream.h"
14 
15 namespace OpenCMISS
16 {
17 namespace Zinc
18 {
19 
20 class StreamresourceFile;
21 class StreamresourceMemory;
22 
37 {
38 protected:
39 
40  cmzn_streamresource_id id;
41 
42 public:
43 
44  Streamresource() : id(0)
45  { }
46 
47  // takes ownership of C handle, responsibility for destroying it
48  explicit Streamresource(cmzn_streamresource_id in_streamresource_id) : id(in_streamresource_id)
49  { }
50 
51  Streamresource(const Streamresource& streamResource) : id(cmzn_streamresource_access(streamResource.id))
52  { }
53 
54  Streamresource& operator=(const Streamresource& streamResource)
55  {
56  cmzn_streamresource_id temp_id = cmzn_streamresource_access(streamResource.id);
57  if (0 != id)
58  {
59  cmzn_streamresource_destroy(&id);
60  }
61  id = temp_id;
62  return *this;
63  }
64 
66  {
67  if (0 != id)
68  {
69  cmzn_streamresource_destroy(&id);
70  }
71  }
72 
78  bool isValid() const
79  {
80  return (0 != id);
81  }
82 
88  cmzn_streamresource_id getId() const
89  {
90  return id;
91  }
92 
100  inline StreamresourceFile castFile();
112 
113 };
114 
123 {
124 public:
125 
127  { }
128 
129  // takes ownership of C handle, responsibility for destroying it
130  explicit StreamresourceFile(cmzn_streamresource_file_id streamresource_file_id) :
131  Streamresource(reinterpret_cast<cmzn_streamresource_id>(streamresource_file_id))
132  { }
133 
140  char *getName()
141  {
142  return cmzn_streamresource_file_get_name(
143  reinterpret_cast<cmzn_streamresource_file_id>(id));
144  }
145 
146 };
147 
157 {
158 public:
159 
161  { }
162 
163  // takes ownership of C handle, responsibility for destroying it
164  explicit StreamresourceMemory(cmzn_streamresource_memory_id streamresource_memory_id) :
165  Streamresource(reinterpret_cast<cmzn_streamresource_id>(streamresource_memory_id))
166  { }
167 
168 };
169 
171 {
172  return StreamresourceFile(cmzn_streamresource_cast_file(id));
173 }
174 
176 {
177  return StreamresourceMemory(cmzn_streamresource_cast_memory(id));
178 }
179 
182 
194 {
195 protected:
196 
197  cmzn_streaminformation_id id;
198 
199 public:
200 
201  Streaminformation() : id(0)
202  { }
203 
204  // takes ownership of C handle, responsibility for destroying it
205  explicit Streaminformation(cmzn_streaminformation_id in_streaminformation_id) : id(in_streaminformation_id)
206  { }
207 
208  Streaminformation(const Streaminformation& streamInformation) :
209  id(cmzn_streaminformation_access(streamInformation.id))
210  { }
211 
216  {
217  DATA_COMPRESSION_TYPE_INVALID = CMZN_STREAMINFORMATION_DATA_COMPRESSION_TYPE_INVALID,
219  DATA_COMPRESSION_TYPE_DEFAULT = CMZN_STREAMINFORMATION_DATA_COMPRESSION_TYPE_DEFAULT,
227  DATA_COMPRESSION_TYPE_NONE = CMZN_STREAMINFORMATION_DATA_COMPRESSION_TYPE_NONE,
232  DATA_COMPRESSION_TYPE_GZIP = CMZN_STREAMINFORMATION_DATA_COMPRESSION_TYPE_GZIP,
239  DATA_COMPRESSION_TYPE_BZ2 = CMZN_STREAMINFORMATION_DATA_COMPRESSION_TYPE_BZIP2
246  };
247 
248  Streaminformation& operator=(const Streaminformation& streamInformation)
249  {
250  cmzn_streaminformation_id temp_id = cmzn_streaminformation_access(streamInformation.id);
251  if (0 != id)
252  {
253  cmzn_streaminformation_destroy(&id);
254  }
255  id = temp_id;
256  return *this;
257  }
258 
259  ~Streaminformation()
260  {
261  if (0 != id)
262  {
263  cmzn_streaminformation_destroy(&id);
264  }
265  }
266 
272  bool isValid() const
273  {
274  return (0 != id);
275  }
276 
282  cmzn_streaminformation_id getId() const
283  {
284  return id;
285  }
286 
303  {
304  return StreamresourceFile(reinterpret_cast<cmzn_streamresource_file_id>(
305  cmzn_streaminformation_create_streamresource_file(id, file_name)));
306  }
307 
324  {
325  return StreamresourceMemory(reinterpret_cast<cmzn_streamresource_memory_id>(
326  cmzn_streaminformation_create_streamresource_memory(id)));
327  }
328 
347  unsigned int buffer_length)
348  {
349  return StreamresourceMemory(reinterpret_cast<cmzn_streamresource_memory_id>(
350  cmzn_streaminformation_create_streamresource_memory_buffer(id, buffer, buffer_length)));
351  }
352 
362  {
363  return static_cast<DataCompressionType>(
364  cmzn_streaminformation_get_resource_data_compression_type(
365  reinterpret_cast<cmzn_streaminformation_id>(id), resource.getId()));
366  }
367 
380  int setResourceDataCompressionType(const Streamresource& resource, DataCompressionType dataCompressionType)
381  {
382  return cmzn_streaminformation_set_resource_data_compression_type(
383  reinterpret_cast<cmzn_streaminformation_id>(id), resource.getId(),
384  static_cast<cmzn_streaminformation_data_compression_type>(dataCompressionType));
385  }
386 
394  {
395  return static_cast<DataCompressionType>(
396  cmzn_streaminformation_get_data_compression_type(
397  reinterpret_cast<cmzn_streaminformation_id>(id)));
398  }
399 
410  {
411  return cmzn_streaminformation_set_data_compression_type(
412  reinterpret_cast<cmzn_streaminformation_id>(id),
413  static_cast<cmzn_streaminformation_data_compression_type>(dataCompressionType));
414  }
415 
432 
433 };
434 
435 } // namespace Zinc
436 }
437 
438 
439 #endif /* CMZN_STREAM_HPP__ */
StreamresourceFile castFile()
Definition: stream.hpp:170
A derived streamresource describing a file.
Definition: stream.hpp:122
enum DataCompressionType getResourceDataCompressionType(const Streamresource &resource)
Definition: stream.hpp:361
A description of a resource for reading from or writing to.
Definition: stream.hpp:36
A region-specific stream information object.
Definition: streamregion.hpp:31
int setDataCompressionType(DataCompressionType dataCompressionType)
Definition: stream.hpp:409
StreaminformationImage castImage()
Definition: streamimage.hpp:212
Base type listing resources and options for stream I/O.
Definition: stream.hpp:193
StreaminformationRegion castRegion()
Definition: streamregion.hpp:215
int setResourceDataCompressionType(const Streamresource &resource, DataCompressionType dataCompressionType)
Definition: stream.hpp:380
char * getName()
Definition: stream.hpp:140
DataCompressionType
Definition: stream.hpp:215
A derived stream resource describing a block of memory.
Definition: stream.hpp:156
An image-specific stream information object.
Definition: streamimage.hpp:30
StreamresourceMemory castMemory()
Definition: stream.hpp:175
enum DataCompressionType getDataCompressionType()
Definition: stream.hpp:393
StreamresourceFile createStreamresourceFile(const char *file_name)
Definition: stream.hpp:302
StreamresourceMemory createStreamresourceMemory()
Definition: stream.hpp:323
bool isValid() const
Definition: stream.hpp:272
StreamresourceMemory createStreamresourceMemoryBuffer(const void *buffer, unsigned int buffer_length)
Definition: stream.hpp:346
cmzn_streaminformation_id getId() const
Definition: stream.hpp:282
cmzn_streamresource_id getId() const
Definition: stream.hpp:88
bool isValid() const
Definition: stream.hpp:78