bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Boxed types for CommonC++


From: Marc Boris Dürner
Subject: Boxed types for CommonC++
Date: Sat, 3 Jan 2004 02:13:42 +0100 (MET)

Hi, 
Thinking about boxed types in CommonC++. Would be useful in many situations.
Look at 
a possible class MemoryChunk. Its a template class that takes a primitive
type (uint8_t 
and higher) as parameter and holds it privately in union with a array of
bytes. This class 
could serve as base class for boxed integers, adresses etc... 
 
Any thoughts? Ideas how to extend this? 
 
 


------------------------------------------------------------------------------- 
 
template <class TYPE> 
class MemoryChunk { 
   public: 
   MemoryChunk() {} 
   ~MemoryChunk() {} 
   const uint8_t& getByte(unsigned int offset) { 
      if(n < getSize()) { 
         return _chunk.bytes[offset]; 
      } 
      else { 
         return 0; //THROW out of range 
      } 
   } 
   private: 
   unsigned int getSize() {return sizeof(TYPE)/sizeof(uint8_t);} 
   union chunk_u { 
      TYPE chunk; 
      uint8_t bytes[getSize()]; 
   } _chunk;   
}; 
 
 
typedef MemoryChunk<uint8_t> Byte; 
typedef MemoryChunk<uint16_t> Word; 
typedef MemoryChunk<uint32_t> DWord; 
typedef MemoryChunk<uint64_t> QWord; 

-- 
+++ GMX - die erste Adresse für Mail, Message, More +++
Neu: Preissenkung für MMS und FreeMMS! http://www.gmx.net






reply via email to

[Prev in Thread] Current Thread [Next in Thread]