Index: ext/libicpf/src/cfg_xml.cpp =================================================================== diff -u -N -rd5bb2e19e22f57bd018e9db355108b54dfbc364c -r9bdff2e0b309af11014634d8c38367e4f6b656e3 --- ext/libicpf/src/cfg_xml.cpp (.../cfg_xml.cpp) (revision d5bb2e19e22f57bd018e9db355108b54dfbc364c) +++ ext/libicpf/src/cfg_xml.cpp (.../cfg_xml.cpp) (revision 9bdff2e0b309af11014634d8c38367e4f6b656e3) @@ -77,7 +77,7 @@ * \param[in] name - name of the tag being processed * \param[in] attrs - array of pointers to strings with attributes and their values */ -void XMLCALL element_start(void *userData, const tchar_t *name, const tchar_t **attrs) +void xml_cfg::element_start(void *userData, const tchar_t *name, const tchar_t **attrs) { XMLSTATE* pState=(XMLSTATE*)userData; @@ -95,7 +95,11 @@ if (bContainer) { - std::pair pr=pState->pNode->m_mNodes.insert(xml_storage::value_type(tstring_t(name), xml_node(pState->pNode))); + std::pair pr; + if (pState->pNode) + pr=pState->pNode->m_mNodes.insert(xml_storage::value_type(tstring_t(name), xml_node(pState->pNode))); + else + pr=((xml_storage*)pState->pCfg->m_hStorage)->insert(xml_storage::value_type(tstring_t(name), xml_node(pState->pNode))); pState->pNode=&((*pr.first).second); } } @@ -105,7 +109,7 @@ * \param[in] userData - user defined parameter * \param[in] name - name of the tag being closed */ -void XMLCALL element_end(void *userData, const XML_Char* /*name*/) +void xml_cfg::element_end(void *userData, const tchar_t* /*name*/) { XMLSTATE* pState=(XMLSTATE*)userData; @@ -139,7 +143,7 @@ XML_SetElementHandler(parser, element_start, element_end); // XML_SetCharacterDataHandler(parser, element_content); - XMLSTATE xs = { this }; + XMLSTATE xs = { this, NULL }; XML_SetUserData(parser, &xs); for (;;) Index: ext/libicpf/src/cfg_xml.h =================================================================== diff -u -N -rd5bb2e19e22f57bd018e9db355108b54dfbc364c -r9bdff2e0b309af11014634d8c38367e4f6b656e3 --- ext/libicpf/src/cfg_xml.h (.../cfg_xml.h) (revision d5bb2e19e22f57bd018e9db355108b54dfbc364c) +++ ext/libicpf/src/cfg_xml.h (.../cfg_xml.h) (revision 9bdff2e0b309af11014634d8c38367e4f6b656e3) @@ -11,7 +11,7 @@ * It handles the xml data streams contained in the files, providing * a way to set and retrieve data contained in the xml document. */ -class xml_cfg : public config_base +class LIBICPF_API xml_cfg : public config_base { public: /** \name Construction/destruction/operators */ @@ -52,6 +52,9 @@ /// Clear helper - clears the appropriate attribures void clear(ptr_t pNodePtr, const tchar_t* pszName); + static void element_start(void *userData, const tchar_t *name, const tchar_t **attrs); + static void element_end(void *userData, const tchar_t* /*name*/); + protected: ptr_t m_hStorage; ///< Handle to the internal xml storage }; Index: ext/libicpf/src/config_property.cpp =================================================================== diff -u -N -rd5bb2e19e22f57bd018e9db355108b54dfbc364c -r9bdff2e0b309af11014634d8c38367e4f6b656e3 --- ext/libicpf/src/config_property.cpp (.../config_property.cpp) (revision d5bb2e19e22f57bd018e9db355108b54dfbc364c) +++ ext/libicpf/src/config_property.cpp (.../config_property.cpp) (revision 9bdff2e0b309af11014634d8c38367e4f6b656e3) @@ -30,8 +30,11 @@ m_uiPropType(uiType), m_pszName(NULL) { + memset(&m_val, 0, sizeof(_VALUE)); + memset(&m_range, 0, sizeof(_RANGE)); + // init - init(pszName, uiType); + init(pszName, uiType, false); } /** Constructs a property object based on some other property object. @@ -40,7 +43,7 @@ */ property::property(const property& src) { - operator=(src); + copy_from(src, false); } /** Destructs the property object. @@ -58,71 +61,8 @@ property& property::operator=(const property& rSrc) { if (this != &rSrc) - { - // clear values in this class - clear_value(); + copy_from(rSrc, true); - // copy the value(s) - if (rSrc.m_uiPropType & flag_array) - { - // source property is an array - switch(rSrc.m_uiPropType & mask_type) - { - case type_string: - m_val.hArray=new std::vector(*(std::vector*)rSrc.m_val.hArray); - break; - case type_signed_num: - m_val.hArray=new std::vector(*(std::vector*)rSrc.m_val.hArray); - break; - case type_unsigned_num: - m_val.hArray=new std::vector(*(std::vector*)rSrc.m_val.hArray); - break; - case type_bool: - m_val.hArray=new std::vector(*(std::vector*)rSrc.m_val.hArray); - break; - default: - assert(false); // unknown property type - } - } - else - { - // source property is normal value - switch(rSrc.m_uiPropType & mask_type) - { - case type_string: - { - m_val.pszVal=copy_string(rSrc.m_val.pszVal); - break; - } - case type_signed_num: - { - m_val.llVal=rSrc.m_val.llVal; - m_range.ll.llHi=rSrc.m_range.ll.llHi; - m_range.ll.llLo=rSrc.m_range.ll.llLo; - break; - } - case type_unsigned_num: - { - m_val.ullVal=rSrc.m_val.ullVal; - m_range.ull.ullHi=rSrc.m_range.ull.ullHi; - m_range.ull.ullLo=rSrc.m_range.ull.ullLo; - break; - } - case type_bool: - { - m_val.bVal=rSrc.m_val.bVal; - break; - } - default: - assert(false); // property type not implemented? - } - } - - // copy values - m_uiPropType=rSrc.m_uiPropType; - m_pszName=copy_string(rSrc.m_pszName); - } - return *this; } @@ -973,4 +913,76 @@ #endif } +/** Function makes a copy of a given property storing it in this one. + * + * \param[in] rSrc - property to copy from + * \param[in] bClear - should we cleat current contents first + */ +void property::copy_from(const property& rSrc, bool bClear) +{ + // clear values in this class + if (bClear) + clear_value(); + + // copy the value(s) + if (rSrc.m_uiPropType & flag_array) + { + // source property is an array + switch(rSrc.m_uiPropType & mask_type) + { + case type_string: + m_val.hArray=new std::vector(*(std::vector*)rSrc.m_val.hArray); + break; + case type_signed_num: + m_val.hArray=new std::vector(*(std::vector*)rSrc.m_val.hArray); + break; + case type_unsigned_num: + m_val.hArray=new std::vector(*(std::vector*)rSrc.m_val.hArray); + break; + case type_bool: + m_val.hArray=new std::vector(*(std::vector*)rSrc.m_val.hArray); + break; + default: + assert(false); // unknown property type + } + } + else + { + // source property is normal value + switch(rSrc.m_uiPropType & mask_type) + { + case type_string: + { + m_val.pszVal=copy_string(rSrc.m_val.pszVal); + break; + } + case type_signed_num: + { + m_val.llVal=rSrc.m_val.llVal; + m_range.ll.llHi=rSrc.m_range.ll.llHi; + m_range.ll.llLo=rSrc.m_range.ll.llLo; + break; + } + case type_unsigned_num: + { + m_val.ullVal=rSrc.m_val.ullVal; + m_range.ull.ullHi=rSrc.m_range.ull.ullHi; + m_range.ull.ullLo=rSrc.m_range.ull.ullLo; + break; + } + case type_bool: + { + m_val.bVal=rSrc.m_val.bVal; + break; + } + default: + assert(false); // property type not implemented? + } + } + + // copy values + m_uiPropType=rSrc.m_uiPropType; + m_pszName=copy_string(rSrc.m_pszName); +} + END_ICPF_NAMESPACE Index: ext/libicpf/src/config_property.h =================================================================== diff -u -N -rd5bb2e19e22f57bd018e9db355108b54dfbc364c -r9bdff2e0b309af11014634d8c38367e4f6b656e3 --- ext/libicpf/src/config_property.h (.../config_property.h) (revision d5bb2e19e22f57bd018e9db355108b54dfbc364c) +++ ext/libicpf/src/config_property.h (.../config_property.h) (revision 9bdff2e0b309af11014634d8c38367e4f6b656e3) @@ -128,6 +128,8 @@ ll_t signed_from_string(const tchar_t* pszSrc); ///< Retrieves a signed number from a string ull_t unsigned_from_string(const tchar_t* pszSrc); ///< Retrieves an unsigned number from a string + void copy_from(const property& rSrc, bool bClear); ///< Makes a copy of a given property + protected: // basic, common property description uint_t m_uiPropType; ///< Property type and flags Index: ext/libicpf/src/exception.cpp =================================================================== diff -u -N -r6dae57f5e7aeeb965bc018024d8360069f6e15c1 -r9bdff2e0b309af11014634d8c38367e4f6b656e3 --- ext/libicpf/src/exception.cpp (.../exception.cpp) (revision 6dae57f5e7aeeb965bc018024d8360069f6e15c1) +++ ext/libicpf/src/exception.cpp (.../exception.cpp) (revision 9bdff2e0b309af11014634d8c38367e4f6b656e3) @@ -31,6 +31,7 @@ /** Constructor that takes the const description. The description (along with other tchar_t* parameters) * are copied to the internal members (so there is some memory allocation). + * * \param[in] pszDesc - exception description (currently should be in english) * \param[in] pszFilename - source file name from which the exception is thrown * \param[in] pszFunction - function name from which the exception is thrown @@ -51,11 +52,16 @@ set_string(&m_pszDesc, pszDesc); set_string(&m_pszFilename, pszFilename); set_string(&m_pszFunction, pszFunction); +#if defined(_DEBUG) && (defined(_WIN32) || defined(_WIN64)) + tchar_t szInfo[MAX_EXCEPTION]; + OutputDebugString(get_info(szInfo, MAX_EXCEPTION)); +#endif } /** Constructor that takes the ptr to a buffer as a description. The pointer to a buffer is * stored in the internal member and will be deleted in the destructor. Other tchar_t* parameters * are copied to the internal members (so there is some memory allocated). + * * \param[in] pszDesc - ptr to exception description (currently should be in english) allocated with new operator * \param[in] pszFilename - source file name from which the exception is thrown * \param[in] pszFunction - function name from which the exception is thrown @@ -75,8 +81,30 @@ { set_string(&m_pszFilename, pszFilename); set_string(&m_pszFunction, pszFunction); +#if defined(_DEBUG) && (defined(_WIN32) || defined(_WIN64)) + tchar_t szInfo[MAX_EXCEPTION]; + OutputDebugString(get_info(szInfo, MAX_EXCEPTION)); +#endif } +/** Copy constructor for the exception class. + * + * \param[in] rSrc - source exception to copy data from + */ +exception::exception(const exception& rSrc) : + m_pszDesc(NULL), + m_pszFilename(NULL), + m_pszFunction(NULL), + m_uiLine(rSrc.m_uiLine), + m_uiAppCode(rSrc.m_uiAppCode), + m_uiSystemCode(rSrc.m_uiSystemCode), + m_uiReserved(rSrc.m_uiReserved) +{ + set_string(&m_pszDesc, rSrc.m_pszDesc); + set_string(&m_pszFilename, rSrc.m_pszFilename); + set_string(&m_pszFunction, rSrc.m_pszFunction); +} + /** Destructor deletes all the allocated memory for the exception object */ exception::~exception() @@ -86,17 +114,42 @@ delete [] m_pszFunction; } +/** Assigns another exception data to this object. + * + * \param[in] e - source exception to copy from. + * \return Reference to this object. + */ +exception& exception::operator=(const exception& eSrc) +{ + if (this != &eSrc) + { + delete [] m_pszDesc; + delete [] m_pszFilename; + delete [] m_pszFunction; + + set_string(&m_pszDesc, eSrc.m_pszDesc); + set_string(&m_pszFilename, eSrc.m_pszFilename); + set_string(&m_pszFunction, eSrc.m_pszFunction); + m_uiLine=eSrc.m_uiLine; + m_uiAppCode=eSrc.m_uiAppCode; + m_uiSystemCode=eSrc.m_uiSystemCode; + m_uiReserved=eSrc.m_uiReserved; + } + + return *this; +} + /** Function retrieves the full information about the exception into * the string buffer specified by user. * \param[out] pszInfo - buffer fot the full exception description * \param[in] tMaxLen - size of the specified buffer * \return Pointer to the exception description (to the pszInfo to be specific) */ -const tchar_t* exception::get_info(tchar_t* pszInfo, intptr_t tMaxLen) +const tchar_t* exception::get_info(tchar_t* pszInfo, size_t stMaxLen) { - _sntprintf(pszInfo, (size_t)tMaxLen, _t("description: ") TSTRFMT _t("\nfile: ") TSTRFMT _t("\nfunction: ") TSTRFMT _t("\nline: ") ULFMT _t("\napp code: ") ULFMT _t("\nsys code: ") ULFMT _t("\nreserved: ") ULFMT _t("\n"), + _sntprintf(pszInfo, stMaxLen, _t("description: ") TSTRFMT _t("\nfile: ") TSTRFMT _t("\nfunction: ") TSTRFMT _t("\nline: ") ULFMT _t("\napp code: ") ULFMT _t("\nsys code: ") ULFMT _t("\nreserved: ") ULFMT _t("\n"), m_pszDesc, m_pszFilename, m_pszFunction, m_uiLine, m_uiAppCode, m_uiSystemCode, m_uiReserved); - pszInfo[tMaxLen-1]=_t('\0'); + pszInfo[stMaxLen-1]=_t('\0'); return pszInfo; } Index: ext/libicpf/src/exception.h =================================================================== diff -u -N -raba7605f4821e4a65dd64cb5118f4f44d65155eb -r9bdff2e0b309af11014634d8c38367e4f6b656e3 --- ext/libicpf/src/exception.h (.../exception.h) (revision aba7605f4821e4a65dd64cb5118f4f44d65155eb) +++ ext/libicpf/src/exception.h (.../exception.h) (revision 9bdff2e0b309af11014634d8c38367e4f6b656e3) @@ -28,6 +28,7 @@ #include "libicpf.h" #include "gen_types.h" +#undef THROW /** \brief Macro used for throwing an exception the easy way. * * Macro throws an exception specified by the parameters. Other params needed by @@ -38,7 +39,6 @@ * \param[in] sys_code - system error code (platform specific) * \param[in] reserved_code - currently unused; must be 0 */ -#undef THROW #define THROW(desc,app_code,sys_code,reserved_code) throw icpf::exception(desc, _t(__FILE__), _t(__FUNCTION__), __LINE__, app_code, sys_code, reserved_code) /// Logs an exception in a log file #define LOG_EXCEPTION(except, ptr_log) (except)->log("Caught an exception in ", _t(__FUNCTION__), ptr_log) @@ -61,13 +61,18 @@ exception(const tchar_t* pszDesc, const tchar_t* pszFilename, const tchar_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved); /// Standard constructor that takes non-const ptr to a buffer as the description exception(tchar_t* pszDesc, const tchar_t* pszFilename, const tchar_t* pszFunction, uint_t uiLine, uint_t uiAppCode, uint_t uiSystemCode, uint_t uiReserved); + /// Copy constructor + exception(const exception& rSrc); /// Standard destructor ~exception(); + + /// Assignment operator + exception& operator=(const exception& eSrc); /**@}*/ /** \name Outputting */ /**@{*/ - const tchar_t* get_info(tchar_t* pszInfo, intptr_t tMaxLen); ///< Retrieves the exception information to a specified string buffer + const tchar_t* get_info(tchar_t* pszInfo, size_t stMaxLen); ///< Retrieves the exception information to a specified string buffer const tchar_t* get_desc() const { return m_pszDesc; }; const tchar_t* get_filename() const { return m_pszFilename; }; const tchar_t* get_function() const { return m_pszFunction; };