![]() |
VR-Link API Documentation for DIS
|
00001 /****************************************************************************** 00002 ** Copyright (c) 1992-2010 VT MAK 00003 ** All rights reserved. 00004 ******************************************************************************/ 00005 00006 00008 00009 #ifndef varType_H_ 00010 #define varType_H_ 00011 00012 #ifdef DtUSE_UTILITIES_NAMESPACE 00013 namespace DtUSE_UTILITIES_NAMESPACE 00014 { 00015 #endif 00016 00017 00018 // A Internal template typedefs set of 00019 template <typename T> 00020 struct _NativeTypeToArg 00021 { 00022 typedef DtString Type; 00023 }; 00024 00028 template <typename T> 00029 struct DT_DLL_MTL DtVarType 00030 { 00031 typedef typename _NativeTypeToArg<T>::Type ArgType; 00032 00033 //Get the native type string. 00034 static DtString nativeNameOfType(); 00035 00036 //Get the CmdLine ARG type string. 00037 static DtString argNameOfType(); 00038 00039 //Get the XML schema type string. 00040 static DtString xsNameOfType(); 00041 00042 //To and from CmdLine Argument types. 00043 static ArgType convertToArgType(T value); 00044 static T convertFromArgType(ArgType value); 00045 00046 //To and From String conversions 00047 static DtString convertToString(T value); 00048 static T convertFromString(const DtString& value); 00049 00050 //Get Schema Type 00051 static DtEnvValueSP createSchemaType(DtEnvironment); 00052 00053 //To and From Environment Value 00054 static void convertToEnvironmentValue(DtEnvironment env,T value); 00055 static T convertFromEnvironmentValue(DtEnvironment env); 00056 }; 00057 00058 //Macro To Declare a simple Var Type. This macro should be placed in a header. 00059 #define DtDeclareVarType(NativeType,CmdLineType)\ 00060 template <>\ 00061 struct _NativeTypeToArg<NativeType>\ 00062 {\ 00063 typedef CmdLineType Type;\ 00064 };\ 00065 template <>\ 00066 DtString DtVarType<NativeType>::nativeNameOfType();\ 00067 template <>\ 00068 DtString DtVarType<NativeType>::argNameOfType();\ 00069 template <>\ 00070 DtString DtVarType<NativeType>::xsNameOfType();\ 00071 template <>\ 00072 DtVarType<NativeType>::ArgType DtVarType<NativeType>::convertToArgType(NativeType);\ 00073 template <>\ 00074 NativeType DtVarType<NativeType>::convertFromArgType(DtVarType<NativeType>::ArgType);\ 00075 template <>\ 00076 DtString DtVarType<NativeType>::convertToString(NativeType);\ 00077 template <>\ 00078 NativeType DtVarType<NativeType>::convertFromString(const DtString&);\ 00079 template <>\ 00080 DtEnvValueSP DtVarType<NativeType>::createSchemaType(DtEnvironment);\ 00081 template <>\ 00082 void DtVarType<NativeType>::convertToEnvironmentValue(DtEnvironment env,NativeType value);\ 00083 template <>\ 00084 NativeType DtVarType<NativeType>::convertFromEnvironmentValue(DtEnvironment env);\ 00085 00086 //Macro To Define the names a simple Var Type. This macro should be placed in a source file. 00087 #define DtDefineVarTypeNames(NativeType,ArgNameStr,xsTypeStr)\ 00088 template<>\ 00089 DtString DtVarType<NativeType>::nativeNameOfType()\ 00090 {\ 00091 return #NativeType;\ 00092 };\ 00093 template<>\ 00094 DtString DtVarType<NativeType>::argNameOfType()\ 00095 {\ 00096 return ArgNameStr;\ 00097 }\ 00098 template<>\ 00099 DtString DtVarType<NativeType>::xsNameOfType()\ 00100 {\ 00101 return xsTypeStr;\ 00102 }\ 00103 00104 // Macro to Define the conversion functions of a simple Var Type.This macro should be placed in a source file. 00105 #define DtDefineVarTypeArgFunctions(NativeType,ToStrFunction,FromStrFunction,ToArgFunction,FromArgFunction)\ 00106 template<>\ 00107 DtVarType<NativeType>::ArgType DtVarType<NativeType>::convertToArgType(NativeType value)\ 00108 {\ 00109 return ToArgFunction;\ 00110 }\ 00111 template<>\ 00112 NativeType DtVarType<NativeType>::convertFromArgType(DtVarType<NativeType>::ArgType value)\ 00113 {\ 00114 return FromArgFunction;\ 00115 }\ 00116 template<>\ 00117 DtString DtVarType<NativeType>::convertToString(NativeType value)\ 00118 {\ 00119 return ToStrFunction;\ 00120 }\ 00121 template<>\ 00122 NativeType DtVarType<NativeType>::convertFromString(const DtString& value)\ 00123 {\ 00124 return FromStrFunction;\ 00125 } 00126 00127 // Macro to Define the schema functions. This macro should be placed in a source file. 00128 #define DtDefineVarTypeEnvFunctions(NativeType,SchemaTypeFunction,ToEnvironmentFunction,FromEnvironmentFunction)\ 00129 template <>\ 00130 DtEnvValueSP DtVarType<NativeType>::createSchemaType(DtEnvironment env)\ 00131 {\ 00132 return SchemaTypeFunction;\ 00133 }\ 00134 template <>\ 00135 void DtVarType<NativeType>::convertToEnvironmentValue(DtEnvironment env,NativeType value)\ 00136 {\ 00137 ToEnvironmentFunction;\ 00138 }\ 00139 template <>\ 00140 NativeType DtVarType<NativeType>::convertFromEnvironmentValue(DtEnvironment env)\ 00141 {\ 00142 return FromEnvironmentFunction;\ 00143 }\ 00144 00145 #ifdef DtUSE_UTILITIES_NAMESPACE 00146 } 00147 #endif 00148 00149 00150 #endif