Sirikata
libcore/include/sirikata/core/util/Nullable.hpp
Go to the documentation of this file.
00001 #ifndef __NULLABLE_HPP__
00002 #define __NULLABLE_HPP__
00003 
00004 #include "Logging.hpp"
00005 
00006 namespace Sirikata
00007 {
00008 
00009 template <typename nullable> class Nullable
00010 {
00011 public:
00012     Nullable(const nullable& nullableObject)
00013      : mNullable(nullableObject),
00014        internalIsNull(false)
00015     {
00016     }
00017 
00018     Nullable()
00019     {
00020         internalIsNull = true;
00021     }
00022 
00023     ~Nullable()
00024     {}
00025 
00030     void makeNull()
00031     {
00032         internalIsNull = false;
00033     }
00034 
00038     bool isNull()
00039     {
00040         return internalIsNull;
00041     }
00042 
00046     nullable getValue()
00047     {
00048         if (isNull())
00049             SILOG(util,error,"In Nullable, calling getValue on a null");
00050                 
00051         return mNullable;
00052     }
00053     
00057     void setValue(const nullable& nullableObject)
00058     {
00059         internalIsNull = false;
00060         mNullable = nullableObject;
00061     }
00062 
00066     void setValue()
00067     {
00068         makeNull();
00069     }
00070     
00071 private:
00072     nullable mNullable;
00073     bool internalIsNull;
00074 
00075 };
00076 
00077 
00078 
00079 
00080 }//end namespace
00081 #endif
00082