From db0e7777d9d74bb76fea19498bc231328c7b17c2 Mon Sep 17 00:00:00 2001 From: Khaled Noaman <knoaman@apache.org> Date: Tue, 16 Dec 2003 18:41:15 +0000 Subject: [PATCH] Make IC_Field stateless git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@175579 13f79535-47bb-0310-9956-ffa450edef68 --- .../schema/identity/FieldActivator.cpp | 20 +++++++++-- .../schema/identity/FieldActivator.hpp | 28 ++++++++++++--- .../validators/schema/identity/IC_Field.cpp | 22 ++++++++---- .../validators/schema/identity/IC_Field.hpp | 35 ++++++++++++++----- .../validators/schema/identity/ValueStore.cpp | 13 ++++++- .../validators/schema/identity/ValueStore.hpp | 19 +++++++--- 6 files changed, 111 insertions(+), 26 deletions(-) diff --git a/src/xercesc/validators/schema/identity/FieldActivator.cpp b/src/xercesc/validators/schema/identity/FieldActivator.cpp index 64864a1f5..0462b67a2 100644 --- a/src/xercesc/validators/schema/identity/FieldActivator.cpp +++ b/src/xercesc/validators/schema/identity/FieldActivator.cpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.6 2003/12/16 18:41:15 knoaman + * Make IC_Field stateless + * * Revision 1.5 2003/05/22 02:10:52 knoaman * Default the memory manager. * @@ -83,6 +86,7 @@ #include <xercesc/validators/schema/identity/ValueStore.hpp> #include <xercesc/validators/schema/identity/ValueStoreCache.hpp> #include <xercesc/validators/schema/identity/XPathMatcherStack.hpp> +#include <xercesc/util/HashPtr.hpp> XERCES_CPP_NAMESPACE_BEGIN @@ -94,15 +98,27 @@ FieldActivator::FieldActivator(ValueStoreCache* const valueStoreCache, MemoryManager* const manager) : fValueStoreCache(valueStoreCache) , fMatcherStack(matcherStack) + , fMayMatch(0) , fMemoryManager(manager) { + fMayMatch = new (manager) ValueHashTableOf<bool>(29, new (manager) HashPtr(), manager); } FieldActivator::FieldActivator(const FieldActivator& other) : fValueStoreCache(other.fValueStoreCache) , fMatcherStack(other.fMatcherStack) + , fMayMatch(0) , fMemoryManager(other.fMemoryManager) { + fMayMatch = new (fMemoryManager) ValueHashTableOf<bool>(29, new (fMemoryManager) HashPtr(), fMemoryManager); + ValueHashTableOfEnumerator<bool> mayMatchEnum(other.fMayMatch); + + // Build key set + while (mayMatchEnum.hasMoreElements()) + { + IC_Field* field = (IC_Field*) mayMatchEnum.nextElementKey(); + fMayMatch->put(field, other.fMayMatch->get(field)); + } } @@ -130,9 +146,9 @@ FieldActivator& FieldActivator::operator =(const FieldActivator& other) { XPathMatcher* FieldActivator::activateField(IC_Field* const field, const int initialDepth) { ValueStore* valueStore = fValueStoreCache->getValueStoreFor(field, initialDepth); - XPathMatcher* matcher = field->createMatcher(valueStore, fMemoryManager); + XPathMatcher* matcher = field->createMatcher(this, valueStore, fMemoryManager); - field->setMayMatch(true); + setMayMatch(field, true); fMatcherStack->addMatcher(matcher); matcher->startDocumentFragment(); diff --git a/src/xercesc/validators/schema/identity/FieldActivator.hpp b/src/xercesc/validators/schema/identity/FieldActivator.hpp index 471bbe29a..79f4cacee 100644 --- a/src/xercesc/validators/schema/identity/FieldActivator.hpp +++ b/src/xercesc/validators/schema/identity/FieldActivator.hpp @@ -69,7 +69,7 @@ // --------------------------------------------------------------------------- // Includes // --------------------------------------------------------------------------- -#include <xercesc/util/PlatformUtils.hpp> +#include <xercesc/util/ValueHashTableOf.hpp> XERCES_CPP_NAMESPACE_BEGIN @@ -100,11 +100,17 @@ public: // ----------------------------------------------------------------------- FieldActivator& operator =(const FieldActivator& other); + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + bool getMayMatch(IC_Field* const field); + // ----------------------------------------------------------------------- // Setter methods // ----------------------------------------------------------------------- void setValueStoreCache(ValueStoreCache* const other); void setMatcherStack(XPathMatcherStack* const matcherStack); + void setMayMatch(IC_Field* const field, bool value); // ----------------------------------------------------------------------- // Activation methods @@ -131,12 +137,21 @@ private: // ----------------------------------------------------------------------- // Data // ----------------------------------------------------------------------- - ValueStoreCache* fValueStoreCache; - XPathMatcherStack* fMatcherStack; - MemoryManager* fMemoryManager; + ValueStoreCache* fValueStoreCache; + XPathMatcherStack* fMatcherStack; + ValueHashTableOf<bool>* fMayMatch; + MemoryManager* fMemoryManager; }; +// --------------------------------------------------------------------------- +// FieldActivator: Getter methods +// --------------------------------------------------------------------------- +inline bool FieldActivator::getMayMatch(IC_Field* const field) { + + return fMayMatch->get(field); +} + // --------------------------------------------------------------------------- // FieldActivator: Setter methods // --------------------------------------------------------------------------- @@ -151,6 +166,11 @@ FieldActivator::setMatcherStack(XPathMatcherStack* const matcherStack) { fMatcherStack = matcherStack; } +inline void FieldActivator::setMayMatch(IC_Field* const field, bool value) { + + fMayMatch->put(field, value); +} + XERCES_CPP_NAMESPACE_END #endif diff --git a/src/xercesc/validators/schema/identity/IC_Field.cpp b/src/xercesc/validators/schema/identity/IC_Field.cpp index 4653cb5be..81be17be8 100644 --- a/src/xercesc/validators/schema/identity/IC_Field.cpp +++ b/src/xercesc/validators/schema/identity/IC_Field.cpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.6 2003/12/16 18:41:15 knoaman + * Make IC_Field stateless + * * Revision 1.5 2003/10/14 15:24:23 peiyongz * Implementation of Serialization/Deserialization * @@ -82,10 +85,10 @@ // --------------------------------------------------------------------------- // Includes // --------------------------------------------------------------------------- +#include <xercesc/validators/schema/identity/FieldActivator.hpp> #include <xercesc/validators/schema/identity/IC_Field.hpp> #include <xercesc/validators/schema/identity/ValueStore.hpp> #include <xercesc/validators/schema/identity/XercesXPath.hpp> - #include <xercesc/validators/schema/identity/IdentityConstraint.hpp> XERCES_CPP_NAMESPACE_BEGIN @@ -96,10 +99,12 @@ XERCES_CPP_NAMESPACE_BEGIN FieldMatcher::FieldMatcher(XercesXPath* const xpath, IC_Field* const aField, ValueStore* const valueStore, + FieldActivator* const fieldActivator, MemoryManager* const manager) : XPathMatcher(xpath, (IdentityConstraint*) 0, manager) , fField(aField) , fValueStore(valueStore) + , fFieldActivator(fieldActivator) { } @@ -114,12 +119,12 @@ void FieldMatcher::matched(const XMLCh* const content, fValueStore->reportNilError(fField->getIdentityConstraint()); } - fValueStore->addValue(fField, dv, content); + fValueStore->addValue(fFieldActivator, fField, dv, content); // once we've stored the value for this field, we set the mayMatch // member to false so that, in the same scope, we don't match any more // values (and throw an error instead). - fField->setMayMatch(false); + fFieldActivator->setMayMatch(fField, false); } // --------------------------------------------------------------------------- @@ -157,7 +162,14 @@ bool IC_Field::operator!= (const IC_Field& other) const { XPathMatcher* IC_Field::createMatcher(ValueStore* const valueStore, MemoryManager* const manager) { - return new (manager) FieldMatcher(fXPath, this, valueStore, manager); + return 0; +} + +XPathMatcher* IC_Field::createMatcher(FieldActivator* const fieldActivator, + ValueStore* const valueStore, + MemoryManager* const manager) +{ + return new (manager) FieldMatcher(fXPath, this, valueStore, fieldActivator, manager); } /*** @@ -171,14 +183,12 @@ void IC_Field::serialize(XSerializeEngine& serEng) if (serEng.isStoring()) { - serEng<<fMayMatch; serEng<<fXPath; IdentityConstraint::storeIC(serEng, fIdentityConstraint); } else { - serEng>>fMayMatch; serEng>>fXPath; fIdentityConstraint = IdentityConstraint::loadIC(serEng); diff --git a/src/xercesc/validators/schema/identity/IC_Field.hpp b/src/xercesc/validators/schema/identity/IC_Field.hpp index 3bced5b3b..dfbd78289 100644 --- a/src/xercesc/validators/schema/identity/IC_Field.hpp +++ b/src/xercesc/validators/schema/identity/IC_Field.hpp @@ -75,6 +75,7 @@ XERCES_CPP_NAMESPACE_BEGIN // Forward Declaration // --------------------------------------------------------------------------- class ValueStore; +class FieldActivator; class VALIDATORS_EXPORT IC_Field : public XSerializable, public XMemory @@ -93,21 +94,38 @@ public: bool operator== (const IC_Field& other) const; bool operator!= (const IC_Field& other) const; - // ----------------------------------------------------------------------- + // ----------------------------------------------------------------------- // Getter methods // ----------------------------------------------------------------------- - bool getMayMatch() const { return fMayMatch; } XercesXPath* getXPath() const { return fXPath; } IdentityConstraint* getIdentityConstraint() const { return fIdentityConstraint; } - // ----------------------------------------------------------------------- + /** + * @deprecated + */ + bool getMayMatch() const { return false; } + + // ----------------------------------------------------------------------- // Setter methods // ----------------------------------------------------------------------- - void setMayMatch(const bool other) { fMayMatch = other; } + /** + * @deprecated + */ + void setMayMatch(const bool) {} - // ----------------------------------------------------------------------- + // ----------------------------------------------------------------------- // Factory methods // ----------------------------------------------------------------------- + XPathMatcher* createMatcher + ( + FieldActivator* const fieldActivator + , ValueStore* const valueStore + , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager + ); + + /** + * @deprecated + */ XPathMatcher* createMatcher(ValueStore* const valueStore, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); @@ -128,7 +146,6 @@ private: // ----------------------------------------------------------------------- // Data members // ----------------------------------------------------------------------- - bool fMayMatch; XercesXPath* fXPath; IdentityConstraint* fIdentityConstraint; }; @@ -161,6 +178,7 @@ private: FieldMatcher(XercesXPath* const anXPath, IC_Field* const aField, ValueStore* const valueStore, + FieldActivator* const fieldActivator, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); // ----------------------------------------------------------------------- @@ -177,8 +195,9 @@ private: // ----------------------------------------------------------------------- // Data members // ----------------------------------------------------------------------- - ValueStore* fValueStore; - IC_Field* fField; + ValueStore* fValueStore; + IC_Field* fField; + FieldActivator* fFieldActivator; }; XERCES_CPP_NAMESPACE_END diff --git a/src/xercesc/validators/schema/identity/ValueStore.cpp b/src/xercesc/validators/schema/identity/ValueStore.cpp index edbfc3643..783d26400 100644 --- a/src/xercesc/validators/schema/identity/ValueStore.cpp +++ b/src/xercesc/validators/schema/identity/ValueStore.cpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.8 2003/12/16 18:41:15 knoaman + * Make IC_Field stateless + * * Revision 1.7 2003/05/18 14:02:09 knoaman * Memory manager implementation: pass per instance manager. * @@ -94,6 +97,7 @@ #include <xercesc/internal/XMLScanner.hpp> #include <xercesc/framework/XMLValidator.hpp> #include <xercesc/validators/datatype/DatatypeValidator.hpp> +#include <xercesc/validators/schema/identity/FieldActivator.hpp> #include <xercesc/validators/schema/identity/ValueStore.hpp> #include <xercesc/validators/schema/identity/IC_Field.hpp> #include <xercesc/validators/schema/identity/IC_KeyRef.hpp> @@ -132,7 +136,14 @@ void ValueStore::addValue(IC_Field* const field, DatatypeValidator* const dv, const XMLCh* const value) { - if (!field->getMayMatch() && fDoReportError) { +} + +void ValueStore::addValue(FieldActivator* const fieldActivator, + IC_Field* const field, + DatatypeValidator* const dv, + const XMLCh* const value) { + + if (!fieldActivator->getMayMatch(field) && fDoReportError) { fScanner->getValidator()->emitError(XMLValid::IC_FieldMultipleMatch); } diff --git a/src/xercesc/validators/schema/identity/ValueStore.hpp b/src/xercesc/validators/schema/identity/ValueStore.hpp index 1ba54ac62..5e4c8ff16 100644 --- a/src/xercesc/validators/schema/identity/ValueStore.hpp +++ b/src/xercesc/validators/schema/identity/ValueStore.hpp @@ -94,27 +94,36 @@ public: MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); ~ValueStore(); - // ----------------------------------------------------------------------- + // ----------------------------------------------------------------------- // Getter methods // ----------------------------------------------------------------------- IdentityConstraint* getIdentityConstraint() const; - // ----------------------------------------------------------------------- + // ----------------------------------------------------------------------- // Helper methods // ----------------------------------------------------------------------- void append(const ValueStore* const other); void startValueScope(); void endValueScope(); - void addValue(IC_Field* const field, DatatypeValidator* const dv, + void addValue(FieldActivator* const fieldActivator, + IC_Field* const field, + DatatypeValidator* const dv, const XMLCh* const value); bool contains(const FieldValueMap* const other); - // ----------------------------------------------------------------------- + /** + * @deprecated + */ + void addValue(IC_Field* const field, DatatypeValidator* const dv, + const XMLCh* const value); + + + // ----------------------------------------------------------------------- // Document handling methods // ----------------------------------------------------------------------- void endDcocumentFragment(ValueStoreCache* const valueStoreCache); - // ----------------------------------------------------------------------- + // ----------------------------------------------------------------------- // Error reporting methods // ----------------------------------------------------------------------- void duplicateValue(); -- GitLab