]> git.donarmstrong.com Git - bamtools.git/blobdiff - src/utils/bamtools_variant.h
Cleaned up intra-API includes & moved version numbers to 2.0.0
[bamtools.git] / src / utils / bamtools_variant.h
index 4927de984d38bbc641b846046db995a3d5a38025..4c477fb253829c827bcab6c3bb4c1c1cfb424aff 100644 (file)
@@ -1,9 +1,8 @@
 // ***************************************************************************
 // bamtools_variant.h (c) 2010 Derek Barnett, Erik Garrison
 // Marth Lab, Department of Biology, Boston College
-// All rights reserved.
 // ---------------------------------------------------------------------------
-// Last modified: 2 June 2010
+// Last modified: 10 October 2011
 // ---------------------------------------------------------------------------
 // Provides a template-based variant type
 // ---------------------------------------------------------------------------
 #ifndef BAMTOOLS_VARIANT_H
 #define BAMTOOLS_VARIANT_H
 
+#include "utils/utils_global.h"
 #include <stdexcept>
-#include <typeinfo>
 #include <string>
+#include <typeinfo>
 
 namespace BamTools {
 
-class Variant {
+class UTILS_EXPORT Variant {
   
     public:
-        Variant(void) : data (NULL) { }
+        Variant(void) : data(NULL) { }
         
         Variant(const Variant& other) { 
-            if(other.data != NULL
+            if ( other.data != NULL 
                 other.data->AddRef();
             data = other.data;
         }
 
         ~Variant(void) { 
-            if(data != NULL) data->Release();
+            if ( data != NULL ) 
+                data->Release();
         }
 
         // NOTE: This code takes care of self-assignment.
         // DO NOT CHANGE THE ORDER of the statements.
-        Variant& operator=(const Variant& rhs) {
-            if(rhs.data != NULL
+        Variant& operator= (const Variant& rhs) {
+            if ( rhs.data != NULL 
                 rhs.data->AddRef();
-            if(data != NULL
+            if ( data != NULL 
                 data->Release();
             data = rhs.data;
-            return * this;
+            return *this;
         }
 
         // This member template constructor allows you to
         // instance a variant_t object with a value of any type.
         template<typename T>
-        Variant(T v)
-            : data(new Impl<T>(v))
+        Variant(T v) 
+            : data(new Impl<T>(v)) 
         { 
             data->AddRef(); 
         }
@@ -88,13 +89,13 @@ class Variant {
     private:
         struct ImplBase {
                 
-            ImplBase() : refs(0) {}
-            virtual ~ImplBase() {}
+            ImplBase() : refs(0) { }
+            virtual ~ImplBase(void) { }
                 
-            void AddRef(void) { refs ++; }
+            void AddRef(void) { ++refs; }
             void Release(void) { 
                 --refs;
-                if(refs == 0) delete this;
+                if ( refs == 0 ) delete this;
             }
                 
             size_t refs;
@@ -102,7 +103,7 @@ class Variant {
 
         template<typename T>
         struct Impl : ImplBase {
-            Impl(T v) : data (v) { }
+            Impl(T v) : data(v) { }
             ~Impl(void) { }
             T data;
         };
@@ -113,9 +114,9 @@ class Variant {
         static Impl<T>* CastFromBase(ImplBase* v) {
             // This upcast will fail if T is other than the T used
             // with the constructor of variant_t.
-            Impl<T>* p = dynamic_cast<Impl<T>*> (v);
-            if (p == NULL
-                throw std::invalid_argument(typeid(T).name()+std::string(" is not a valid type"));
+            Impl<T>* p = dynamic_cast< Impl<T>* > (v);
+            if ( p == NULL 
+                throw std::invalid_argument( typeid(T).name() + std::string(" is not a valid type") );
             return p;
         }