You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ne...@apache.org on 2003/11/10 22:54:51 UTC
cvs commit: xml-xerces/c/src/xercesc/validators/schema ComplexTypeInfo.cpp SchemaAttDefList.cpp SchemaAttDefList.hpp
neilg 2003/11/10 13:54:51
Modified: c/src/xercesc/validators/DTD DTDAttDefList.cpp
DTDAttDefList.hpp DTDElementDecl.cpp
c/src/xercesc/validators/schema ComplexTypeInfo.cpp
SchemaAttDefList.cpp SchemaAttDefList.hpp
Log:
implementation for new stateless means of traversing attribute definition lists
Revision Changes Path
1.6 +55 -2 xml-xerces/c/src/xercesc/validators/DTD/DTDAttDefList.cpp
Index: DTDAttDefList.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/DTD/DTDAttDefList.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DTDAttDefList.cpp 20 Oct 2003 11:46:28 -0000 1.5
+++ DTDAttDefList.cpp 10 Nov 2003 21:54:51 -0000 1.6
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.6 2003/11/10 21:54:51 neilg
+ * implementation for new stateless means of traversing attribute definition lists
+ *
* Revision 1.5 2003/10/20 11:46:28 gareth
* Pass in memory manager to constructors and use for creation of enumerators.
*
@@ -93,6 +96,7 @@
// ---------------------------------------------------------------------------
#include <xercesc/validators/DTD/DTDAttDefList.hpp>
#include <xercesc/internal/XTemplateSerializer.hpp>
+#include <xercesc/util/ArrayIndexOutOfBoundsException.hpp>
XERCES_CPP_NAMESPACE_BEGIN
@@ -103,13 +107,19 @@
: XMLAttDefList(manager)
,fEnum(0)
,fList(listToUse)
+,fArray(0)
+,fSize(0)
+,fCount(0)
{
fEnum = new (getMemoryManager()) RefHashTableOfEnumerator<DTDAttDef>(listToUse);
+ fArray = (DTDAttDef **)((getMemoryManager())->allocate( sizeof(DTDAttDef*) << 1));
+ fSize = 2;
}
DTDAttDefList::~DTDAttDefList()
{
delete fEnum;
+ (getMemoryManager())->deallocate(fArray);
}
@@ -173,6 +183,34 @@
fEnum->Reset();
}
+/**
+ * return total number of attributes in this list
+ */
+unsigned int DTDAttDefList::getAttDefCount() const
+{
+ return fCount;
+}
+
+/**
+ * return attribute at the index-th position in the list.
+ */
+XMLAttDef &DTDAttDefList::getAttDef(unsigned int index)
+{
+ if(index >= fCount)
+ ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::AttrList_BadIndex);
+ return *(fArray[index]);
+}
+
+/**
+ * return attribute at the index-th position in the list.
+ */
+const XMLAttDef &DTDAttDefList::getAttDef(unsigned int index) const
+{
+ if(index >= fCount)
+ ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::AttrList_BadIndex);
+ return *(fArray[index]);
+}
+
/***
* Support for Serialization/De-serialization
***/
@@ -192,6 +230,7 @@
*
***/
XTemplateSerializer::storeObject(fList, serEng);
+ serEng << fCount;
// do not serialize fEnum
}
@@ -203,11 +242,22 @@
*
***/
XTemplateSerializer::loadObject(&fList, 3, true, serEng);
-
+ // assume empty so we can size fArray just right
+ serEng >> fSize;
if (!fEnum && fList)
{
fEnum = new (getMemoryManager()) RefHashTableOfEnumerator<DTDAttDef>(fList);
}
+ if(fSize)
+ {
+ (getMemoryManager())->deallocate(fArray);
+ fArray = (DTDAttDef **)((getMemoryManager())->allocate( sizeof(DTDAttDef*) * fSize));
+ fCount = 0;
+ while(fEnum->hasMoreElements())
+ {
+ fArray[fCount++] = &fEnum->nextElement();
+ }
+ }
}
}
@@ -217,6 +267,9 @@
: XMLAttDefList(manager)
,fEnum(0)
,fList(0)
+,fArray(0)
+,fSize(0)
+,fCount(0)
{
}
1.6 +59 -1 xml-xerces/c/src/xercesc/validators/DTD/DTDAttDefList.hpp
Index: DTDAttDefList.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/DTD/DTDAttDefList.hpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DTDAttDefList.hpp 20 Oct 2003 11:46:28 -0000 1.5
+++ DTDAttDefList.hpp 10 Nov 2003 21:54:51 -0000 1.6
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.6 2003/11/10 21:54:51 neilg
+ * implementation for new stateless means of traversing attribute definition lists
+ *
* Revision 1.5 2003/10/20 11:46:28 gareth
* Pass in memory manager to constructors and use for creation of enumerators.
*
@@ -129,6 +132,10 @@
// -----------------------------------------------------------------------
// Implementation of the virtual interface
// -----------------------------------------------------------------------
+
+ /**
+ * @deprecated This method is not thread-safe.
+ */
virtual bool hasMoreElements() const;
virtual bool isEmpty() const;
virtual XMLAttDef* findAttDef
@@ -151,9 +158,32 @@
const XMLCh* const attURI
, const XMLCh* const attName
) const;
+
+ /**
+ * @deprecated This method is not thread-safe.
+ */
virtual XMLAttDef& nextElement();
+
+ /**
+ * @deprecated This method is not thread-safe.
+ */
virtual void Reset();
+ /**
+ * return total number of attributes in this list
+ */
+ virtual unsigned int getAttDefCount() const ;
+
+ /**
+ * return attribute at the index-th position in the list.
+ */
+ virtual XMLAttDef &getAttDef(unsigned int index) ;
+
+ /**
+ * return attribute at the index-th position in the list.
+ */
+ virtual const XMLAttDef &getAttDef(unsigned int index) const ;
+
/***
* Support for Serialization/De-serialization
***/
@@ -162,6 +192,9 @@
DTDAttDefList(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
private :
+
+ void addAttDef(DTDAttDef *toAdd);
+
// -----------------------------------------------------------------------
// Private data members
//
@@ -172,10 +205,35 @@
// fList
// The list of DTDAttDef objects that represent the attributes that
// a particular element supports.
+ // fArray
+ // vector of pointers to the DTDAttDef objects contained in this list
+ // fSize
+ // size of fArray
+ // fCount
+ // number of DTDAttDef objects currently stored in this list
// -----------------------------------------------------------------------
RefHashTableOfEnumerator<DTDAttDef>* fEnum;
RefHashTableOf<DTDAttDef>* fList;
+ DTDAttDef** fArray;
+ unsigned int fSize;
+ unsigned int fCount;
+
+ friend class DTDElementDecl;
};
+
+inline void DTDAttDefList::addAttDef(DTDAttDef *toAdd)
+{
+ if(fCount == fSize)
+ {
+ // need to grow fArray
+ fSize <<= 1;
+ DTDAttDef** newArray = (DTDAttDef **)((getMemoryManager())->allocate( sizeof(DTDAttDef*) * fSize ));
+ memcpy(newArray, fArray, fCount * sizeof(DTDAttDef *));
+ (getMemoryManager())->deallocate(fArray);
+ fArray = newArray;
+ }
+ fArray[fCount++] = toAdd;
+}
XERCES_CPP_NAMESPACE_END
1.12 +9 -1 xml-xerces/c/src/xercesc/validators/DTD/DTDElementDecl.cpp
Index: DTDElementDecl.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/DTD/DTDElementDecl.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- DTDElementDecl.cpp 31 Oct 2003 22:17:43 -0000 1.11
+++ DTDElementDecl.cpp 10 Nov 2003 21:54:51 -0000 1.12
@@ -165,6 +165,10 @@
);
retVal->setElemId(getId());
fAttDefs->put((void*)retVal->getFullName(), retVal);
+ // update and/or create fAttList
+ if(!fAttList)
+ ((DTDElementDecl*)this)->fAttList = new (getMemoryManager()) DTDAttDefList(fAttDefs,getMemoryManager());
+ fAttList->addAttDef(retVal);
wasAdded = true;
}
@@ -306,6 +310,10 @@
toAdd->setElemId(getId());
fAttDefs->put((void*)(toAdd->getFullName()), toAdd);
+ // update and/or create fAttList
+ if(!fAttList)
+ ((DTDElementDecl*)this)->fAttList = new (getMemoryManager()) DTDAttDefList(fAttDefs,getMemoryManager());
+ fAttList->addAttDef(toAdd);
}
1.18 +13 -2 xml-xerces/c/src/xercesc/validators/schema/ComplexTypeInfo.cpp
Index: ComplexTypeInfo.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/ComplexTypeInfo.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- ComplexTypeInfo.cpp 7 Nov 2003 17:08:12 -0000 1.17
+++ ComplexTypeInfo.cpp 10 Nov 2003 21:54:51 -0000 1.18
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.18 2003/11/10 21:54:51 neilg
+ * implementation for new stateless means of traversing attribute definition lists
+ *
* Revision 1.17 2003/11/07 17:08:12 knoaman
* For PSVI support, distinguish wildcard elements with namespace lists.
*
@@ -284,6 +287,10 @@
fAttDefs->put((void*)(toAdd->getAttName()->getLocalPart()),
toAdd->getAttName()->getURI(), toAdd);
+ // update and/or create fAttList
+ if(!fAttList)
+ ((ComplexTypeInfo*)this)->fAttList = new (fMemoryManager) SchemaAttDefList(fAttDefs,fMemoryManager);
+ fAttList->addAttDef(toAdd);
}
void ComplexTypeInfo::setContentSpec(ContentSpecNode* const toAdopt) {
@@ -378,9 +385,13 @@
retVal->setElemId(getElementId());
fAttDefs->put((void*)retVal->getAttName()->getLocalPart(), uriId, retVal);
+ // update and/or create fAttList
+ if(!fAttList)
+ ((ComplexTypeInfo*)this)->fAttList = new (fMemoryManager) SchemaAttDefList(fAttDefs,fMemoryManager);
+ fAttList->addAttDef(retVal);
wasAdded = true;
}
- else
+ else
{
wasAdded = false;
}
1.7 +55 -1 xml-xerces/c/src/xercesc/validators/schema/SchemaAttDefList.cpp
Index: SchemaAttDefList.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/SchemaAttDefList.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SchemaAttDefList.cpp 20 Oct 2003 11:46:28 -0000 1.6
+++ SchemaAttDefList.cpp 10 Nov 2003 21:54:51 -0000 1.7
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.7 2003/11/10 21:54:51 neilg
+ * implementation for new stateless means of traversing attribute definition lists
+ *
* Revision 1.6 2003/10/20 11:46:28 gareth
* Pass in memory manager to constructors and use for creation of enumerators.
*
@@ -89,6 +92,7 @@
#include <xercesc/validators/schema/SchemaAttDefList.hpp>
#include <xercesc/internal/XTemplateSerializer.hpp>
+#include <xercesc/util/ArrayIndexOutOfBoundsException.hpp>
XERCES_CPP_NAMESPACE_BEGIN
@@ -99,13 +103,19 @@
: XMLAttDefList(manager)
,fEnum(0)
,fList(listToUse)
+,fArray(0)
+,fCount(0)
+,fSize(0)
{
fEnum = new (getMemoryManager()) RefHash2KeysTableOfEnumerator<SchemaAttDef>(listToUse);
+ fArray = (SchemaAttDef **)((getMemoryManager())->allocate( sizeof(SchemaAttDef*) << 1));
+ fSize = 2;
}
SchemaAttDefList::~SchemaAttDefList()
{
delete fEnum;
+ (getMemoryManager())->deallocate(fArray);
}
@@ -171,6 +181,34 @@
fEnum->Reset();
}
+/**
+ * return total number of attributes in this list
+ */
+unsigned int SchemaAttDefList::getAttDefCount() const
+{
+ return fCount;
+}
+
+/**
+ * return attribute at the index-th position in the list.
+ */
+XMLAttDef &SchemaAttDefList::getAttDef(unsigned int index)
+{
+ if(index >= fCount)
+ ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::AttrList_BadIndex);
+ return *(fArray[index]);
+}
+
+/**
+ * return attribute at the index-th position in the list.
+ */
+const XMLAttDef &SchemaAttDefList::getAttDef(unsigned int index) const
+{
+ if(index >= fCount)
+ ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::AttrList_BadIndex);
+ return *(fArray[index]);
+}
+
/***
* Support for Serialization/De-serialization
***/
@@ -190,6 +228,7 @@
*
***/
XTemplateSerializer::storeObject(fList, serEng);
+ serEng << fCount;
// do not serialize fEnum
}
@@ -202,10 +241,22 @@
***/
XTemplateSerializer::loadObject(&fList, 3, true, serEng);
+ // assume empty so we can size fArray just right
+ serEng >> fSize;
if (!fEnum && fList)
{
fEnum = new (getMemoryManager()) RefHash2KeysTableOfEnumerator<SchemaAttDef>(fList);
}
+ if(fSize)
+ {
+ (getMemoryManager())->deallocate(fArray);
+ fArray = (SchemaAttDef **)((getMemoryManager())->allocate( sizeof(SchemaAttDef*) * fSize));
+ fCount = 0;
+ while(fEnum->hasMoreElements())
+ {
+ fArray[fCount++] = &fEnum->nextElement();
+ }
+ }
}
}
@@ -213,6 +264,9 @@
SchemaAttDefList::SchemaAttDefList(MemoryManager* const manager)
:fEnum(0)
,fList(0)
+,fArray(0)
+,fCount(0)
+,fSize(0)
{
}
1.6 +58 -1 xml-xerces/c/src/xercesc/validators/schema/SchemaAttDefList.hpp
Index: SchemaAttDefList.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/SchemaAttDefList.hpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SchemaAttDefList.hpp 20 Oct 2003 11:46:28 -0000 1.5
+++ SchemaAttDefList.hpp 10 Nov 2003 21:54:51 -0000 1.6
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.6 2003/11/10 21:54:51 neilg
+ * implementation for new stateless means of traversing attribute definition lists
+ *
* Revision 1.5 2003/10/20 11:46:28 gareth
* Pass in memory manager to constructors and use for creation of enumerators.
*
@@ -119,6 +122,10 @@
// -----------------------------------------------------------------------
// Implementation of the virtual interface
// -----------------------------------------------------------------------
+
+ /**
+ * @deprecated This method is not thread-safe.
+ */
virtual bool hasMoreElements() const;
virtual bool isEmpty() const;
virtual XMLAttDef* findAttDef
@@ -141,9 +148,32 @@
const XMLCh* const attURI
, const XMLCh* const attName
) const;
+
+ /**
+ * @deprecated This method is not thread-safe.
+ */
virtual XMLAttDef& nextElement();
+
+ /**
+ * @deprecated This method is not thread-safe.
+ */
virtual void Reset();
+ /**
+ * return total number of attributes in this list
+ */
+ virtual unsigned int getAttDefCount() const ;
+
+ /**
+ * return attribute at the index-th position in the list.
+ */
+ virtual XMLAttDef &getAttDef(unsigned int index) ;
+
+ /**
+ * return attribute at the index-th position in the list.
+ */
+ virtual const XMLAttDef &getAttDef(unsigned int index) const ;
+
/***
* Support for Serialization/De-serialization
***/
@@ -152,6 +182,8 @@
SchemaAttDefList(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
private :
+ void addAttDef(SchemaAttDef *toAdd);
+
// -----------------------------------------------------------------------
// Private data members
//
@@ -162,10 +194,35 @@
// fList
// The list of SchemaAttDef objects that represent the attributes that
// a particular element supports.
+ // fArray
+ // vector of pointers to the DTDAttDef objects contained in this list
+ // fSize
+ // size of fArray
+ // fCount
+ // number of DTDAttDef objects currently stored in this list
// -----------------------------------------------------------------------
RefHash2KeysTableOfEnumerator<SchemaAttDef>* fEnum;
RefHash2KeysTableOf<SchemaAttDef>* fList;
+ SchemaAttDef** fArray;
+ unsigned int fSize;
+ unsigned int fCount;
+
+ friend class ComplexTypeInfo;
};
+
+inline void SchemaAttDefList::addAttDef(SchemaAttDef *toAdd)
+{
+ if(fCount == fSize)
+ {
+ // need to grow fArray
+ fSize <<= 1;
+ SchemaAttDef** newArray = (SchemaAttDef **)((getMemoryManager())->allocate( sizeof(SchemaAttDef*) * fSize ));
+ memcpy(newArray, fArray, fCount * sizeof(SchemaAttDef *));
+ (getMemoryManager())->deallocate(fArray);
+ fArray = newArray;
+ }
+ fArray[fCount++] = toAdd;
+}
XERCES_CPP_NAMESPACE_END
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org