00001 // This is core/vil/vil_memory_chunk.h 00002 #ifndef vil_memory_chunk_h_ 00003 #define vil_memory_chunk_h_ 00004 //: 00005 // \file 00006 // \brief Ref. counted block of data on the heap 00007 // \author Tim Cootes 00008 00009 #include <vcl_atomic_count.h> 00010 #include <vcl_cstddef.h> 00011 #include <vil/vil_smart_ptr.h> 00012 #include <vil/vil_pixel_format.h> 00013 00014 //: Ref. counted block of data on the heap. 00015 // Image data block used by vil_image_view<T>. 00016 class vil_memory_chunk 00017 { 00018 //: Data 00019 void *data_; 00020 00021 //: Number of elements (bytes) 00022 vcl_size_t size_; 00023 00024 //: Indicate what format data is (used for binary IO) 00025 // Should always be a scalar type. 00026 vil_pixel_format pixel_format_; 00027 00028 //: Reference count 00029 vcl_atomic_count ref_count_; 00030 00031 public: 00032 //: Dflt ctor 00033 vil_memory_chunk(); 00034 00035 //: Allocate n bytes of memory 00036 // \param pixel_format indicates what format to be used for binary IO, 00037 // and should always be a scalar type. 00038 vil_memory_chunk(vcl_size_t n, vil_pixel_format pixel_format); 00039 00040 //: Copy ctor 00041 vil_memory_chunk(const vil_memory_chunk&); 00042 00043 //: Copy operator 00044 vil_memory_chunk& operator=(const vil_memory_chunk&); 00045 00046 //: Destructor 00047 virtual ~vil_memory_chunk(); 00048 00049 //: Increment reference count 00050 void ref() { ++ref_count_; } 00051 00052 //: Decrement reference count 00053 void unref(); 00054 00055 //: Number of objects referring to this data 00056 int ref_count() const { return ref_count_; } 00057 00058 //: Pointer to first element of data 00059 void* data() { return data_;} 00060 00061 //: Pointer to first element of data 00062 void* const_data() const { return data_;} 00063 00064 //: Indicate what format data is to be saved as in binary IO 00065 vil_pixel_format pixel_format() const { return pixel_format_; } 00066 00067 //: Number of bytes allocated 00068 vcl_size_t size() const { return size_; } 00069 00070 //: Create space for n bytes 00071 // pixel_format indicates what format to be used for binary IO 00072 void set_size(unsigned long n, vil_pixel_format pixel_format); 00073 }; 00074 00075 typedef vil_smart_ptr<vil_memory_chunk> vil_memory_chunk_sptr; 00076 00077 #endif // vil_memory_chunk_h_
1.5.1