GUID.h

Go to the documentation of this file.
00001 /****************** <VPR heading BEGIN do not edit this line> *****************
00002  *
00003  * VR Juggler Portable Runtime
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Patrick Hartling, Kevin Meinert, Carolina Cruz-Neira
00007  *
00008  * -----------------------------------------------------------------
00009  * File:          $RCSfile$
00010  * Date modified: $Date: 2006-07-11 08:02:10 -0500 (Tue, 11 Jul 2006) $
00011  * Version:       $Revision: 19006 $
00012  * -----------------------------------------------------------------
00013  *
00014  ****************** <VPR heading END do not edit this line> ******************/
00015 
00016 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00017  *
00018  * VR Juggler is (C) Copyright 1998-2005 by Iowa State University
00019  *
00020  * Original Authors:
00021  *   Allen Bierbaum, Christopher Just,
00022  *   Patrick Hartling, Kevin Meinert,
00023  *   Carolina Cruz-Neira, Albert Baker
00024  *
00025  * This library is free software; you can redistribute it and/or
00026  * modify it under the terms of the GNU Library General Public
00027  * License as published by the Free Software Foundation; either
00028  * version 2 of the License, or (at your option) any later version.
00029  *
00030  * This library is distributed in the hope that it will be useful,
00031  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00032  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00033  * Library General Public License for more details.
00034  *
00035  * You should have received a copy of the GNU Library General Public
00036  * License along with this library; if not, write to the
00037  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00038  * Boston, MA 02111-1307, USA.
00039  *
00040  *************** <auto-copyright.pl END do not edit this line> ***************/
00041 
00042 #ifndef _VPR_GUID_H_
00043 #define _VPR_GUID_H_
00044 
00045 #include <vpr/vprConfig.h>
00046 #include <string>
00047 #include <vpr/vprTypes.h>
00048 #include <vpr/IO/SerializableObject.h>    // For serializing GUID
00049 
00050 
00051 namespace vpr
00052 {
00053 
00054 class GUIDFactory;
00055 
00061 class VPR_CLASS_API GUID : public vpr::SerializableObject
00062 {
00063 public:
00070    class GenerateTag { };
00071    static GenerateTag generateTag;
00072 
00073 public:
00074    GUID(const GenerateTag& tag);
00075 
00076    virtual ~GUID() {;}
00077 
00081    std::string toString() const;
00082 
00083    bool operator==(const GUID& guidObj) const;
00084 
00085    bool operator!= (const GUID& guidObj) const
00086    {
00087       return ! (*this == guidObj);
00088    }
00089 
00090    bool operator<(const GUID& r) const
00091    {
00092       bool ret_val(false);
00093 
00094       if (mGuid.packed.l0 < r.mGuid.packed.l0)
00095       {  ret_val = true; }
00096       else if(mGuid.packed.l0 == r.mGuid.packed.l0)
00097       {
00098          if(mGuid.packed.l1 < r.mGuid.packed.l1)
00099          {  ret_val = true; }
00100          else if(mGuid.packed.l1 == r.mGuid.packed.l1)
00101          {
00102             if(mGuid.packed.l2 < r.mGuid.packed.l2)
00103             {  ret_val = true; }
00104             else if(mGuid.packed.l2 == r.mGuid.packed.l2)
00105             {
00106                if(mGuid.packed.l3 < r.mGuid.packed.l3)
00107                {
00108                   ret_val = true;
00109                }
00110             }
00111          }
00112       }
00113 
00114       return ret_val;
00115    }
00116 
00117    struct StdGUID
00118    {
00119       vpr::Uint32 m0;
00120       vpr::Uint16 m1;
00121       vpr::Uint16 m2;
00122       vpr::Uint8  m3;
00123       vpr::Uint8  m4;
00124       vpr::Uint8  m5[6];
00125    };
00126 
00127 public:
00131    GUID();
00132 
00136    GUID(const struct StdGUID& guid);
00137 
00146    explicit GUID(const std::string& guidString)
00147    {
00148       fromString(guidString);
00149    }
00150 
00155    GUID(const GUID& nsGuid, const std::string& name);
00156 
00158    GUID(const GUID& obj) : vpr::SerializableObject(obj)
00159    {
00160       mGuid.packed.l0 = obj.mGuid.packed.l0;
00161       mGuid.packed.l1 = obj.mGuid.packed.l1;
00162       mGuid.packed.l2 = obj.mGuid.packed.l2;
00163       mGuid.packed.l3 = obj.mGuid.packed.l3;
00164    }
00165 
00166    GUID& operator= (const GUID& obj)
00167    {
00168       if(&obj == this) // Check for self
00169       {
00170          return *this;
00171       }
00172 
00173       mGuid.packed.l0 = obj.mGuid.packed.l0;
00174       mGuid.packed.l1 = obj.mGuid.packed.l1;
00175       mGuid.packed.l2 = obj.mGuid.packed.l2;
00176       mGuid.packed.l3 = obj.mGuid.packed.l3;
00177       return *this;
00178    }
00179 
00180    void generate();
00181    void generate(const GUID& nsGuid, const std::string& name);
00182 
00185    virtual vpr::ReturnStatus writeObject(vpr::ObjectWriter* writer);
00186    virtual vpr::ReturnStatus readObject(vpr::ObjectReader* reader);
00188 
00194    union _vpr_guid
00195    {
00197       struct _moz
00198       {
00199          vpr::Uint32 m0;
00200          vpr::Uint16 m1;
00201          vpr::Uint16 m2;
00202          vpr::Uint8 m3[8];
00203       } moz;
00204 
00206       struct StdGUID standard;
00207 
00214       struct _packed
00215       {
00216          vpr::Uint32 l0;
00217          vpr::Uint32 l1;
00218          vpr::Uint32 l2;
00219          vpr::Uint32 l3;
00220       } packed;
00221    } mGuid;
00222 
00223    friend class vpr::GUIDFactory;
00224 
00225    static const vpr::GUID NullGUID;
00226    
00227 
00232    struct hash
00233    {
00234       enum
00235       {
00236          bucket_size = 4,
00237          min_buckets = 8
00238       };
00239       size_t operator() (const vpr::GUID& guid) const
00240       {
00241          return guid.mGuid.packed.l0 + guid.mGuid.packed.l1 +
00242                 guid.mGuid.packed.l2 + guid.mGuid.packed.l3;
00243       }
00244       bool operator()(const vpr::GUID& guid1, const vpr::GUID& guid2) const
00245       { 
00246          return (guid1 < guid2);
00247       }
00248    };
00249 
00250 private:
00251 
00256    void fromString(const std::string& guid_string);
00257 };
00258 
00259 } // End of vpr namespace
00260 
00261 namespace std
00262 {
00263 
00264 inline std::ostream& operator<<(std::ostream& out, const vpr::GUID& guid)
00265 {
00266    out << guid.toString();
00267    return out;
00268 }
00269 
00270 }
00271 
00272 
00273 #endif /* _VPR_GUID_H_ */

Generated on Thu Jan 4 10:52:09 2007 for VR Juggler Portable Runtime by  doxygen 1.5.1