Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

vil_memory_chunk.h

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

Generated on Thu Jan 10 14:40:01 2008 for core/vil by  doxygen 1.4.4