Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version
Go to top

Linq-To-XML Style of Node Creation for C++

, 7 Jun 2012
Linq-To-XML Node Creation for Native C++
elmax-84498.zip
BuildProcessTemplates
Elmax.vsmdi
ElmaxNet
Properties
Elmax
Elmax.vcxproj.user
StringUtils
Local.testsettings
TestNativeElmax
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax
Properties
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
TryoutNet
Properties
Settings.settings
Tryout
res
Tryout.ico
Tryout.vcxproj.user
elmax-ver083.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
elmax-ver084.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
elmax-ver085.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
elmax-ver086.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
elmax-ver087.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
Elmax-ver089.zip
Elmax-ver089
Elmax.vsmdi
Elmax
Elmax.vcxproj.user
StringUtils
ElmaxNet
Properties
Local.testsettings
TestNativeElmax
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax
Properties
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout
res
Tryout.ico
Tryout.vcxproj.user
TryoutNet
Properties
Settings.settings
ElmaxSrcVer082.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
#pragma once

#include "BaseConverter.h"
#ifdef ELMAX_USE_BOOST_REGEX
	#include <boost/regex.hpp>
#else
	#include <regex>
#endif

namespace Elmax
{
//! Class to convert values to and fro string with regex checks in accessors methods.
class RegexConverter : public Elmax::BaseConverter
{
public:
	//! Default constructor
	RegexConverter(void);
	//! Virtual destructor
	virtual ~RegexConverter(void);
	//! Convert the boolean into string
	//!
	//! @param dest is the string to be set
	//! @param val is the source boolean value to convert from
	//! @returns true if successful
	virtual bool SetBool(std::wstring& dest, bool val);
	//! Convert the character into string
	//!
	//! @param dest is the string to be set
	//! @param val is the source character value to convert from
	//! @returns true if successful
	virtual bool SetChar(std::wstring& dest, char val);
	//! Convert the short integer into string
	//!
	//! @param dest is the string to be set
	//! @param val is the source short integer value to convert from
	//! @returns true if successful
	virtual bool SetShort(std::wstring& dest, short val);
	//! Convert the 32bit integer into string
	//!
	//! @param dest is the string to be set
	//! @param val is the source 32bit integer value to convert from
	//! @returns true if successful
	virtual bool SetInt32(std::wstring& dest, int val);
	//! Convert the 64bit integer into string
	//!
	//! @param dest is the string to be set
	//! @param val is the source 64bit integer value to convert from
	//! @returns true if successful
	virtual bool SetInt64(std::wstring& dest, __int64 val);
	//! Convert the unsigned character into string
	//!
	//! @param dest is the string to be set
	//! @param val is the source unsigned character value to convert from
	//! @returns true if successful
	virtual bool SetUChar(std::wstring& dest, unsigned char val);
	//! Convert the unsigned short into string
	//!
	//! @param dest is the string to be set
	//! @param val is the source unsigned short value to convert from
	//! @returns true if successful
	virtual bool SetUShort(std::wstring& dest, unsigned short val);
	//! Convert the unsigned 32bit integer into string
	//!
	//! @param dest is the string to be set
	//! @param val is the source unsigned 32bit integer value to convert from
	//! @returns true if successful
	virtual bool SetUInt32(std::wstring& dest, unsigned int val);
	//! Convert the unsigned 64bit integer into string
	//!
	//! @param dest is the string to be set
	//! @param val is the source unsigned 64bit integer value to convert from
	//! @returns true if successful
	virtual bool SetUInt64(std::wstring& dest, unsigned __int64 val);
	//! Convert the float into string
	//!
	//! @param dest is the string to be set
	//! @param val is the source float value to convert from
	//! @returns true if successful
	virtual bool SetFloat(std::wstring& dest, float val);
	//! Convert the double into string
	//!
	//! @param dest is the string to be set
	//! @param val is the source double value to convert from
	//! @returns true if successful
	virtual bool SetDouble(std::wstring& dest, double val);
	//! Set the wide string into string
	//!
	//! @param dest is the string to be set
	//! @param val is the source wide string value to set from
	//! @returns true if successful
	virtual bool SetString(std::wstring& dest, const std::wstring& val);
	//! Set the ascii string into string
	//!
	//! @param dest is the string to be set
	//! @param val is the source ascii string value to set from
	//! @returns true if successful
	virtual bool SetString(std::wstring& dest, const std::string& val);
	//! Convert the string into boolean ("true" or "yes" or "1" or "ok" get true value 
	//! while "false" or "no" or "0" or "cancel" get false value)
	//!
	//! @param src is the source string to convert from
	//! @param defaultVal is the default boolean value to use if src is invalid or empty
	//! @param val is the destination boolean value to be set
	//! @returns true if successful
	virtual bool GetBool(const std::wstring& src, bool defaultVal, bool& val);
	//! Convert the string into character
	//!
	//! @param src is the source string to convert from
	//! @param defaultVal is the default character value to use if src is invalid or empty
	//! @param val is the destination character value to be set
	//! @returns true if successful
	virtual bool GetChar(const std::wstring& src, char defaultVal, char& val);
	//! Convert the string into short integer
	//!
	//! @param src is the source string to convert from
	//! @param defaultVal is the default short integer value to use if src is invalid or empty
	//! @param val is the destination short integer value to be set
	//! @returns true if successful
	virtual bool GetShort(const std::wstring& src, short defaultVal, short& val);
	//! Convert the string into 32bit integer
	//!
	//! @param src is the source string to convert from
	//! @param defaultVal is the default 32bit integer value to use if src is invalid or empty
	//! @param val is the destination 32bit integer value to be set
	//! @returns true if successful
	virtual bool GetInt32(const std::wstring& src, int defaultVal, int& val);
	//! Convert the string into 64bit integer
	//!
	//! @param src is the source string to convert from
	//! @param defaultVal is the default 64bit integer value to use if src is invalid or empty
	//! @param val is the destination 64bit integer value to be set
	//! @returns true if successful
	virtual bool GetInt64(const std::wstring& src, __int64 defaultVal, __int64& val);
	//! Convert the string into unsigned character
	//!
	//! @param src is the source string to convert from
	//! @param defaultVal is the default unsigned character value to use if src is invalid or empty
	//! @param val is the destination unsigned character value to be set
	//! @returns true if successful
	virtual bool GetUChar(const std::wstring& src, unsigned char defaultVal, unsigned char& val);
	//! Convert the string into unsigned short
	//!
	//! @param src is the source string to convert from
	//! @param defaultVal is the default unsigned short value to use if src is invalid or empty
	//! @param val is the destination unsigned short value to be set
	//! @returns true if successful
	virtual bool GetUShort(const std::wstring& src, unsigned short defaultVal, unsigned short& val);
	//! Convert the string into unsigned 32bit integer
	//!
	//! @param src is the source string to convert from
	//! @param defaultVal is the default unsigned 32bit integer value to use if src is invalid or empty
	//! @param val is the destination unsigned 32bit integer value to be set
	//! @returns true if successful
	virtual bool GetUInt32(const std::wstring& src, unsigned int defaultVal, unsigned int& val);
	//! Convert the string into unsigned 64bit integer
	//!
	//! @param src is the source string to convert from
	//! @param defaultVal is the default unsigned 64bit integer value to use if src is invalid or empty
	//! @param val is the destination unsigned 64bit integer value to be set
	//! @returns true if successful
	virtual bool GetUInt64(const std::wstring& src, unsigned __int64 defaultVal, unsigned __int64& val);
	//! Convert the string into float
	//!
	//! @param src is the source string to convert from
	//! @param defaultVal is the default float value to use if src is invalid or empty
	//! @param val is the destination float value to be set
	//! @returns true if successful
	virtual bool GetFloat(const std::wstring& src, float defaultVal, float& val);
	//! Convert the string into double
	//!
	//! @param src is the source string to convert from
	//! @param defaultVal is the default double value to use if src is invalid or empty
	//! @param val is the destination double value to be set
	//! @returns true if successful
	virtual bool GetDouble(const std::wstring& src, double defaultVal, double& val);
	//! Set the string into wide string
	//!
	//! @param src is the source string to convert from
	//! @param defaultVal is the default wide string value to use if src is invalid or empty
	//! @param val is the destination wide string value to be set
	//! @returns true if successful
	virtual bool GetString(const std::wstring& src, const std::wstring& defaultVal, std::wstring& val);
	//! Convert the string into ascii string
	//!
	//! @param src is the source string to convert from
	//! @param defaultVal is the default ascii string value to use if src is invalid or empty
	//! @param val is the destination ascii string value to be set
	//! @returns true if successful
	virtual bool GetString(const std::wstring& src, const std::string& defaultVal, std::string& val);
private:
#ifdef ELMAX_USE_BOOST_REGEX
	//! regex object for float
	boost::wregex m_rxFloat;
	//! regex object for integer
	boost::wregex m_rxInt;
	//! regex object for unsigned integer
	boost::wregex m_rxUInt;
#else
	//! regex object for float
	std::tr1::wregex m_rxFloat;
	//! regex object for integer
	std::tr1::wregex m_rxInt;
	//! regex object for unsigned integer
	std::tr1::wregex m_rxUInt;
#endif // ELMAX_USE_BOOST_REGEX

};

} // ns Elmax

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.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

Share

About the Author

Shao Voon Wong
Software Developer
Singapore Singapore
No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 7 Jun 2012
Article Copyright 2011 by Shao Voon Wong
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid