/******************************************************************************
** Copyright (c) 1992-2026 MAK Technologies, Inc
** All rights reserved.
******************************************************************************/


//! \file varType.h

#ifndef varType_H_
#define varType_H_

#ifdef DtUSE_UTILITIES_NAMESPACE
namespace DtUSE_UTILITIES_NAMESPACE
{
#endif


// A Internal template typedefs set of 
template <typename T>
struct _NativeTypeToArg
{
   typedef DtString Type;
};

//! A template function for providing the necessary conversion functions for
//! native types to the command line and environment.  Typically use the 
//! Helper macros defined below to special.
template <typename T>
struct DT_DLL_MTL DtVarType
{
   typedef typename _NativeTypeToArg<T>::Type ArgType;

   //Get the native type string.
   static DtString nativeNameOfType();

   //Get the CmdLine ARG type string.
   static DtString argNameOfType();

   //Get the XML schema type string.
   static DtString xsNameOfType();

   //To and from CmdLine Argument types.
   static ArgType convertToArgType(T value);
   static T convertFromArgType(ArgType value);

   //To and From String conversions
   static DtString convertToString(T value);
   static T        convertFromString(const DtString& value);

   //Get Schema Type
   static DtEnvValueSP createSchemaType(DtEnvironment);

   //To and From Environment Value
   static void convertToEnvironmentValue(DtEnvironment env,T value);
   static T convertFromEnvironmentValue(DtEnvironment env);
};

//Macro To Declare a simple Var Type. This macro should be placed in a header.
#define DtDeclareVarType(NativeType,CmdLineType)\
   template <>\
   struct _NativeTypeToArg<NativeType>\
   {\
      typedef CmdLineType Type;\
   };\
   template <>\
   DtString DtVarType<NativeType>::nativeNameOfType();\
   template <>\
   DtString DtVarType<NativeType>::argNameOfType();\
   template <>\
   DtString DtVarType<NativeType>::xsNameOfType();\
   template <>\
   DtVarType<NativeType>::ArgType DtVarType<NativeType>::convertToArgType(NativeType);\
   template <>\
   NativeType DtVarType<NativeType>::convertFromArgType(DtVarType<NativeType>::ArgType);\
   template <>\
   DtString DtVarType<NativeType>::convertToString(NativeType);\
   template <>\
   NativeType DtVarType<NativeType>::convertFromString(const DtString&);\
   template <>\
   DtEnvValueSP DtVarType<NativeType>::createSchemaType(DtEnvironment);\
   template <>\
   void DtVarType<NativeType>::convertToEnvironmentValue(DtEnvironment env,NativeType value);\
   template <>\
   NativeType DtVarType<NativeType>::convertFromEnvironmentValue(DtEnvironment env);\

//Macro To Define the names a simple Var Type. This macro should be placed in a source file.
#define DtDefineVarTypeNames(NativeType,ArgNameStr,xsTypeStr)\
   template<>\
   DtString DtVarType<NativeType>::nativeNameOfType()\
   {\
      return #NativeType;\
   };\
   template<>\
   DtString DtVarType<NativeType>::argNameOfType()\
   {\
      return ArgNameStr;\
   }\
   template<>\
   DtString DtVarType<NativeType>::xsNameOfType()\
   {\
      return xsTypeStr;\
   }\

// Macro to Define the conversion functions of a simple Var Type.This macro should be placed in a source file.
#define DtDefineVarTypeArgFunctions(NativeType,ToStrFunction,FromStrFunction,ToArgFunction,FromArgFunction)\
   template<>\
   DtVarType<NativeType>::ArgType DtVarType<NativeType>::convertToArgType(NativeType value)\
   {\
      return ToArgFunction;\
   }\
   template<>\
   NativeType DtVarType<NativeType>::convertFromArgType(DtVarType<NativeType>::ArgType value)\
   {\
      return FromArgFunction;\
   }\
   template<>\
   DtString DtVarType<NativeType>::convertToString(NativeType value)\
   {\
      return ToStrFunction;\
   }\
   template<>\
   NativeType DtVarType<NativeType>::convertFromString(const DtString& value)\
   {\
      return FromStrFunction;\
   }

// Macro to Define the schema functions. This macro should be placed in a source file.
#define DtDefineVarTypeEnvFunctions(NativeType,SchemaTypeFunction,ToEnvironmentFunction,FromEnvironmentFunction)\
   template <>\
   DtEnvValueSP DtVarType<NativeType>::createSchemaType(DtEnvironment env)\
   {\
      return SchemaTypeFunction;\
   }\
   template <>\
   void DtVarType<NativeType>::convertToEnvironmentValue(DtEnvironment env,NativeType value)\
   {\
      ToEnvironmentFunction;\
   }\
   template <>\
   NativeType DtVarType<NativeType>::convertFromEnvironmentValue(DtEnvironment env)\
   {\
      return FromEnvironmentFunction;\
   }\

#ifdef DtUSE_UTILITIES_NAMESPACE
}
#endif


#endif
