VR-Forces 4.0.4 Class Documentation
include/vrvCore/DtUniqueElementAttribute.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002 ** Copyright (c) 2009 MAK Technologies, Inc.
00003 ** All rights reserved.
00004 *******************************************************************************/
00005 /*******************************************************************************
00006 ** $RCSfile: DtUniqueElementAttribute.h,v $ $Revision: 1.2 $ $State: Exp $
00007 *******************************************************************************/
00008 
00012 
00013 #pragma once
00014 
00015 #include <vrvCore/vrvCore.h>
00016 #include <vrvCore/DtElementEntry.h>
00017 
00018 #include <string>
00019 
00020 namespace makVrv
00021 {
00022    template <typename Type>
00023    struct TypeIds;
00024 
00025    //Macro simply define once before the element attribute.
00026 #define AddTypeId(typeStr, number)\
00027    template <> struct TypeIds<typeStr> { enum { id = number }; }
00028 
00029    typedef std::pair<int, int> pairInts;
00030 
00031    //Add default built in types
00032    AddTypeId(unsigned char,     1);
00033    AddTypeId(unsigned short,    2);
00034    AddTypeId(unsigned int,      3);
00035    AddTypeId(unsigned long int, 4);
00036    AddTypeId(char,     5);
00037    AddTypeId(short,    6);
00038    AddTypeId(int,      7);
00039    AddTypeId(long int, 8);
00040    AddTypeId(float,  9);
00041    AddTypeId(double, 10);
00042    AddTypeId(bool,        11);
00043    AddTypeId(std::string, 12);
00044    AddTypeId(pairInts, 13);
00045 
00046    template <typename T>
00047    class DtTypedElementAttribute : public DtElementAttribute
00048    {
00049    public:
00050       DtTypedElementAttribute(unsigned short attrId, const T& value)
00051       : DtElementAttribute(attrId, TypeIds<T>::id)
00052       , myValue(value)
00053       {
00054       }
00055 
00056       virtual ~DtTypedElementAttribute()
00057       {
00058       }
00059 
00061       virtual DtElementAttribute* clone() const
00062       {
00063          return new DtTypedElementAttribute(attributeId(),value());
00064       }
00065 
00066       inline const T& value() const
00067       {
00068          return myValue;
00069       }
00070 
00071    private:   
00072       T myValue;   
00073    };
00074 
00075    template <typename T, unsigned short AttributeId>
00076    class DtUniqueElementAttribute : public DtTypedElementAttribute<T>
00077    {
00078    public:
00079       DtUniqueElementAttribute(const T& value)
00080       : DtTypedElementAttribute<T>(AttributeId, value)         
00081       {
00082       }
00083 
00084       virtual ~DtUniqueElementAttribute()
00085       {
00086 
00087       }
00088 
00090       virtual DtElementAttribute* clone() const
00091       {
00092          return new DtUniqueElementAttribute<T,AttributeId>(this->value());
00093       }
00094 
00096       static const DtUniqueElementAttribute<T,AttributeId>* findInEntry(const DtElementEntry& entry)
00097       {
00098          return dynamic_cast<const DtUniqueElementAttribute<T,AttributeId>*>(entry.findAttribute(AttributeId));
00099       }
00100    };
00101 }
00102 
00103 #define DtUniqueElementAttribute_INL_
00104 #include <vrvCore/DtUniqueElementAttribute.inl>
00105 #undef DtUniqueElementAttribute_INL_
00106 
00107 

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)