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