Main Page   Reference Manual   Namespace List   Compound List   Namespace Members   Compound Members   File Members  

/usr/src/libcwd/libcwd/include/libcwd/class_alloc.h

Go to the documentation of this file.
00001 // $Header: /cvsroot/libcwd/libcwd/include/libcwd/class_alloc.h,v 1.4 2004/06/03 12:23:07 libcw Exp $
00002 //
00003 // Copyright (C) 2000 - 2004, by
00004 // 
00005 // Carlo Wood, Run on IRC <carlo@alinoe.com>
00006 // RSA-1024 0x624ACAD5 1997-01-26                    Sign & Encrypt
00007 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6  F6 F6 55 DD 1C DC FF 61
00008 //
00009 // This file may be distributed under the terms of the Q Public License
00010 // version 1.0 as appearing in the file LICENSE.QPL included in the
00011 // packaging of this file.
00012 //
00013 
00018 #ifndef LIBCWD_CLASS_ALLOC_H
00019 #define LIBCWD_CLASS_ALLOC_H
00020 
00021 #ifndef LIBCWD_CONFIG_H
00022 #include <libcwd/config.h>
00023 #endif
00024 
00025 #ifndef LIBCWD_ENUM_MEMBLK_TYPES_H
00026 #include <libcwd/enum_memblk_types.h>           // Needed for memblk_types_nt.
00027 #endif
00028 #ifndef LIBCW_LOCKABLE_AUTO_PTR_H
00029 #include <libcwd/lockable_auto_ptr.h>           // Needed for lockable_auto_ptr<char, true>.
00030 #endif
00031 #if CWDEBUG_LOCATION && !defined(LIBCWD_CLASS_LOCATION_H)
00032 #include <libcwd/class_location.h>              // Needed for location_ct.
00033 #endif
00034 #ifndef LIBCW_CSTDDEF
00035 #define LIBCW_CSTDDEF
00036 #include <cstddef>                              // Needed for size_t.
00037 #endif
00038 #ifndef LIBCWD_SMART_PTR_H
00039 #include <libcwd/smart_ptr.h>
00040 #endif
00041 #ifndef LIBCW_SYS_TIME_H
00042 #define LIBCW_SYS_TIME_H
00043 #include <sys/time.h>                           // Needed for struct timeval.
00044 #endif
00045 
00046 namespace libcwd {
00047 
00048 // Forward declaration
00049 class type_info_ct;
00050 
00051 //===================================================================================================
00052 //
00053 // The class which describes allocated memory blocks.
00054 //
00055 
00060 class alloc_ct {
00061 protected:
00062   void const* a_start;                          
00063   size_t a_size;                                
00064   memblk_types_nt a_memblk_type;                
00065   type_info_ct const* type_info_ptr;            
00066   _private_::smart_ptr a_description;           
00067   struct timeval a_time;                        
00068 #if CWDEBUG_LOCATION
00069   location_ct const* M_location;                
00070 #endif
00071 
00072 public:
00076   size_t size(void) const { return a_size; }
00077 
00081   void const* start(void) const { return a_start; }
00082 
00086   memblk_types_nt memblk_type(void) const { return a_memblk_type; }
00087 
00095   type_info_ct const& type_info(void) const { return *type_info_ptr; }
00096 
00102   char const* description(void) const { return a_description; }
00103 
00109   struct timeval const& time(void) const { return a_time; }
00110 
00111 #if CWDEBUG_LOCATION
00112 
00119   location_ct const& location(void) const { return *M_location; }
00120 #endif
00121 
00122 protected:
00127   alloc_ct(void const* s, size_t sz, memblk_types_nt type, type_info_ct const& ti, struct timeval const& t
00128 #if CWDEBUG_LOCATION
00129       , location_ct const* l
00130 #endif
00131       ) : a_start(s), a_size(sz), a_memblk_type(type), type_info_ptr(&ti), a_time(t)
00132 #if CWDEBUG_LOCATION
00133       , M_location(l)
00134 #endif
00135       , M_tagged(false)
00136       { }
00137 
00145   virtual ~alloc_ct() { }
00146 
00147   // For internal use:
00148 private:
00149   bool M_tagged;                                // Set when AllocTag et al was called.
00150 public:
00151   bool is_tagged(void) const { return M_tagged; }
00152   void alloctag_called(void) { M_tagged = true; }
00153 };
00154 
00155 } // namespace libcwd
00156 
00157 #endif // LIBCWD_CLASS_ALLOC_H
Copyright © 2001 - 2004 Carlo Wood.  All rights reserved.