[Top][All Lists]
[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: |
Tue, 6 Jan 2004 03:15:43 +0100 (MET) |
> It sounds interesting. I suppose this relates the boxed types
>and MemoryChunk template you comment on another post?
Yes, but not neccessarily. For the boxed types we also would need to
implement float,
char etc...
It just seemed a good analogy to low level C-programming where you use
uint8_t for a
byte and the larger int types for short series of bytes. The union is a fast
way of extracting
bytes.
union chunk_u {
TYPE chunk;
uint8_t bytes[sizeof(TYPE)/sizeof(uint8_t)];
} _chunk;
The union doesnt make much sense though if TYPE is a float. So would it work
to have a
template class BoxedType that boxes everything and then use derivatives of
BoxedType
for MemoryChunk? So BoxedType would be identical to MemoryChunk, just
without the
union.
BoxedType <- UInt8
<- UInt16
<- UInt32
<- UInt64
typedef MemoryChunk<UInt8> Byte;
typedef MemoryChunk<UInt16> Word;
etc...
Marc
On Mon, Dec 29, 2003 at 03:20:19AM +0100, "Marc Boris Dürner" wrote:
> Hi,
> For the implementation of classes for numeric IP addresses I am trying to
> treat an IP
> address as a series of bytes. I have a base class NetAddress that has a
> vector<uint8_t>
> as a member and is so usable for inet4, inet6, ipx etc... (and maybe mac
> address as well)
> The derived class Inet4Address for instance has a validator that can
> validate a string as
> input and put 4 bytes into the vector. It provides compatibility
> getter/setter to in_addr.
>
> Is this a good idea?
>
> regards,
> Marc
--
+++ GMX - die erste Adresse für Mail, Message, More +++
Neu: Preissenkung für MMS und FreeMMS! http://www.gmx.net