From d23a489940499bd6c634a1cb0a9875f094f8a850 Mon Sep 17 00:00:00 2001 From: weidai Date: Thu, 20 Mar 2003 01:24:12 +0000 Subject: various changes for 5.1 git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@38 57ff6487-cd31-0410-9ec3-f628ee90f5f0 --- algparam.h | 54 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) (limited to 'algparam.h') diff --git a/algparam.h b/algparam.h index 624fcdc..999998d 100644 --- a/algparam.h +++ b/algparam.h @@ -88,29 +88,33 @@ template class GetValueHelperClass { public: - GetValueHelperClass(const T *pObject, const char *name, const std::type_info &valueType, void *pValue) + GetValueHelperClass(const T *pObject, const char *name, const std::type_info &valueType, void *pValue, const NameValuePairs *searchFirst) : m_pObject(pObject), m_name(name), m_valueType(&valueType), m_pValue(pValue), m_found(false), m_getValueNames(false) { - if (strcmp(name, "ValueNames") == 0) - m_found = m_getValueNames = true; - - std::string thisPointerName = std::string("ThisPointer:") + typeid(T).name(); - - if (m_getValueNames) + if (strcmp(m_name, "ValueNames") == 0) { - NameValuePairs::ThrowIfTypeMismatch(name, typeid(std::string), *m_valueType); + m_found = m_getValueNames = true; + NameValuePairs::ThrowIfTypeMismatch(m_name, typeid(std::string), *m_valueType); + if (searchFirst) + searchFirst->GetVoidValue(m_name, valueType, pValue); if (typeid(T) != typeid(BASE)) - pObject->BASE::GetVoidValue(name, valueType, pValue); - (*reinterpret_cast(m_pValue) += thisPointerName) += ";"; + pObject->BASE::GetVoidValue(m_name, valueType, pValue); + ((*reinterpret_cast(m_pValue) += "ThisPointer:") += typeid(T).name()) += ';'; } - else if (name == thisPointerName) + + if (!m_found && strncmp(m_name, "ThisPointer:", 12) == 0 && strcmp(m_name+12, typeid(T).name()) == 0) { - NameValuePairs::ThrowIfTypeMismatch(name, typeid(T *), *m_valueType); + NameValuePairs::ThrowIfTypeMismatch(m_name, typeid(T *), *m_valueType); *reinterpret_cast(pValue) = pObject; m_found = true; + return; } - else if (typeid(T) != typeid(BASE)) - m_found = pObject->BASE::GetVoidValue(name, valueType, pValue); + + if (!m_found && searchFirst) + m_found = searchFirst->GetVoidValue(m_name, valueType, pValue); + + if (!m_found && typeid(T) != typeid(BASE)) + m_found = pObject->BASE::GetVoidValue(m_name, valueType, pValue); } operator bool() const {return m_found;} @@ -120,7 +124,7 @@ public: { if (m_getValueNames) (*reinterpret_cast(m_pValue) += name) += ";"; - else if (!m_found && strcmp(name, m_name) == 0) + if (!m_found && strcmp(name, m_name) == 0) { NameValuePairs::ThrowIfTypeMismatch(name, typeid(R), *m_valueType); *reinterpret_cast(m_pValue) = (m_pObject->*pm)(); @@ -131,10 +135,9 @@ public: GetValueHelperClass &Assignable() { - std::string thisObjectName = std::string("ThisObject:") + typeid(T).name(); if (m_getValueNames) - (*reinterpret_cast(m_pValue) += thisObjectName) += ";"; - else if (!m_found && m_name == thisObjectName) + ((*reinterpret_cast(m_pValue) += "ThisObject:") += typeid(T).name()) += ';'; + if (!m_found && strncmp(m_name, "ThisObject:", 11) == 0 && strcmp(m_name+11, typeid(T).name()) == 0) { NameValuePairs::ThrowIfTypeMismatch(m_name, typeid(T), *m_valueType); *reinterpret_cast(m_pValue) = *m_pObject; @@ -152,15 +155,15 @@ private: }; template -GetValueHelperClass GetValueHelper(const T *pObject, const char *name, const std::type_info &valueType, void *pValue, BASE *dummy=NULL) +GetValueHelperClass GetValueHelper(const T *pObject, const char *name, const std::type_info &valueType, void *pValue, const NameValuePairs *searchFirst=NULL, BASE *dummy=NULL) { - return GetValueHelperClass(pObject, name, valueType, pValue); + return GetValueHelperClass(pObject, name, valueType, pValue, searchFirst); } template -GetValueHelperClass GetValueHelper(const T *pObject, const char *name, const std::type_info &valueType, void *pValue) +GetValueHelperClass GetValueHelper(const T *pObject, const char *name, const std::type_info &valueType, void *pValue, const NameValuePairs *searchFirst=NULL) { - return GetValueHelperClass(pObject, name, valueType, pValue); + return GetValueHelperClass(pObject, name, valueType, pValue, searchFirst); } // ******************************************************** @@ -239,7 +242,8 @@ AssignFromHelperClass AssignFromHelper(T *pObject, const NameValuePairs &s // ******************************************************** -void AssignIntToInteger(void *pInteger, const void *pInt); +// This should allow the linker to discard Integer code if not needed. +extern bool (*AssignIntToInteger)(const std::type_info &valueType, void *pInteger, const void *pInt); const std::type_info & IntegerTypeId(); @@ -283,9 +287,7 @@ public: else if (strcmp(name, m_name) == 0) { // special case for retrieving an Integer parameter when an int was passed in - if (valueType == IntegerTypeId() && typeid(T) == typeid(int)) - AssignIntToInteger(pValue, &m_value); - else + if (!(AssignIntToInteger != NULL && typeid(T) == typeid(int) && AssignIntToInteger(valueType, pValue, &m_value))) { ThrowIfTypeMismatch(name, typeid(T), valueType); *reinterpret_cast(pValue) = m_value; -- cgit v1.2.1