vil_memory_chunk.h
Go to the documentation of this file.
1 // This is core/vil/vil_memory_chunk.h
2 #ifndef vil_memory_chunk_h_
3 #define vil_memory_chunk_h_
4 //:
5 // \file
6 // \brief Ref. counted block of data on the heap
7 // \author Tim Cootes
8 
9 #include <cstddef>
10 #include <vcl_atomic_count.h>
11 #ifdef _MSC_VER
12 # include <vcl_msvc_warnings.h>
13 #endif
14 #include <vil/vil_smart_ptr.h>
15 #include <vil/vil_pixel_format.h>
16 
17 //: Ref. counted block of data on the heap.
18 // Image data block used by vil_image_view<T>.
20 {
21  protected:
22  //: Data
23  void *data_;
24 
25  //: Number of elements (bytes)
26  std::size_t size_;
27 
28  //: Indicate what format data is (used for binary IO)
29  // Should always be a scalar type.
31 
32  //: Reference count
33  vcl_atomic_count ref_count_;
34 
35  public:
36  //: Dflt ctor
38 
39  //: Allocate n bytes of memory
40  // \param pixel_format indicates what format to be used for binary IO,
41  // and should always be a scalar type.
43 
44  //: Copy ctor
46 
47  //: Copy operator
49 
50  //: Destructor
51  virtual ~vil_memory_chunk();
52 
53  //: Increment reference count
54  void ref() { ++ref_count_; }
55 
56  //: Decrement reference count
57  void unref();
58 
59  //: Number of objects referring to this data
60  long ref_count() const { return ref_count_; }
61 
62  //: Pointer to first element of data
63  virtual void* data();
64 
65  //: Pointer to first element of data
66  virtual void* const_data() const;
67 
68  //: Indicate what format data is to be saved as in binary IO
70 
71  //: Number of bytes allocated
72  std::size_t size() const { return size_; }
73 
74  //: Create space for n bytes
75  // pixel_format indicates what format to be used for binary IO
76  virtual void set_size(unsigned long n, vil_pixel_format pixel_format);
77 };
78 
80 
81 #endif // vil_memory_chunk_h_
virtual void * data()
Pointer to first element of data.
vil_pixel_format
Describes the type of the concrete data.
std::size_t size() const
Number of bytes allocated.
virtual void * const_data() const
Pointer to first element of data.
long ref_count() const
Number of objects referring to this data.
vil_smart_ptr< vil_memory_chunk > vil_memory_chunk_sptr
virtual void set_size(unsigned long n, vil_pixel_format pixel_format)
Create space for n bytes.
std::size_t size_
Number of elements (bytes).
vil_memory_chunk & operator=(const vil_memory_chunk &)
Copy operator.
void ref()
Increment reference count.
Ref. counted block of data on the heap.
vcl_atomic_count ref_count_
Reference count.
Contains a templated smart pointer class.
vil_pixel_format pixel_format_
Indicate what format data is (used for binary IO).
vil_pixel_format pixel_format() const
Indicate what format data is to be saved as in binary IO.
virtual ~vil_memory_chunk()
Destructor.
void unref()
Decrement reference count.
vil_memory_chunk()
Dflt ctor.