From f58a0b3a1f657124076b96ba092e1f69e88af263 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 18 Jun 2007 20:25:50 +0000 Subject: Added the atom class and did some more client work, it will close the socket now when the end has been reached. --- src/atom.h | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/atom.h (limited to 'src/atom.h') diff --git a/src/atom.h b/src/atom.h new file mode 100644 index 0000000..731e08b --- /dev/null +++ b/src/atom.h @@ -0,0 +1,93 @@ +#ifndef ATOM_H +#define ATOM_H + +#include +#include +#include "bu/exceptions.h" + +namespace Bu +{ + /** + * + */ + template > + class Atom + { + private: + typedef struct Atom MyType; + + public: + Atom() : + pData( NULL ) + { + } + + virtual ~Atom() + { + clear(); + } + + bool isSet() const + { + return (pData != NULL); + } + + void set( const t &val ) + { + clear(); + pData = ta.allocate( 1 ); + ta.construct( pData, val ); + } + + t &get() + { + if( !pData ) + throw Bu::ExceptionBase("Not set"); + return *pData; + } + + const t &get() const + { + if( !pData ) + throw Bu::ExceptionBase("Not set"); + return *pData; + } + + void clear() + { + if( pData ) + { + ta.destroy( pData ); + ta.deallocate( pData, 1 ); + pData = NULL; + } + } + + operator const t &() const + { + if( !pData ) + throw Bu::ExceptionBase("Not set"); + return *pData; + } + + operator t &() + { + if( !pData ) + throw Bu::ExceptionBase("Not set"); + return *pData; + } + + MyType &operator =( const t &oth ) + { + set( oth ); + + return *this; + } + + private: + t *pData; + talloc ta; + }; +} + +#endif -- cgit v1.2.3