- toolpublic.zip
- ToolPublic
- GUI.Tools
- License.txt
- SampleScripts
- Sample.Report
- Tools
- XML.Forms
- GiftCardPurchase.form
- LicenseEntry.form
- PayByCreditCard.form
- Send.Alerts.To.form
- ServerDriveLogon.form
- ServerInfo.form
- StdAfx.h
- ToolDll
- ToolDllTester
- ToolExDllCore
- ToolExtender
- ToolTester
- Utilities
- samples.zip
- Samples
- RunTool.exe
- RunToolDll.exe
- ToolExtender.dll
- ToolPub.DLL
- ToolPub.lib
- xmlformtest.exe
- toolforge.zip
- ToolForge.exe
|
/*****************************************************************************/
/* SOURCE FILE */
/*****************************************************************************/
/*
$Archive: $
$Revision: $
Last Checkin:
$Date: $
By:
$Author: $
Last Modification:
$ModTime: $
Description: A variant data class for containing data scraped from
entry fields on an XML form
TOOL And XML FORMS License
==========================
Except where otherwise noted, all of the documentation
and software included in the TOOL package is
copyrighted by Michael Swartzendruber.
Copyright (C) 2005 Michael John Swartzendruber.
All rights reserved.
Access to this code, whether intentional or accidental,
does NOT IMPLY any transfer of rights.
This software is provided "as-is," without any express
or implied warranty. In no event shall the author be held
liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for
any purpose, including commercial applications, and to
alter and redistribute it, provided that the following
conditions are met:
1. All redistributions of source code files must retain
all copyright notices that are currently in place,
and this list of conditions without modification.
2. The origin of this software must not be misrepresented;
you must not claim that you wrote the original software.
3. If you use this software in another product, an acknowledgment
in the product documentation would be appreciated but is
not required.
4. Modified versions in source or binary form must be plainly
marked as such, and must not be misrepresented as being
the original software.
*/
static char OBJECT_ID[] = "$Revision: 1 $ : $JustDate: 1/25/02 $";
/*****************************************************************************/
#include "stdafx.h"
#include "XMLVariantData.h"
#pragma warning( disable : 4786 )
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
/*****************************************************************************/
/*
FUNCTION NAME: XMLFormVariantData::XMLFormVariantData
DESCRIPTION: ctor for assigning this as a string
INPUT: oValue - string containing the value for this
OUTPUT: none
RETURNS: none
*/
XMLFormVariantData::XMLFormVariantData( const char* pchValue )
{
m_eValueType = eIsAString;
if ( pchValue && *pchValue )
{
m_oValue.assign( pchValue );
}
else
{
m_oValue.assign( "" );
}
}
XMLFormVariantData::XMLFormVariantData( std::string oValue )
{
m_eValueType = eIsAString;
m_oValue = oValue;
}
XMLFormVariantData::XMLFormVariantData( const char chValue )
{
char achTemp[ 2 ];
achTemp[ 0 ] = chValue;
achTemp[ 1 ] = 0;
m_eValueType = eIsAString;
m_oValue.assign( achTemp );
}
/* End of function "XMLFormVariantData::XMLFormVariantData"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: XMLFormVariantData::XMLFormVariantData
DESCRIPTION: ctor for assigning this as an double
INPUT: dValue - int containing the value for this
OUTPUT: none
RETURNS: none
*/
XMLFormVariantData::XMLFormVariantData( double dValue )
{
m_eValueType = eIsADouble;
m_dValue = dValue;
}
/* End of function "XMLFormVariantData::XMLFormVariantData"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: XMLFormVariantData::XMLFormVariantData
DESCRIPTION: ctor for assigning this as an integer
INPUT: dValue - int containing the value for this
OUTPUT: none
RETURNS: none
*/
XMLFormVariantData::XMLFormVariantData( int iValue )
{
m_eValueType = eIsAInteger;
m_iValue = iValue;
}
/* End of function "XMLFormVariantData::XMLFormVariantData"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: XMLFormVariantData::XMLFormVariantData
DESCRIPTION: ctor for assigning this as a boolean
INPUT: bValue - bool containing the value for this
OUTPUT: none
RETURNS: none
*/
XMLFormVariantData::XMLFormVariantData( bool bValue )
{
m_eValueType = eIsABoolean;
m_bValue = bValue;
}
/* End of function "XMLFormVariantData::XMLFormVariantData"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: XMLFormVariantData::XMLFormVariantData
DESCRIPTION: ctor for assigning this as a date time
INPUT: xValue - date/time structure containing value for this
OUTPUT: none
RETURNS: none
*/
XMLFormVariantData::XMLFormVariantData( SYSTEMTIME xValue )
{
m_eValueType = eIsADate;
memcpy( &m_xValue, &xValue, sizeof( SYSTEMTIME ) );
}
/* End of function "XMLFormVariantData::XMLFormVariantData"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: XMLFormVariantData::GetValueType
DESCRIPTION: returns the meta type for this to the caller
INPUT: void
OUTPUT: none
RETURNS: the type of data this is actually holding
*/
XMLFormVariantData::eFieldDataType XMLFormVariantData::GetValueType( void )
{
return m_eValueType;
}
/* End of function "XMLFormVariantData::GetValueType"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: XMLFormVariantData::GetValue
DESCRIPTION: return the value of this as a string. converting if necessary
to the extent that a conversion can be done
INPUT: roOutput - output will be put here
OUTPUT: string representation of the value in this
RETURNS: true if value is returned, false if not
*/
bool XMLFormVariantData::GetValue( std::string& roOutput )
{
switch ( m_eValueType )
{
case eIsAString:
{
roOutput = m_oValue;
return( true );
}
break;
case eIsADouble:
{
CString oTemp;
oTemp.Format( "%.6f", m_dValue );
roOutput.assign( (const char*)oTemp );
return( true );
}
break;
case eIsAInteger:
{
char achTemp[ 12 ];
itoa( m_iValue, achTemp, 10 );
roOutput.assign( achTemp );
return( true );
}
break;
case eIsABoolean:
{
if ( m_bValue )
{
roOutput.assign( "1" );
}
else
{
roOutput.assign( "0" );
}
return( true );
}
break;
case eIsADate:
{
char achDateTime[ 50 ];
sprintf( achDateTime,
"%02u/%02u/%02u %02u:%02u:%02u",
m_xValue.wMonth,
m_xValue.wDay,
m_xValue.wYear,
m_xValue.wHour,
m_xValue.wMinute,
m_xValue.wSecond );
roOutput.assign( achDateTime );
return( true );
}
break;
case eIsInvalidOrNull:
{
m_oValue.assign( "" );
return( false );
}
break;
}
return( false );
}
/* End of function "XMLFormVariantData::GetValue"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: XMLFormVariantData::GetValue
DESCRIPTION: returns the value of this as a number, converting if necessary
to the extent that a conversion can be done
INPUT: dblOutput - value will be placed here
OUTPUT: numeric representation of the value in this
RETURNS: true if a value was returned to the caller
*/
bool XMLFormVariantData::GetValue( double& rdblOutput )
{
switch ( m_eValueType )
{
case eIsAString:
{
const char* pchValue = m_oValue.c_str();
int iLength = strlen( pchValue );
// bCanConvert value assumes success
//
bool bCanConvert = true;
for ( int iLoop = 0; iLoop < iLength; iLoop++ )
{
if ( !isdigit( *(pchValue + iLoop ) ) )
{
if ( *(pchValue + iLoop ) != '.' )
{
bCanConvert = false;
}
}
}
if ( bCanConvert )
{
rdblOutput = atof( pchValue );
return( true );
}
else
{
return( false );
}
}
break;
case eIsADouble:
{
rdblOutput = m_dValue;
return( true );
}
break;
case eIsAInteger:
{
rdblOutput = m_iValue;
return( true );
}
break;
case eIsABoolean:
{
if ( m_bValue )
{
rdblOutput = 1;
}
else
{
rdblOutput = 0;
}
return( true );
}
break;
case eIsADate:
case eIsInvalidOrNull:
{
rdblOutput = 0;
return( false );
}
break;
}
return( false );
}
/* End of function "XMLFormVariantData::GetValue"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: XMLFormVariantData::GetValue
DESCRIPTION: returns the value of this as a number, converting if necessary
to the extent that a conversion can be done
INPUT: riOutput - value will be put here
OUTPUT: integer value of this will be returned via the parameter
RETURNS: true if value returned to the caller
*/
bool XMLFormVariantData::GetValue( int& riOutput )
{
switch ( m_eValueType )
{
case eIsAString:
{
const char* pchValue = m_oValue.c_str();
int iLength = strlen( pchValue );
// bCanConvert value assumes success
//
bool bCanConvert = true;
for ( int iLoop = 0; iLoop < iLength; iLoop++ )
{
if ( !isdigit( *(pchValue + iLoop ) ) )
{
bCanConvert = false;
}
}
if ( bCanConvert )
{
riOutput = atoi( pchValue );
return( true );
}
else
{
return( false );
}
}
break;
case eIsADouble:
{
riOutput = static_cast<int>(m_dValue);
return( true );
}
break;
case eIsAInteger:
{
riOutput = m_iValue;
return( true );
}
break;
case eIsABoolean:
{
if ( m_bValue )
{
riOutput = 1;
}
else
{
riOutput = 0;
}
return( true );
}
break;
case eIsADate:
case eIsInvalidOrNull:
{
return( false );
}
break;
}
return( false );
}
/* End of function "XMLFormVariantData::GetValue"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: XMLFormVariantData::GetValue
DESCRIPTION: returns the value of this as a bool, converting if necessary
to the extent that a conversion can be done
INPUT: rbOutput - value will be returned through here
OUTPUT: boolean representation of the value in this
RETURNS: true if value returned to caller
*/
bool XMLFormVariantData::GetValue( bool& rbOutput )
{
switch ( m_eValueType )
{
case eIsAString:
{
if ( 0 == m_oValue.length() )
{
rbOutput = false;
}
else
{
rbOutput = true;
}
return( true );
}
break;
case eIsADouble:
{
if ( 0 == m_dValue )
{
rbOutput = false;
}
else
{
rbOutput = true;
}
return( true );
}
break;
case eIsAInteger:
{
if ( 0 == m_iValue )
{
rbOutput = false;
}
else
{
rbOutput = true;
}
return( true );
}
break;
case eIsABoolean:
{
rbOutput = m_bValue;
return( true );
}
break;
case eIsADate:
case eIsInvalidOrNull:
{
return( false );
}
break;
}
return( false );
}
/* End of function "XMLFormVariantData::GetValue"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: XMLFormVariantData::GetValue
DESCRIPTION: returns the value of this as a bool, converting if necessary
to the extent that a conversion can be done
INPUT: rxOutput - value will be returned through here
OUTPUT: date representation of the value in this
RETURNS: true if value returned to caller
*/
bool XMLFormVariantData::GetValue( SYSTEMTIME& rxOutput )
{
switch ( m_eValueType )
{
case eIsAString:
case eIsADouble:
case eIsAInteger:
case eIsABoolean:
case eIsInvalidOrNull:
{
return( false );
}
break;
case eIsADate:
{
memcpy( &rxOutput, &m_xValue, sizeof( SYSTEMTIME ) );
return( true );
}
break;
}
return( false );
}
/* End of function "XMLFormVariantData::GetValue"
/*****************************************************************************/
/*****************************************************************************/
/* Check-in history
$WorkFile: $
$Archive: $
*$Log: $
*/
/*****************************************************************************/
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.