mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
Integration of OCCT 6.5.0 from SVN
This commit is contained in:
44
src/LDOM/FILES
Executable file
44
src/LDOM/FILES
Executable file
@@ -0,0 +1,44 @@
|
||||
LDOM_DeclareSequence.hxx
|
||||
LDOM_Attr.cxx
|
||||
LDOM_Attr.hxx
|
||||
LDOM_BasicAttribute.cxx
|
||||
LDOM_BasicAttribute.hxx
|
||||
LDOM_BasicElement.cxx
|
||||
LDOM_BasicElement.hxx
|
||||
LDOM_BasicNode.cxx
|
||||
LDOM_BasicNode.hxx
|
||||
LDOM_BasicText.cxx
|
||||
LDOM_BasicText.hxx
|
||||
LDOM_CDATASection.hxx
|
||||
LDOM_CharReference.hxx
|
||||
LDOM_CharReference.cxx
|
||||
LDOM_CharacterData.cxx
|
||||
LDOM_CharacterData.hxx
|
||||
LDOM_Comment.hxx
|
||||
LDOM_Document.cxx
|
||||
LDOM_Document.hxx
|
||||
LDOM_DocumentType.hxx
|
||||
LDOM_Element.cxx
|
||||
LDOM_Element.hxx
|
||||
LDOM_LDOMImplementation.cxx
|
||||
LDOM_LDOMImplementation.hxx
|
||||
LDOM_MemManager.cxx
|
||||
LDOM_MemManager.hxx
|
||||
LDOM_Node.cxx
|
||||
LDOM_Node.hxx
|
||||
LDOM_NodeList.cxx
|
||||
LDOM_NodeList.hxx
|
||||
LDOM_Text.hxx
|
||||
LDOM_XmlReader.cxx
|
||||
LDOM_XmlReader.hxx
|
||||
LDOM_XmlWriter.cxx
|
||||
LDOM_XmlWriter.hxx
|
||||
LDOMBasicString.cxx
|
||||
LDOMBasicString.hxx
|
||||
LDOMParser.cxx
|
||||
LDOMParser.hxx
|
||||
LDOMString.cxx
|
||||
LDOMString.hxx
|
||||
LDOM_OSStream.cxx
|
||||
LDOM_OSStream.hxx
|
||||
Handle_LDOM_MemManager.hxx
|
18
src/LDOM/Handle_LDOM_MemManager.hxx
Executable file
18
src/LDOM/Handle_LDOM_MemManager.hxx
Executable file
@@ -0,0 +1,18 @@
|
||||
// File: Handle_LDOM_MemManager.hxx
|
||||
// Created: 12.02.02 15:53:26
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: Open Cascade 2001
|
||||
|
||||
|
||||
#ifndef Handle_LDOM_MemManager_HeaderFile
|
||||
#define Handle_LDOM_MemManager_HeaderFile
|
||||
|
||||
#include <MMgt_TShared.hxx>
|
||||
#include <Standard_DefineHandle.hxx>
|
||||
|
||||
class LDOM_MemManager;
|
||||
|
||||
// Define handle class for LDOM_MemManager
|
||||
DEFINE_STANDARD_HANDLE (LDOM_MemManager, MMgt_TShared)
|
||||
|
||||
#endif
|
353
src/LDOM/LDOMBasicString.cxx
Executable file
353
src/LDOM/LDOMBasicString.cxx
Executable file
@@ -0,0 +1,353 @@
|
||||
// File: LDOMBasicString.cxx
|
||||
// Created: 26.06.01 16:52:43
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
// History:
|
||||
|
||||
|
||||
#include <LDOMBasicString.hxx>
|
||||
#include <LDOM_MemManager.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
#include <TCollection_ExtendedString.hxx>
|
||||
#include <errno.h>
|
||||
|
||||
//=======================================================================
|
||||
//function : LDOMString
|
||||
//purpose : Create a free string (not connected to any type of container)
|
||||
//=======================================================================
|
||||
|
||||
LDOMBasicString::LDOMBasicString (const char * aValue)
|
||||
{
|
||||
if (aValue == NULL /*|| aValue[0] == '\0'*/) {
|
||||
myType = LDOM_NULL;
|
||||
myVal.ptr = NULL;
|
||||
} else {
|
||||
myType = LDOM_AsciiFree;
|
||||
Standard_Integer aLen = strlen (aValue) + 1;
|
||||
myVal.ptr = new char [aLen];
|
||||
memcpy (myVal.ptr, aValue, aLen);
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : LDOMString
|
||||
//purpose : Create an Ascii string managed by LDOM_Document
|
||||
//=======================================================================
|
||||
|
||||
LDOMBasicString::LDOMBasicString (const char * aValue,
|
||||
const Handle(LDOM_MemManager)& aDoc)
|
||||
{
|
||||
if (aValue == NULL /*|| aValue[0] == '\0'*/) {
|
||||
myType = LDOM_NULL;
|
||||
myVal.ptr = NULL;
|
||||
} else {
|
||||
myType = LDOM_AsciiDoc;
|
||||
Standard_Integer aLen = strlen (aValue) + 1;
|
||||
myVal.ptr = aDoc -> Allocate (aLen);
|
||||
memcpy (myVal.ptr, aValue, aLen);
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : LDOMString
|
||||
//purpose : Create an Ascii string managed by LDOM_Document
|
||||
//=======================================================================
|
||||
|
||||
LDOMBasicString::LDOMBasicString (const char * aValue,
|
||||
const Standard_Integer aLen,
|
||||
const Handle(LDOM_MemManager)& aDoc)
|
||||
{
|
||||
if (aValue == NULL || aLen == 0) {
|
||||
myType = LDOM_NULL;
|
||||
myVal.ptr = NULL;
|
||||
} else {
|
||||
myType = LDOM_AsciiDoc;
|
||||
myVal.ptr = aDoc -> Allocate (aLen + 1);
|
||||
memcpy (myVal.ptr, aValue, aLen);
|
||||
((char *)myVal.ptr)[aLen] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : LDOMBasicString
|
||||
//purpose : Copy constructor
|
||||
//=======================================================================
|
||||
|
||||
LDOMBasicString::LDOMBasicString (const LDOMBasicString& anOther)
|
||||
: myType (anOther.Type())
|
||||
{
|
||||
switch (myType) {
|
||||
case LDOM_AsciiFree:
|
||||
if (anOther.myVal.ptr) {
|
||||
Standard_Integer aLen = strlen ((const char *)anOther.myVal.ptr) + 1;
|
||||
myVal.ptr = new char [aLen];
|
||||
memcpy (myVal.ptr, anOther.myVal.ptr, aLen);
|
||||
break;
|
||||
}
|
||||
case LDOM_AsciiDoc:
|
||||
case LDOM_AsciiDocClear:
|
||||
case LDOM_AsciiHashed:
|
||||
myVal.ptr = anOther.myVal.ptr;
|
||||
break;
|
||||
case LDOM_Integer:
|
||||
myVal.i = anOther.myVal.i;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ~LDOMString()
|
||||
//purpose : Destructor
|
||||
//=======================================================================
|
||||
|
||||
LDOMBasicString::~LDOMBasicString ()
|
||||
{
|
||||
if (myType == LDOM_AsciiFree) {
|
||||
if (myVal.ptr)
|
||||
delete [] (char *) myVal.ptr;
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator =
|
||||
//purpose : Assignment to NULL
|
||||
//=======================================================================
|
||||
|
||||
LDOMBasicString& LDOMBasicString::operator = (const LDOM_NullPtr *)
|
||||
{
|
||||
if (myType == LDOM_AsciiFree && myVal.ptr)
|
||||
delete [] (char *) myVal.ptr;
|
||||
myType = LDOM_NULL;
|
||||
myVal.ptr = NULL;
|
||||
return * this;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator =
|
||||
//purpose : Assignment
|
||||
//=======================================================================
|
||||
|
||||
LDOMBasicString& LDOMBasicString::operator = (const LDOMBasicString& anOther)
|
||||
{
|
||||
if (myType == LDOM_AsciiFree && myVal.ptr)
|
||||
delete [] (char *) myVal.ptr;
|
||||
myType = anOther.Type();
|
||||
switch (myType) {
|
||||
case LDOM_AsciiFree:
|
||||
if (anOther.myVal.ptr) {
|
||||
Standard_Integer aLen = strlen ((const char *)anOther.myVal.ptr) + 1;
|
||||
myVal.ptr = new char [aLen];
|
||||
memcpy (myVal.ptr, anOther.myVal.ptr, aLen);
|
||||
break;
|
||||
}
|
||||
case LDOM_AsciiDoc:
|
||||
case LDOM_AsciiDocClear:
|
||||
case LDOM_AsciiHashed:
|
||||
myVal.ptr = anOther.myVal.ptr;
|
||||
break;
|
||||
case LDOM_Integer:
|
||||
myVal.i = anOther.myVal.i;
|
||||
default: ;
|
||||
}
|
||||
return * this;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : equals
|
||||
//purpose : Compare two strings by content
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean LDOMBasicString::equals (const LDOMBasicString& anOther) const
|
||||
{
|
||||
Standard_Boolean aResult = Standard_False;
|
||||
switch (myType)
|
||||
{
|
||||
case LDOM_NULL:
|
||||
return (anOther == NULL);
|
||||
case LDOM_Integer:
|
||||
switch (anOther.Type())
|
||||
{
|
||||
case LDOM_Integer:
|
||||
return (myVal.i == anOther.myVal.i);
|
||||
case LDOM_AsciiFree:
|
||||
case LDOM_AsciiDoc:
|
||||
case LDOM_AsciiDocClear:
|
||||
case LDOM_AsciiHashed:
|
||||
{
|
||||
long aLongOther = strtol ((const char *) anOther.myVal.ptr, NULL, 10);
|
||||
return (errno == 0 && aLongOther == long(myVal.i));
|
||||
}
|
||||
case LDOM_NULL:
|
||||
default:
|
||||
;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
switch (anOther.Type())
|
||||
{
|
||||
case LDOM_Integer:
|
||||
{
|
||||
long aLong = strtol ((const char *) myVal.ptr, NULL, 10);
|
||||
return (errno == 0 && aLong == long(anOther.myVal.i));
|
||||
}
|
||||
case LDOM_AsciiFree:
|
||||
case LDOM_AsciiDoc:
|
||||
case LDOM_AsciiDocClear:
|
||||
case LDOM_AsciiHashed:
|
||||
return (strcmp ((const char *) myVal.ptr,
|
||||
(const char *) anOther.myVal.ptr) == 0);
|
||||
case LDOM_NULL:
|
||||
default:
|
||||
;
|
||||
}
|
||||
}
|
||||
return aResult;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator TCollection_AsciiString
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOMBasicString::operator TCollection_AsciiString () const
|
||||
{
|
||||
switch (myType) {
|
||||
case LDOM_Integer:
|
||||
return TCollection_AsciiString (myVal.i);
|
||||
case LDOM_AsciiFree:
|
||||
case LDOM_AsciiDoc:
|
||||
case LDOM_AsciiDocClear:
|
||||
case LDOM_AsciiHashed:
|
||||
return TCollection_AsciiString (Standard_CString(myVal.ptr));
|
||||
default: ;
|
||||
}
|
||||
return TCollection_AsciiString ();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator TCollection_ExtendedString
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOMBasicString::operator TCollection_ExtendedString () const
|
||||
{
|
||||
switch (myType) {
|
||||
case LDOM_Integer:
|
||||
return TCollection_ExtendedString (myVal.i);
|
||||
case LDOM_AsciiFree:
|
||||
case LDOM_AsciiDoc:
|
||||
case LDOM_AsciiDocClear:
|
||||
case LDOM_AsciiHashed:
|
||||
{
|
||||
char buf[6] = {'\0','\0','\0','\0','\0','\0'};
|
||||
const long aUnicodeHeader = 0xfeff;
|
||||
Standard_CString ptr = Standard_CString (myVal.ptr);
|
||||
errno = 0;
|
||||
// Check if ptr is ascii string
|
||||
if (ptr[0] != '#' || ptr[1] != '#')
|
||||
return TCollection_ExtendedString (ptr);
|
||||
buf[0] = ptr[2];
|
||||
buf[1] = ptr[3];
|
||||
buf[2] = ptr[4];
|
||||
buf[3] = ptr[5];
|
||||
if (strtol (&buf[0], NULL, 16) != aUnicodeHeader)
|
||||
return TCollection_ExtendedString (ptr);
|
||||
|
||||
// convert Unicode to Extended String
|
||||
ptr += 2;
|
||||
Standard_Integer aLength = (strlen(ptr) / 4), j = 0;
|
||||
Standard_ExtCharacter * aResult = new Standard_ExtCharacter[aLength--];
|
||||
while (aLength--) {
|
||||
ptr += 4;
|
||||
buf[0] = ptr[0];
|
||||
buf[1] = ptr[1];
|
||||
buf[2] = ptr[2];
|
||||
buf[3] = ptr[3];
|
||||
aResult[j++] = Standard_ExtCharacter (strtol (&buf[0], NULL, 16));
|
||||
if (errno) {
|
||||
delete [] aResult;
|
||||
return TCollection_ExtendedString();
|
||||
}
|
||||
}
|
||||
aResult[j] = 0;
|
||||
TCollection_ExtendedString aResultStr (aResult);
|
||||
delete [] aResult;
|
||||
return aResultStr;
|
||||
}
|
||||
default: ;
|
||||
}
|
||||
return TCollection_ExtendedString();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetInteger
|
||||
//purpose : Conversion to Integer
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean LDOMBasicString::GetInteger (Standard_Integer& aResult) const
|
||||
{
|
||||
switch (myType) {
|
||||
case LDOM_Integer:
|
||||
aResult = myVal.i;
|
||||
break;
|
||||
case LDOM_AsciiFree:
|
||||
case LDOM_AsciiDoc:
|
||||
case LDOM_AsciiDocClear:
|
||||
case LDOM_AsciiHashed:
|
||||
{
|
||||
char * ptr;
|
||||
long aValue = strtol ((const char *)myVal.ptr, &ptr, 10);
|
||||
if (ptr == myVal.ptr || errno == ERANGE || errno == EINVAL)
|
||||
return Standard_False;
|
||||
aResult = Standard_Integer (aValue);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return Standard_False;
|
||||
}
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
#ifdef DEB
|
||||
#ifndef WNT
|
||||
//=======================================================================
|
||||
// Debug Function for DBX: use "print -p <Variable> or pp <Variable>"
|
||||
//=======================================================================
|
||||
#include <LDOM_OSStream.hxx>
|
||||
#define FLITERAL 0x10
|
||||
char * db_pretty_print (const LDOMBasicString * aString, int fl, char *)
|
||||
{
|
||||
LDOM_OSStream out (128);
|
||||
const char * str;
|
||||
switch (aString -> myType) {
|
||||
case LDOMBasicString::LDOM_Integer:
|
||||
if ((fl & FLITERAL) == 0) out << "LDOM_Integer: ";
|
||||
out << '\"' << aString -> myVal.i << '\"'; goto finis;
|
||||
case LDOMBasicString::LDOM_AsciiFree:
|
||||
if ((fl & FLITERAL) == 0) out << "LDOM_AsciiFree: ";
|
||||
break;
|
||||
case LDOMBasicString::LDOM_AsciiDoc:
|
||||
if ((fl & FLITERAL) == 0) out << "LDOM_AsciiDoc: ";
|
||||
break;
|
||||
case LDOMBasicString::LDOM_AsciiDocClear:
|
||||
if ((fl & FLITERAL) == 0) out << "LDOM_AsciiDocClear: ";
|
||||
break;
|
||||
case LDOMBasicString::LDOM_AsciiHashed:
|
||||
if ((fl & FLITERAL) == 0) out << "LDOM_AsciiHashed: ";
|
||||
break;
|
||||
default:
|
||||
out << "Unknown type";
|
||||
}
|
||||
str = (const char *) aString -> myVal.ptr;
|
||||
out << '\"';
|
||||
if (strlen (str) > 512)
|
||||
out.rdbuf() -> sputn (str, 512);
|
||||
else
|
||||
out << str;
|
||||
out << '\"';
|
||||
finis:
|
||||
out << ends;
|
||||
return (char *)out.str();
|
||||
}
|
||||
#endif
|
||||
#endif
|
125
src/LDOM/LDOMBasicString.hxx
Executable file
125
src/LDOM/LDOMBasicString.hxx
Executable file
@@ -0,0 +1,125 @@
|
||||
// File: LDOMBasicString.hxx
|
||||
// Created: 26.06.01 16:41:14
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
|
||||
|
||||
#ifndef LDOMBasicString_HeaderFile
|
||||
#define LDOMBasicString_HeaderFile
|
||||
|
||||
#include <Standard_Type.hxx>
|
||||
#include <Standard_Macro.hxx>
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
#include <TCollection_ExtendedString.hxx>
|
||||
|
||||
class Handle(LDOM_MemManager);
|
||||
class LDOM_NullPtr;
|
||||
class TCollection_AsciiString;
|
||||
class TCollection_ExtendedString;
|
||||
|
||||
// Block of comments describing class LDOMBasicString
|
||||
//
|
||||
|
||||
class LDOMBasicString
|
||||
{
|
||||
friend class LDOM_MemManager;
|
||||
friend class LDOM_Node;
|
||||
public:
|
||||
enum StringType {
|
||||
LDOM_NULL = 0,
|
||||
LDOM_Integer,
|
||||
// LDOM_Real,
|
||||
LDOM_AsciiFree, // String not connected to any container
|
||||
LDOM_AsciiDoc, // String connected to LDOM_Document (container)
|
||||
LDOM_AsciiDocClear, // --"--"--, consists of only XML-valid chars
|
||||
LDOM_AsciiHashed // String connected to hash table
|
||||
};
|
||||
|
||||
Standard_EXPORT ~LDOMBasicString ();
|
||||
|
||||
StringType Type () const { return myType; }
|
||||
|
||||
Standard_EXPORT Standard_Boolean
|
||||
GetInteger (Standard_Integer& aResult) const;
|
||||
// Conversion to Integer (only for LDOM_Integer)
|
||||
|
||||
const char *
|
||||
GetString () const { return myType == LDOM_Integer ||
|
||||
myType == LDOM_NULL ?
|
||||
"" : (const char *) myVal.ptr; }
|
||||
// Conversion to char * (only for LDOM_Ascii*)
|
||||
|
||||
Standard_EXPORT Standard_Boolean
|
||||
equals (const LDOMBasicString& anOther) const;
|
||||
// Compare two strings by content
|
||||
|
||||
Standard_EXPORT LDOMBasicString&
|
||||
operator = (const LDOM_NullPtr *);
|
||||
|
||||
Standard_EXPORT LDOMBasicString&
|
||||
operator = (const LDOMBasicString& anOther);
|
||||
|
||||
Standard_Boolean
|
||||
operator == (const LDOM_NullPtr *) const
|
||||
{ return myType==LDOM_NULL; }
|
||||
Standard_Boolean
|
||||
operator != (const LDOM_NullPtr *) const
|
||||
{ return myType!=LDOM_NULL; }
|
||||
|
||||
Standard_Boolean
|
||||
operator == (const LDOMBasicString& anOther) const
|
||||
{
|
||||
return myType==anOther.myType && myVal.i==anOther.myVal.i;
|
||||
}
|
||||
|
||||
Standard_Boolean
|
||||
operator != (const LDOMBasicString& anOther) const
|
||||
{
|
||||
return myType!=anOther.myType || myVal.i!=anOther.myVal.i;
|
||||
}
|
||||
|
||||
// AGV auxiliary API
|
||||
Standard_EXPORT operator TCollection_AsciiString () const;
|
||||
|
||||
Standard_EXPORT operator TCollection_ExtendedString () const;
|
||||
|
||||
LDOMBasicString ()
|
||||
: myType (LDOM_NULL) { myVal.ptr = NULL; }
|
||||
// Empty constructor
|
||||
|
||||
Standard_EXPORT LDOMBasicString (const LDOMBasicString& anOther);
|
||||
// Copy constructor
|
||||
|
||||
LDOMBasicString (const Standard_Integer aValue)
|
||||
: myType (LDOM_Integer) { myVal.i = aValue; }
|
||||
|
||||
Standard_EXPORT LDOMBasicString (const char * aValue);
|
||||
// Create LDOM_AsciiFree
|
||||
|
||||
Standard_EXPORT LDOMBasicString (const char * aValue,
|
||||
const Handle(LDOM_MemManager)& aDoc);
|
||||
// Create LDOM_AsciiDoc
|
||||
|
||||
Standard_EXPORT LDOMBasicString (const char * aValue,
|
||||
const Standard_Integer aLen,
|
||||
const Handle(LDOM_MemManager)& aDoc);
|
||||
// Create LDOM_AsciiDoc
|
||||
|
||||
protected:
|
||||
// ---------- PROTECTED METHODS ----------
|
||||
void SetDirect (const StringType aType, const char * aValue)
|
||||
{ myType = aType; myVal.ptr = (void *) aValue; }
|
||||
|
||||
|
||||
protected:
|
||||
// ---------- PROTECTED FIELDS ----------
|
||||
|
||||
StringType myType;
|
||||
union {
|
||||
int i;
|
||||
void * ptr;
|
||||
} myVal;
|
||||
friend char * db_pretty_print (const LDOMBasicString *, int, char *);
|
||||
};
|
||||
|
||||
#endif
|
366
src/LDOM/LDOMParser.cxx
Executable file
366
src/LDOM/LDOMParser.cxx
Executable file
@@ -0,0 +1,366 @@
|
||||
// File: LDOMParser.cxx
|
||||
// Created: 20.07.01 14:58:24
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
// History: AGV 060302: Input from istream
|
||||
// AGV 130302: Return error if there are data after the root element
|
||||
|
||||
//#define LDOM_PARSER_TRACE
|
||||
|
||||
#include <LDOMParser.hxx>
|
||||
#include <LDOM_MemManager.hxx>
|
||||
#include <LDOM_XmlReader.hxx>
|
||||
#include <LDOM_BasicText.hxx>
|
||||
#include <LDOM_CharReference.hxx>
|
||||
|
||||
#include <fcntl.h>
|
||||
#ifdef WNT
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
//=======================================================================
|
||||
//function : ~LDOMParser
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOMParser::~LDOMParser()
|
||||
{
|
||||
if (myReader) delete myReader;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ReadRecord
|
||||
//purpose : Take the next lexical element from XML stream
|
||||
//=======================================================================
|
||||
|
||||
#ifdef LDOM_PARSER_TRACE
|
||||
static
|
||||
#else
|
||||
inline
|
||||
#endif
|
||||
LDOM_XmlReader::RecordType ReadRecord (LDOM_XmlReader& aReader,
|
||||
LDOM_OSStream& aData)
|
||||
{
|
||||
#ifdef LDOM_PARSER_TRACE
|
||||
static aCounter = 0;
|
||||
++ aCounter;
|
||||
#endif
|
||||
const LDOM_XmlReader::RecordType aType = aReader.ReadRecord (aData);
|
||||
#ifdef LDOM_PARSER_TRACE
|
||||
static FILE * ff = NULL;
|
||||
TCollection_AsciiString aTraceFileName;
|
||||
#ifdef WNT
|
||||
aTraceFileName = TCollection_AsciiString (getenv("TEMP")) + "\\ldom.trace";
|
||||
#else
|
||||
aTraceFileName = "/tmp/ldom.trace";
|
||||
#endif
|
||||
ff = fopen (aTraceFileName.ToCString(),ff ? "at": "wt");
|
||||
const char * aDataType;
|
||||
switch (aType) {
|
||||
case LDOM_XmlReader::XML_UNKNOWN: aDataType= "XML_UNKNOWN "; break;
|
||||
case LDOM_XmlReader::XML_HEADER: aDataType= "XML_HEADER "; break;
|
||||
case LDOM_XmlReader::XML_DOCTYPE: aDataType= "XML_DOCTYPE "; break;
|
||||
case LDOM_XmlReader::XML_COMMENT: aDataType= "XML_COMMENT "; break;
|
||||
case LDOM_XmlReader::XML_START_ELEMENT: aDataType= "XML_START_ELEMENT"; break;
|
||||
case LDOM_XmlReader::XML_END_ELEMENT: aDataType= "XML_END_ELEMENT "; break;
|
||||
case LDOM_XmlReader::XML_FULL_ELEMENT: aDataType= "XML_FULL_ELEMENT "; break;
|
||||
case LDOM_XmlReader::XML_TEXT: aDataType= "XML_TEXT "; break;
|
||||
case LDOM_XmlReader::XML_CDATA: aDataType= "XML_CDATA "; break;
|
||||
case LDOM_XmlReader::XML_EOF: aDataType= "XML_EOF ";
|
||||
}
|
||||
char * aStr = aData.str();
|
||||
fprintf (ff, "%5d %s: %s\n", aCounter, aDataType, aStr);
|
||||
delete [] aStr;
|
||||
fclose (ff);
|
||||
#endif
|
||||
return aType;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetError
|
||||
//purpose : Return text describing a parsing error
|
||||
//=======================================================================
|
||||
|
||||
const TCollection_AsciiString& LDOMParser::GetError
|
||||
(TCollection_AsciiString& aData) const
|
||||
{
|
||||
char * aStr =(char *)myCurrentData.str();
|
||||
aData = aStr;
|
||||
delete [] aStr;
|
||||
return myError;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : parse
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean LDOMParser::parse (istream& anInput)
|
||||
{
|
||||
// Open the DOM Document
|
||||
myDocument = new LDOM_MemManager (20000);
|
||||
myError.Clear();
|
||||
|
||||
// Create the Reader instance
|
||||
if (myReader) delete myReader;
|
||||
myReader = new LDOM_XmlReader (anInput, myDocument, myError);
|
||||
|
||||
// Parse
|
||||
return ParseDocument();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : parse
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean LDOMParser::parse (const char * const aFileName)
|
||||
{
|
||||
// Open the DOM Document
|
||||
myDocument = new LDOM_MemManager (20000);
|
||||
myError.Clear ();
|
||||
|
||||
// Open the file
|
||||
int aFile = open (aFileName, O_RDONLY);
|
||||
if (aFile < 0) {
|
||||
myError = "Fatal XML error: Cannot open XML file";
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
// Create the Reader instance
|
||||
if (myReader) delete myReader;
|
||||
myReader = new LDOM_XmlReader (aFile, myDocument, myError);
|
||||
|
||||
// Parse
|
||||
Standard_Boolean isError = ParseDocument();
|
||||
close (aFile);
|
||||
return isError;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ParseDocument
|
||||
//purpose : parse the whole document (abstracted from the XML source)
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean LDOMParser::ParseDocument ()
|
||||
{
|
||||
Standard_Boolean isError = Standard_False;
|
||||
Standard_Boolean isElement = Standard_False;
|
||||
Standard_Boolean isHeader = Standard_False;
|
||||
Standard_Boolean isDoctype = Standard_False;
|
||||
|
||||
while (1) {
|
||||
LDOM_XmlReader::RecordType aType = ReadRecord (*myReader, myCurrentData);
|
||||
switch (aType) {
|
||||
case LDOM_XmlReader::XML_HEADER:
|
||||
if (isDoctype || isElement) {
|
||||
myError = "Unexpected XML declaration";
|
||||
isError = Standard_True;
|
||||
break;
|
||||
}
|
||||
isHeader = Standard_True;
|
||||
continue;
|
||||
case LDOM_XmlReader::XML_DOCTYPE:
|
||||
if (isElement) {
|
||||
myError = "Unexpected DOCTYPE declaration";
|
||||
isError = Standard_True;
|
||||
break;
|
||||
}
|
||||
isDoctype = Standard_True;
|
||||
case LDOM_XmlReader::XML_COMMENT:
|
||||
continue;
|
||||
case LDOM_XmlReader::XML_FULL_ELEMENT:
|
||||
if (isElement == Standard_False) {
|
||||
isElement = Standard_True;
|
||||
myDocument -> myRootElement = &myReader -> GetElement ();
|
||||
if (startElement()) {
|
||||
isError = Standard_True;
|
||||
myError = "User abort at startElement()";
|
||||
break;
|
||||
}
|
||||
if (endElement()) {
|
||||
isError = Standard_True;
|
||||
myError = "User abort at endElement()";
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
case LDOM_XmlReader::XML_START_ELEMENT:
|
||||
if (isElement == Standard_False) {
|
||||
isElement = Standard_True;
|
||||
myDocument -> myRootElement = &myReader -> GetElement ();
|
||||
if (startElement()) {
|
||||
isError = Standard_True;
|
||||
myError = "User abort at startElement()";
|
||||
break;
|
||||
}
|
||||
isError = ParseElement ();
|
||||
if (isError) break;
|
||||
continue;
|
||||
}
|
||||
isError = Standard_True;
|
||||
myError = "Expected comment or end-of-file";
|
||||
case LDOM_XmlReader::XML_END_ELEMENT:
|
||||
if (endElement()) {
|
||||
isError = Standard_True;
|
||||
myError = "User abort at endElement()";
|
||||
}
|
||||
case LDOM_XmlReader::XML_EOF:
|
||||
break;
|
||||
case LDOM_XmlReader::XML_UNKNOWN:
|
||||
if (isElement) {
|
||||
default:
|
||||
myError = "Unexpected data beyond the Document Element";
|
||||
}
|
||||
isError = Standard_True;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return isError;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ParseElement
|
||||
//purpose : parse one element, given the type of its XML presentation
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean LDOMParser::ParseElement ()
|
||||
{
|
||||
Standard_Boolean isError = Standard_False;
|
||||
const LDOM_BasicElement * aParent = &myReader->GetElement();
|
||||
const LDOM_BasicNode * aLastChild = NULL;
|
||||
while (1) {
|
||||
LDOM_Node::NodeType aLocType;
|
||||
LDOMBasicString aTextValue;
|
||||
char *aTextStr;
|
||||
LDOM_XmlReader::RecordType aType = ReadRecord (* myReader, myCurrentData);
|
||||
switch (aType) {
|
||||
case LDOM_XmlReader::XML_UNKNOWN:
|
||||
isError = Standard_True;
|
||||
break;
|
||||
case LDOM_XmlReader::XML_FULL_ELEMENT:
|
||||
aParent -> AppendChild (&myReader -> GetElement(), aLastChild);
|
||||
if (startElement()) {
|
||||
isError = Standard_True;
|
||||
myError = "User abort at startElement()";
|
||||
break;
|
||||
}
|
||||
if (endElement()) {
|
||||
isError = Standard_True;
|
||||
myError = "User abort at endElement()";
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case LDOM_XmlReader::XML_START_ELEMENT:
|
||||
aParent -> AppendChild (&myReader -> GetElement(), aLastChild);
|
||||
if (startElement()) {
|
||||
isError = Standard_True;
|
||||
myError = "User abort at startElement()";
|
||||
break;
|
||||
}
|
||||
isError = ParseElement ();
|
||||
break;
|
||||
case LDOM_XmlReader::XML_END_ELEMENT:
|
||||
{
|
||||
Standard_CString aParentName = Standard_CString(aParent->GetTagName());
|
||||
aTextStr = (char *)myCurrentData.str();
|
||||
if (strcmp(aTextStr, aParentName) != 0) {
|
||||
myError = "Expected end tag \'";
|
||||
myError += aParentName;
|
||||
myError += "\'";
|
||||
isError = Standard_True;
|
||||
}
|
||||
else if (endElement()) {
|
||||
isError = Standard_True;
|
||||
myError = "User abort at endElement()";
|
||||
}
|
||||
delete [] aTextStr;
|
||||
}
|
||||
return isError;
|
||||
case LDOM_XmlReader::XML_TEXT:
|
||||
aLocType = LDOM_Node::TEXT_NODE;
|
||||
{
|
||||
Standard_Integer aTextLen;
|
||||
aTextStr = LDOM_CharReference::Decode ((char *)myCurrentData.str(), aTextLen);
|
||||
// try to convert to integer
|
||||
if (IsDigit(aTextStr[0])) {
|
||||
if (LDOM_XmlReader::getInteger (aTextValue, aTextStr,
|
||||
aTextStr + aTextLen))
|
||||
aTextValue = LDOMBasicString (aTextStr, aTextLen, myDocument);
|
||||
} else
|
||||
aTextValue = LDOMBasicString (aTextStr, aTextLen, myDocument);
|
||||
}
|
||||
goto create_text_node;
|
||||
case LDOM_XmlReader::XML_COMMENT:
|
||||
aLocType = LDOM_Node::COMMENT_NODE;
|
||||
{
|
||||
Standard_Integer aTextLen;
|
||||
aTextStr = LDOM_CharReference::Decode ((char *)myCurrentData.str(), aTextLen);
|
||||
aTextValue = LDOMBasicString (aTextStr, aTextLen, myDocument);
|
||||
}
|
||||
goto create_text_node;
|
||||
case LDOM_XmlReader::XML_CDATA:
|
||||
aLocType = LDOM_Node::CDATA_SECTION_NODE;
|
||||
aTextStr = (char *)myCurrentData.str();
|
||||
aTextValue = LDOMBasicString(aTextStr,myCurrentData.Length(),myDocument);
|
||||
create_text_node:
|
||||
{
|
||||
LDOM_BasicNode& aTextNode =
|
||||
LDOM_BasicText::Create (aLocType, aTextValue, myDocument);
|
||||
aParent -> AppendChild (&aTextNode, aLastChild);
|
||||
}
|
||||
delete [] aTextStr;
|
||||
break;
|
||||
case LDOM_XmlReader::XML_EOF:
|
||||
myError = "Inexpected end of file";
|
||||
isError = Standard_True;
|
||||
break;
|
||||
default: ;
|
||||
}
|
||||
if (isError) break;
|
||||
}
|
||||
return isError;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : startElement
|
||||
//purpose : virtual hook on 'StartElement' event for descendant classes
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean LDOMParser::startElement ()
|
||||
{
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : endElement
|
||||
//purpose : virtual hook on 'EndElement' event for descendant classes
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean LDOMParser::endElement ()
|
||||
{
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getCurrentElement
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Element LDOMParser::getCurrentElement () const
|
||||
{
|
||||
return LDOM_Element (myReader -> GetElement(), myDocument);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getDocument
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Document LDOMParser::getDocument ()
|
||||
{
|
||||
return myDocument -> Self();
|
||||
}
|
||||
|
86
src/LDOM/LDOMParser.hxx
Executable file
86
src/LDOM/LDOMParser.hxx
Executable file
@@ -0,0 +1,86 @@
|
||||
// File: LDOMParser.hxx
|
||||
// Created: 20.07.01 12:52:47
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
// History: AGV 060302: Input from istream
|
||||
|
||||
#ifndef LDOMParser_HeaderFile
|
||||
#define LDOMParser_HeaderFile
|
||||
|
||||
#include <LDOM_Document.hxx>
|
||||
#include <LDOM_OSStream.hxx>
|
||||
|
||||
class LDOM_XmlReader;
|
||||
//class istream;
|
||||
|
||||
// Class LDOMParser
|
||||
//
|
||||
|
||||
class LDOMParser
|
||||
{
|
||||
public:
|
||||
// ---------- PUBLIC METHODS ----------
|
||||
|
||||
LDOMParser () : myReader (NULL), myCurrentData (16384) {}
|
||||
// Empty constructor
|
||||
|
||||
virtual Standard_EXPORT ~LDOMParser ();
|
||||
// Destructor
|
||||
|
||||
Standard_EXPORT LDOM_Document
|
||||
getDocument ();
|
||||
// Get the LDOM_Document
|
||||
|
||||
Standard_EXPORT Standard_Boolean
|
||||
parse (const char * const aFileName);
|
||||
// Parse a file
|
||||
// Returns True if error occurred, then GetError() can be called
|
||||
|
||||
Standard_EXPORT Standard_Boolean
|
||||
parse (istream& anInput);
|
||||
// Parse a C++ stream
|
||||
// Returns True if error occurred, then GetError() can be called
|
||||
|
||||
Standard_EXPORT const TCollection_AsciiString&
|
||||
GetError (TCollection_AsciiString& aData) const;
|
||||
// Return text describing a parsing error, or Empty if no error occurred
|
||||
|
||||
protected:
|
||||
// ---------- PROTECTED METHODS ----------
|
||||
|
||||
Standard_EXPORT virtual Standard_Boolean
|
||||
startElement ();
|
||||
// virtual hook on 'StartElement' event for descendant classes
|
||||
|
||||
Standard_EXPORT virtual Standard_Boolean
|
||||
endElement ();
|
||||
// virtual hook on 'EndElement' event for descendant classes
|
||||
|
||||
Standard_EXPORT LDOM_Element
|
||||
getCurrentElement () const;
|
||||
// to be called from startElement() and endElement()
|
||||
|
||||
private:
|
||||
// ---------- PRIVATE METHODS ----------
|
||||
Standard_Boolean ParseDocument ();
|
||||
|
||||
Standard_Boolean ParseElement ();
|
||||
|
||||
// ---------- PRIVATE (PROHIBITED) METHODS ----------
|
||||
|
||||
LDOMParser (const LDOMParser& theOther);
|
||||
// Copy constructor
|
||||
|
||||
LDOMParser& operator = (const LDOMParser& theOther);
|
||||
// Assignment
|
||||
|
||||
private:
|
||||
// ---------- PRIVATE FIELDS ----------
|
||||
|
||||
LDOM_XmlReader * myReader;
|
||||
Handle(LDOM_MemManager) myDocument;
|
||||
LDOM_OSStream myCurrentData;
|
||||
TCollection_AsciiString myError;
|
||||
};
|
||||
|
||||
#endif
|
88
src/LDOM/LDOMString.cxx
Executable file
88
src/LDOM/LDOMString.cxx
Executable file
@@ -0,0 +1,88 @@
|
||||
// File: LDOMString.cxx
|
||||
// Created: 25.06.01 15:24:17
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
// History:
|
||||
|
||||
#include <LDOMString.hxx>
|
||||
#include <LDOM_MemManager.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : CreateDirectString
|
||||
//purpose : Only for hashed strings!!
|
||||
//=======================================================================
|
||||
|
||||
LDOMString LDOMString::CreateDirectString (const char * aValue,
|
||||
const LDOM_MemManager& aDoc)
|
||||
{
|
||||
LDOMString aResult;
|
||||
aResult.myPtrDoc = &aDoc;
|
||||
aResult.SetDirect (LDOMBasicString::LDOM_AsciiHashed, aValue);
|
||||
return aResult;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : LDOMString
|
||||
//purpose : Copy from another string with allocation in the document
|
||||
//=======================================================================
|
||||
|
||||
LDOMString::LDOMString (const LDOMBasicString& anOther,
|
||||
const Handle(LDOM_MemManager)& aDoc)
|
||||
: myPtrDoc (&aDoc -> Self())
|
||||
{
|
||||
myType = anOther.Type();
|
||||
switch (myType)
|
||||
{
|
||||
case LDOM_Integer:
|
||||
anOther.GetInteger (myVal.i);
|
||||
break;
|
||||
case LDOM_AsciiFree:
|
||||
myType = LDOM_AsciiDoc;
|
||||
case LDOM_AsciiDocClear:
|
||||
case LDOM_AsciiDoc:
|
||||
{
|
||||
const char * aString = anOther.GetString ();
|
||||
Standard_Integer aLen = strlen (aString) + 1;
|
||||
myVal.ptr = ((LDOM_MemManager *) myPtrDoc) -> Allocate (aLen);
|
||||
memcpy (myVal.ptr, aString, aLen);
|
||||
}
|
||||
break;
|
||||
case LDOM_AsciiHashed:
|
||||
myVal.ptr = (void *)anOther.GetString ();
|
||||
break;
|
||||
default:
|
||||
myType = LDOM_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : LDOMString
|
||||
//purpose : Copy from another with allocation in the document if necessary
|
||||
//=======================================================================
|
||||
/*
|
||||
LDOMString::LDOMString (const LDOMString& anOther, const LDOM_Document& aDoc)
|
||||
: myPtrDoc (&aDoc.myMemManager -> Self())
|
||||
{
|
||||
switch (anOther.Type())
|
||||
{
|
||||
case LDOM_Integer:
|
||||
myType = LDOM_Integer;
|
||||
anOther.GetInteger (myVal.i);
|
||||
break;
|
||||
case LDOM_AsciiDoc:
|
||||
if (aDoc == anOther.getOwnerDocument())
|
||||
case LDOM_AsciiHashed:
|
||||
myVal.ptr = (void *)anOther.GetString ();
|
||||
else {
|
||||
case LDOM_AsciiFree:
|
||||
const char * aString = anOther.GetString ();
|
||||
Standard_Integer aLen = strlen (aString) + 1;
|
||||
myVal.ptr = aDoc.AllocMem (aLen);
|
||||
memcpy (myVal.ptr, aString, aLen);
|
||||
myType = LDOM_AsciiDoc;
|
||||
}
|
||||
break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
*/
|
82
src/LDOM/LDOMString.hxx
Executable file
82
src/LDOM/LDOMString.hxx
Executable file
@@ -0,0 +1,82 @@
|
||||
// File: LDOMString.hxx
|
||||
// Created: 25.06.01 14:37:10
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
|
||||
|
||||
#ifndef LDOMString_HeaderFile
|
||||
#define LDOMString_HeaderFile
|
||||
|
||||
#include <LDOMBasicString.hxx>
|
||||
#include <Handle_LDOM_MemManager.hxx>
|
||||
|
||||
// Class LDOMString
|
||||
// Represents various object types which can be mapped to XML strings
|
||||
//
|
||||
// LDOMString is not an independent type: you must be sure that the owner
|
||||
// LDOM_Document is never lost during the lifetime of its LDOMStrings - for
|
||||
// that it is necessary to keep at least one LDOM_Document or LDOM_Node alive
|
||||
// before all LDOMString's (LDOM_AsciiDoc type) are destroyed.
|
||||
|
||||
class LDOMString : public LDOMBasicString
|
||||
{
|
||||
public:
|
||||
// ---------- PUBLIC METHODS ----------
|
||||
|
||||
LDOMString () : myPtrDoc (NULL) {}
|
||||
// Empty constructor
|
||||
|
||||
LDOMString (const LDOMString& anOther)
|
||||
: LDOMBasicString (anOther), myPtrDoc (anOther.myPtrDoc) {}
|
||||
// Copy constructor
|
||||
|
||||
LDOMString (const Standard_Integer aValue)
|
||||
: LDOMBasicString (aValue), myPtrDoc (NULL) {}
|
||||
// Integer => LDOMString
|
||||
|
||||
// Standard_EXPORT LDOMString (const Standard_Real aValue);
|
||||
|
||||
LDOMString (const char * aValue)
|
||||
: LDOMBasicString (aValue), myPtrDoc (NULL) {}
|
||||
// Create LDOM_AsciiFree
|
||||
|
||||
const LDOM_MemManager& getOwnerDocument () const
|
||||
{ return * myPtrDoc; }
|
||||
|
||||
LDOMString& operator = (const LDOM_NullPtr * aNull)
|
||||
{ LDOMBasicString::operator= (aNull); return *this; }
|
||||
|
||||
LDOMString& operator = (const LDOMString& anOther)
|
||||
{
|
||||
myPtrDoc = anOther.myPtrDoc;
|
||||
LDOMBasicString::operator= (anOther);
|
||||
return * this;
|
||||
}
|
||||
|
||||
private:
|
||||
friend class LDOM_Document;
|
||||
friend class LDOM_Node;
|
||||
friend class LDOM_Element;
|
||||
friend class LDOM_BasicElement;
|
||||
friend class LDOM_BasicAttribute;
|
||||
friend class LDOM_BasicText;
|
||||
|
||||
static LDOMString CreateDirectString
|
||||
(const char * aValue,
|
||||
const LDOM_MemManager& aDoc);
|
||||
|
||||
LDOMString (const LDOMBasicString& anOther,
|
||||
const LDOM_MemManager& aDoc)
|
||||
: LDOMBasicString (anOther), myPtrDoc (&aDoc) {}
|
||||
// Plain copy from LDOMBasicString
|
||||
|
||||
LDOMString (const LDOMBasicString& anOther,
|
||||
const Handle(LDOM_MemManager)& aDoc);
|
||||
// Copy from another string with allocation in the document space
|
||||
|
||||
private:
|
||||
// ---------- PRIVATE FIELDS -------------
|
||||
const LDOM_MemManager * myPtrDoc;
|
||||
};
|
||||
|
||||
#endif
|
30
src/LDOM/LDOM_Attr.cxx
Executable file
30
src/LDOM/LDOM_Attr.cxx
Executable file
@@ -0,0 +1,30 @@
|
||||
// File: LDOM_Attr.cxx
|
||||
// Created: 26.06.01 19:01:10
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
// History:
|
||||
|
||||
|
||||
#include <LDOM_Attr.hxx>
|
||||
#include <LDOM_BasicAttribute.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : LDOM_Attr
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Attr::LDOM_Attr (const LDOM_BasicAttribute& anAttr,
|
||||
const Handle(LDOM_MemManager)& aDoc)
|
||||
: LDOM_Node (anAttr, aDoc) {}
|
||||
|
||||
//=======================================================================
|
||||
//function : setValue
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void LDOM_Attr::setValue (const LDOMString& aValue)
|
||||
{
|
||||
LDOM_BasicAttribute& anAttr = (LDOM_BasicAttribute&) Origin ();
|
||||
anAttr.SetValue (aValue, myDocument);
|
||||
}
|
||||
|
55
src/LDOM/LDOM_Attr.hxx
Executable file
55
src/LDOM/LDOM_Attr.hxx
Executable file
@@ -0,0 +1,55 @@
|
||||
// File: LDOM_Attr.hxx
|
||||
// Created: 26.06.01 17:36:20
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
|
||||
|
||||
#ifndef LDOM_Attr_HeaderFile
|
||||
#define LDOM_Attr_HeaderFile
|
||||
|
||||
#include <LDOM_Node.hxx>
|
||||
|
||||
class LDOM_BasicAttribute;
|
||||
class LDOM_Element;
|
||||
|
||||
// Class LDOM_Attr
|
||||
//
|
||||
|
||||
class LDOM_Attr : public LDOM_Node
|
||||
{
|
||||
public:
|
||||
// ---------- PUBLIC METHODS ----------
|
||||
|
||||
LDOM_Attr () {}
|
||||
// Empty constructor
|
||||
|
||||
LDOM_Attr (const LDOM_Attr& anOther) : LDOM_Node (anOther) {}
|
||||
// Copy constructor
|
||||
|
||||
LDOM_Attr& operator = (const LDOM_NullPtr * aNull)
|
||||
{ return (LDOM_Attr&) LDOM_Node::operator = (aNull); }
|
||||
// Nullify
|
||||
|
||||
LDOM_Attr& operator = (const LDOM_Attr& anOther)
|
||||
{ return (LDOM_Attr&) LDOM_Node::operator = (anOther); }
|
||||
// Assignment
|
||||
|
||||
LDOMString getName () const { return getNodeName (); }
|
||||
|
||||
LDOMString getValue () const { return getNodeValue(); }
|
||||
|
||||
Standard_EXPORT void setValue (const LDOMString& aValue);
|
||||
|
||||
protected:
|
||||
friend class LDOM_Element;
|
||||
// ---------- PROTECTED METHODS ----------
|
||||
|
||||
LDOM_Attr (const LDOM_BasicAttribute& anAttr,
|
||||
const Handle(LDOM_MemManager)& aDoc);
|
||||
|
||||
private:
|
||||
// ---------- PRIVATE FIELDS ----------
|
||||
|
||||
};
|
||||
|
||||
#endif
|
57
src/LDOM/LDOM_BasicAttribute.cxx
Executable file
57
src/LDOM/LDOM_BasicAttribute.cxx
Executable file
@@ -0,0 +1,57 @@
|
||||
// File: LDOM_BasicAttribute.cxx
|
||||
// Created: 26.06.01 18:48:27
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
// History:
|
||||
|
||||
#include <LDOM_BasicAttribute.hxx>
|
||||
#include <LDOM_MemManager.hxx>
|
||||
|
||||
#ifdef WNT
|
||||
// Disable the warning: "operator new unmatched by delete"
|
||||
#pragma warning (disable:4291)
|
||||
#endif
|
||||
|
||||
//=======================================================================
|
||||
//function : LDOM_BasicAttribute
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_BasicAttribute::LDOM_BasicAttribute (const LDOM_Attr& anAttr)
|
||||
: LDOM_BasicNode (anAttr.Origin()),
|
||||
myName (anAttr.getName().GetString()),
|
||||
myValue (anAttr.getValue()) {}
|
||||
|
||||
//=======================================================================
|
||||
//function : Create
|
||||
//purpose : construction in the Document's data pool
|
||||
//=======================================================================
|
||||
|
||||
LDOM_BasicAttribute& LDOM_BasicAttribute::Create
|
||||
(const LDOMBasicString& theName,
|
||||
const Handle(LDOM_MemManager)& theDoc,
|
||||
Standard_Integer& theHash)
|
||||
{
|
||||
void * aMem = theDoc -> Allocate (sizeof(LDOM_BasicAttribute));
|
||||
LDOM_BasicAttribute * aNewAtt = new (aMem) LDOM_BasicAttribute;
|
||||
|
||||
const char * aString = theName.GetString();
|
||||
aNewAtt -> myName =
|
||||
theDoc -> HashedAllocate (aString, strlen(aString), theHash);
|
||||
|
||||
aNewAtt -> myNodeType = LDOM_Node::ATTRIBUTE_NODE;
|
||||
return * aNewAtt;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator =
|
||||
//purpose : Assignment to NULL
|
||||
//=======================================================================
|
||||
|
||||
LDOM_BasicAttribute& LDOM_BasicAttribute::operator= (const LDOM_NullPtr * aNull)
|
||||
{
|
||||
myName = NULL;
|
||||
myValue = aNull;
|
||||
LDOM_BasicNode::operator= (aNull);
|
||||
return * this;
|
||||
}
|
79
src/LDOM/LDOM_BasicAttribute.hxx
Executable file
79
src/LDOM/LDOM_BasicAttribute.hxx
Executable file
@@ -0,0 +1,79 @@
|
||||
// File: LDOM_BasicAttribute.hxx
|
||||
// Created: 26.06.01 16:16:07
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
|
||||
|
||||
#ifndef LDOM_BasicAttribute_HeaderFile
|
||||
#define LDOM_BasicAttribute_HeaderFile
|
||||
|
||||
#include <LDOM_BasicNode.hxx>
|
||||
#include <LDOMBasicString.hxx>
|
||||
|
||||
class LDOM_XmlReader;
|
||||
class LDOM_Element;
|
||||
class LDOM_Attr;
|
||||
class LDOM_Node;
|
||||
|
||||
#ifdef WNT
|
||||
// Disable the warning: "operator new unmatched by delete"
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable:4291)
|
||||
#endif
|
||||
|
||||
// Class LDOM_BasicAttribute
|
||||
//
|
||||
|
||||
class LDOM_BasicAttribute : public LDOM_BasicNode
|
||||
{
|
||||
public:
|
||||
void * operator new (size_t, void * anAddress) { return anAddress; }
|
||||
|
||||
// ---------- PUBLIC METHODS ----------
|
||||
|
||||
LDOM_BasicAttribute () : LDOM_BasicNode (LDOM_Node::UNKNOWN) {}
|
||||
// Empty constructor
|
||||
|
||||
LDOM_BasicAttribute& operator = (const LDOM_NullPtr * aNull);
|
||||
// Nullify
|
||||
|
||||
const char * GetName () const { return myName; }
|
||||
|
||||
const LDOMBasicString& GetValue () const { return myValue; }
|
||||
|
||||
void SetValue (const LDOMBasicString& aValue,
|
||||
const Handle(LDOM_MemManager)& aDoc)
|
||||
{ myValue = LDOMString (aValue, aDoc); }
|
||||
|
||||
private:
|
||||
friend class LDOM_Node;
|
||||
friend class LDOM_Attr;
|
||||
friend class LDOM_Element;
|
||||
friend class LDOM_BasicElement;
|
||||
friend class LDOM_XmlReader;
|
||||
|
||||
// ---------- PRIVATE METHODS ----------
|
||||
|
||||
LDOM_BasicAttribute (const LDOMBasicString& aName)
|
||||
: LDOM_BasicNode (LDOM_Node::ATTRIBUTE_NODE), myName (aName.GetString()) {}
|
||||
// Constructor
|
||||
|
||||
static LDOM_BasicAttribute& Create (const LDOMBasicString& theName,
|
||||
const Handle(LDOM_MemManager)& theDoc,
|
||||
Standard_Integer& theHashIndex);
|
||||
|
||||
LDOM_BasicAttribute (const LDOM_Attr& anAttr);
|
||||
|
||||
private:
|
||||
// ---------- PRIVATE FIELDS ----------
|
||||
|
||||
// LDOMBasicString myName;
|
||||
const char * myName;
|
||||
LDOMBasicString myValue;
|
||||
};
|
||||
|
||||
#ifdef WNT
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
#endif
|
458
src/LDOM/LDOM_BasicElement.cxx
Executable file
458
src/LDOM/LDOM_BasicElement.cxx
Executable file
@@ -0,0 +1,458 @@
|
||||
// File: LDOM_BasicElement.cxx
|
||||
// Created: 26.06.01 21:22:14
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
// History: AGV 140202: Replace(const char *) for (LDOMBasicString)=>myTagName
|
||||
|
||||
#include <LDOM_BasicElement.hxx>
|
||||
#include <LDOM_BasicAttribute.hxx>
|
||||
#include <LDOM_BasicText.hxx>
|
||||
#include <LDOM_MemManager.hxx>
|
||||
|
||||
#ifdef WNT
|
||||
// Disable the warning: "operator new unmatched by delete"
|
||||
#pragma warning (disable:4291)
|
||||
#endif
|
||||
|
||||
//=======================================================================
|
||||
//function : Create
|
||||
//purpose : construction in the Document's data pool
|
||||
//=======================================================================
|
||||
|
||||
LDOM_BasicElement& LDOM_BasicElement::Create
|
||||
(const char * aName,
|
||||
const Standard_Integer aLen,
|
||||
const Handle(LDOM_MemManager)& aDoc)
|
||||
{
|
||||
if (aName == NULL) {
|
||||
static LDOM_BasicElement aVoidElement;
|
||||
aVoidElement = LDOM_BasicElement();
|
||||
return aVoidElement;
|
||||
}
|
||||
void * aMem = aDoc -> Allocate (sizeof(LDOM_BasicElement));
|
||||
LDOM_BasicElement * aNewElem = new (aMem) LDOM_BasicElement;
|
||||
|
||||
Standard_Integer aHash;
|
||||
// aDoc -> HashedAllocate (aString, strlen(aString), aNewElem -> myTagName);
|
||||
aNewElem -> myTagName = aDoc -> HashedAllocate (aName, aLen, aHash);
|
||||
|
||||
aNewElem -> myNodeType = LDOM_Node::ELEMENT_NODE;
|
||||
return * aNewElem;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : RemoveNodes
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void LDOM_BasicElement::RemoveNodes ()
|
||||
{
|
||||
const LDOM_BasicNode * aNode = (const LDOM_BasicNode *) myFirstChild;
|
||||
while (aNode) {
|
||||
const LDOM_BasicNode * aNext = aNode -> GetSibling();
|
||||
switch (aNode -> getNodeType ()) {
|
||||
case LDOM_Node::ELEMENT_NODE:
|
||||
{
|
||||
LDOM_BasicElement& anElement = * (LDOM_BasicElement *) aNode;
|
||||
anElement = NULL;
|
||||
break;
|
||||
}
|
||||
case LDOM_Node::ATTRIBUTE_NODE:
|
||||
{
|
||||
LDOM_BasicAttribute& anAttr = * (LDOM_BasicAttribute *) aNode;
|
||||
anAttr = NULL;
|
||||
break;
|
||||
}
|
||||
case LDOM_Node::TEXT_NODE:
|
||||
case LDOM_Node::COMMENT_NODE:
|
||||
case LDOM_Node::CDATA_SECTION_NODE:
|
||||
{
|
||||
LDOM_BasicText& aTxt = * (LDOM_BasicText *) aNode;
|
||||
aTxt = NULL;
|
||||
break;
|
||||
}
|
||||
default: ;
|
||||
}
|
||||
aNode = aNext;
|
||||
}
|
||||
myFirstChild = NULL;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator =
|
||||
//purpose : Nullify
|
||||
//=======================================================================
|
||||
|
||||
LDOM_BasicElement& LDOM_BasicElement:: operator = (const LDOM_NullPtr * aNull)
|
||||
{
|
||||
myTagName = NULL;
|
||||
RemoveNodes ();
|
||||
LDOM_BasicNode::operator= (aNull);
|
||||
return * this;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : LDOM_BasicElement
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
/*
|
||||
LDOM_BasicElement::LDOM_BasicElement (const LDOM_Element& anElement)
|
||||
: LDOM_BasicNode (LDOM_Node::ELEMENT_NODE),
|
||||
myAttributeMask (0),
|
||||
myFirstChild (NULL)
|
||||
{
|
||||
// LDOMString aNewTagName (anElement.getTagName(), anElement.myDocument);
|
||||
// myTagName = aNewTagName;
|
||||
const LDOM_BasicElement& anOther =
|
||||
(const LDOM_BasicElement&) anElement.Origin();
|
||||
myTagName = anOther.GetTagName();
|
||||
}
|
||||
*/
|
||||
//=======================================================================
|
||||
//function : ~LDOM_BasicElement
|
||||
//purpose : Destructor
|
||||
//=======================================================================
|
||||
|
||||
LDOM_BasicElement::~LDOM_BasicElement ()
|
||||
{
|
||||
myTagName = NULL;
|
||||
RemoveNodes ();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetLastChild
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const LDOM_BasicNode * LDOM_BasicElement::GetLastChild () const
|
||||
{
|
||||
const LDOM_BasicNode * aNode = myFirstChild;
|
||||
if (aNode) {
|
||||
if (aNode -> getNodeType() == LDOM_Node::ATTRIBUTE_NODE)
|
||||
aNode = NULL;
|
||||
else
|
||||
while (aNode -> mySibling) {
|
||||
if (aNode -> mySibling -> getNodeType() == LDOM_Node::ATTRIBUTE_NODE)
|
||||
break;
|
||||
aNode = aNode -> mySibling;
|
||||
}
|
||||
}
|
||||
return aNode;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetAttribute
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const LDOM_BasicAttribute& LDOM_BasicElement::GetAttribute
|
||||
(const LDOMBasicString& aName,
|
||||
const LDOM_BasicNode * aLastCh) const
|
||||
{
|
||||
const LDOM_BasicNode * aNode;
|
||||
if (aLastCh)
|
||||
aNode = aLastCh -> GetSibling ();
|
||||
else
|
||||
aNode = myFirstChild;
|
||||
const char * aNameStr = aName.GetString();
|
||||
while (aNode) {
|
||||
if (aNode -> getNodeType () == LDOM_Node::ATTRIBUTE_NODE) {
|
||||
const LDOM_BasicAttribute * anAttr = (const LDOM_BasicAttribute *) aNode;
|
||||
if (!strcmp (aNameStr, anAttr -> GetName()))
|
||||
return * anAttr;
|
||||
}
|
||||
aNode = aNode -> mySibling;
|
||||
}
|
||||
static const LDOM_BasicAttribute aNullAttribute;
|
||||
return aNullAttribute;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetFirstAttribute
|
||||
//purpose : private method
|
||||
//=======================================================================
|
||||
|
||||
const LDOM_BasicAttribute * LDOM_BasicElement::GetFirstAttribute
|
||||
(const LDOM_BasicNode *& theLastCh,
|
||||
const LDOM_BasicNode **& thePrevNode) const
|
||||
{
|
||||
// Find the First Attribute as well as the Last Child among siblings
|
||||
const LDOM_BasicNode * aFirstAttr;
|
||||
const LDOM_BasicNode ** aPrevNode;
|
||||
if (theLastCh) {
|
||||
aFirstAttr = theLastCh -> mySibling;
|
||||
aPrevNode = (const LDOM_BasicNode **) &(theLastCh -> mySibling);
|
||||
while (aFirstAttr) {
|
||||
if (aFirstAttr -> getNodeType() == LDOM_Node::ATTRIBUTE_NODE) break;
|
||||
aPrevNode = (const LDOM_BasicNode **) & (aFirstAttr -> mySibling);
|
||||
aFirstAttr = aFirstAttr -> mySibling;
|
||||
}
|
||||
} else {
|
||||
aFirstAttr = myFirstChild;
|
||||
aPrevNode = (const LDOM_BasicNode **) &myFirstChild;
|
||||
while (aFirstAttr) {
|
||||
if (aFirstAttr -> getNodeType() == LDOM_Node::ATTRIBUTE_NODE) break;
|
||||
if (aFirstAttr -> isNull() == Standard_False) theLastCh = aFirstAttr;
|
||||
aPrevNode = (const LDOM_BasicNode **) & (aFirstAttr -> mySibling);
|
||||
aFirstAttr = aFirstAttr -> mySibling;
|
||||
}
|
||||
}
|
||||
thePrevNode = aPrevNode;
|
||||
return (LDOM_BasicAttribute *) aFirstAttr;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AddAttribute
|
||||
//purpose : Add or replace an attribute
|
||||
//=======================================================================
|
||||
|
||||
const LDOM_BasicNode * LDOM_BasicElement::AddAttribute
|
||||
(const LDOMBasicString& anAttrName,
|
||||
const LDOMBasicString& anAttrValue,
|
||||
const Handle(LDOM_MemManager)& aDocument,
|
||||
const LDOM_BasicNode * aLastCh)
|
||||
{
|
||||
// Create attribute
|
||||
Standard_Integer aHash;
|
||||
LDOM_BasicAttribute& anAttr =
|
||||
LDOM_BasicAttribute::Create (anAttrName, aDocument, aHash);
|
||||
anAttr.myValue = anAttrValue;
|
||||
|
||||
// Initialize the loop of attribute name search
|
||||
const LDOM_BasicNode ** aPrNode;
|
||||
const LDOM_BasicAttribute * aFirstAttr = GetFirstAttribute (aLastCh, aPrNode);
|
||||
const char * aNameStr = anAttrName.GetString();
|
||||
|
||||
// Check attribute hash value against the current mask
|
||||
const unsigned int anAttrMaskValue = aHash & (8*sizeof(myAttributeMask) - 1);
|
||||
const unsigned long anAttributeMask = (1 << anAttrMaskValue);
|
||||
#ifdef DEBUG_MASK
|
||||
anAttributeMask = 0xffffffff;
|
||||
#endif
|
||||
if ((myAttributeMask & anAttributeMask) == 0) {
|
||||
// this is new attribute, OK
|
||||
myAttributeMask |= anAttributeMask;
|
||||
* aPrNode = &anAttr;
|
||||
anAttr.SetSibling (aFirstAttr);
|
||||
} else {
|
||||
// this attribute may have already been installed
|
||||
LDOM_BasicAttribute * aCurrentAttr = (LDOM_BasicAttribute *) aFirstAttr;
|
||||
while (aCurrentAttr) {
|
||||
if (aCurrentAttr -> getNodeType() == LDOM_Node::ATTRIBUTE_NODE)
|
||||
if (LDOM_MemManager::CompareStrings (aNameStr, aHash,
|
||||
aCurrentAttr -> GetName())) {
|
||||
aCurrentAttr -> SetValue (anAttrValue, aDocument);
|
||||
break;
|
||||
}
|
||||
aCurrentAttr = (LDOM_BasicAttribute *) aCurrentAttr -> mySibling;
|
||||
}
|
||||
if (aCurrentAttr == NULL) {
|
||||
// this is new attribute, OK
|
||||
* aPrNode = &anAttr;
|
||||
anAttr.SetSibling (aFirstAttr);
|
||||
}
|
||||
}
|
||||
return aLastCh;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : RemoveAttribute
|
||||
//purpose : Find and delete an attribute from list
|
||||
//=======================================================================
|
||||
|
||||
const LDOM_BasicNode * LDOM_BasicElement::RemoveAttribute
|
||||
(const LDOMBasicString& aName,
|
||||
const LDOM_BasicNode * aLastCh) const
|
||||
{
|
||||
// Check attribute hash value against the current mask
|
||||
const char * const aNameStr = aName.GetString();
|
||||
const Standard_Integer aHash =
|
||||
LDOM_MemManager::Hash (aNameStr, strlen(aNameStr));
|
||||
const unsigned int anAttrMaskValue = aHash & (8*sizeof(myAttributeMask) - 1);
|
||||
const unsigned long anAttributeMask = (1 << anAttrMaskValue);
|
||||
#ifdef DEBUG_MASK
|
||||
anAttributeMask = 0xffffffff;
|
||||
#endif
|
||||
if ((myAttributeMask & anAttributeMask) == 0) {
|
||||
; // maybe cause for exception
|
||||
} else {
|
||||
const LDOM_BasicNode ** aPrevNode; // dummy
|
||||
const LDOM_BasicAttribute * anAttr = GetFirstAttribute (aLastCh, aPrevNode);
|
||||
while (anAttr) {
|
||||
if (anAttr -> getNodeType () == LDOM_Node::ATTRIBUTE_NODE)
|
||||
if (LDOM_MemManager::CompareStrings(aNameStr,aHash,anAttr->GetName())) {
|
||||
anAttr = NULL;
|
||||
break;
|
||||
}
|
||||
anAttr = (const LDOM_BasicAttribute *) anAttr -> mySibling;
|
||||
}
|
||||
}
|
||||
return aLastCh;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : RemoveChild
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void LDOM_BasicElement::RemoveChild (const LDOM_BasicNode * aChild) const
|
||||
{
|
||||
const LDOM_BasicNode * aNode = myFirstChild;
|
||||
const LDOM_BasicNode ** aPrevNode = (const LDOM_BasicNode **) &myFirstChild;
|
||||
while (aNode) {
|
||||
if (aNode -> getNodeType() == LDOM_Node::ATTRIBUTE_NODE)
|
||||
break;
|
||||
if (aNode == aChild) {
|
||||
* aPrevNode = aNode -> GetSibling();
|
||||
* (LDOM_BasicNode *) aChild = NULL;
|
||||
break;
|
||||
}
|
||||
aPrevNode = (const LDOM_BasicNode **) & (aNode -> mySibling);
|
||||
aNode = aNode -> GetSibling();
|
||||
}
|
||||
// here may be the cause to throw an exception
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AppendChild
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void LDOM_BasicElement::AppendChild (const LDOM_BasicNode * aChild,
|
||||
const LDOM_BasicNode *& aLastChild) const
|
||||
{
|
||||
if (aLastChild) {
|
||||
(const LDOM_BasicNode *&) aChild -> mySibling = aLastChild -> mySibling;
|
||||
(const LDOM_BasicNode *&) aLastChild -> mySibling = aChild;
|
||||
} else {
|
||||
const LDOM_BasicNode * aNode = myFirstChild;
|
||||
const LDOM_BasicNode ** aPrevNode = (const LDOM_BasicNode **) &myFirstChild;
|
||||
while (aNode) {
|
||||
if (aNode -> getNodeType() == LDOM_Node::ATTRIBUTE_NODE) {
|
||||
(const LDOM_BasicNode *&) aChild -> mySibling = aNode;
|
||||
break;
|
||||
}
|
||||
aPrevNode = (const LDOM_BasicNode **) & (aNode -> mySibling);
|
||||
aNode = aNode -> mySibling;
|
||||
}
|
||||
* aPrevNode = aChild;
|
||||
}
|
||||
aLastChild = aChild;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AddElementsByTagName
|
||||
//purpose : Add to the List all sub-elements with the given name (recursive)
|
||||
//=======================================================================
|
||||
|
||||
void LDOM_BasicElement::AddElementsByTagName
|
||||
(LDOM_NodeList& aList, const LDOMBasicString& aTagName) const
|
||||
{
|
||||
const LDOM_BasicNode * aNode = myFirstChild;
|
||||
const char * aTagString = aTagName.GetString();
|
||||
while (aNode) {
|
||||
if (aNode -> getNodeType() == LDOM_Node::ATTRIBUTE_NODE)
|
||||
break;
|
||||
if (aNode -> getNodeType() == LDOM_Node::ELEMENT_NODE) {
|
||||
LDOM_BasicElement& anElement = * (LDOM_BasicElement *) aNode;
|
||||
// if (anElement.GetTagName().equals(aTagName))
|
||||
if (strcmp (anElement.GetTagName(), aTagString) == 0)
|
||||
aList.Append (anElement);
|
||||
anElement.AddElementsByTagName (aList, aTagName);
|
||||
}
|
||||
aNode = aNode -> GetSibling();
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AddAttributes
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void LDOM_BasicElement::AddAttributes (LDOM_NodeList& aList,
|
||||
const LDOM_BasicNode * aLastChild) const
|
||||
{
|
||||
const LDOM_BasicNode * aBNode;
|
||||
if (aLastChild)
|
||||
aBNode = aLastChild -> GetSibling();
|
||||
else
|
||||
aBNode = GetFirstChild();
|
||||
while (aBNode) {
|
||||
if (aBNode -> getNodeType() == LDOM_Node::ATTRIBUTE_NODE)
|
||||
aList.Append (* aBNode);
|
||||
aBNode = aBNode -> GetSibling();
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ReplaceElement
|
||||
//purpose : Copy data and children into this node from another one
|
||||
// The only preserved data is mySibling
|
||||
//=======================================================================
|
||||
|
||||
void LDOM_BasicElement::ReplaceElement
|
||||
(const LDOM_BasicElement& anOtherElem,
|
||||
const Handle(LDOM_MemManager)& aDocument)
|
||||
{
|
||||
myTagName = anOtherElem.GetTagName();
|
||||
myAttributeMask = anOtherElem.myAttributeMask;
|
||||
myFirstChild = NULL;
|
||||
const LDOM_BasicNode * aBNode = anOtherElem.GetFirstChild ();
|
||||
const LDOM_BasicNode * aLastChild = NULL;
|
||||
|
||||
// Loop on children (non-attributes)
|
||||
for (; aBNode != NULL; aBNode = aBNode -> GetSibling()) {
|
||||
if (aBNode -> isNull())
|
||||
continue;
|
||||
LDOM_BasicNode * aNewBNode;
|
||||
const LDOM_Node::NodeType aNewNodeType = aBNode -> getNodeType();
|
||||
switch (aNewNodeType) {
|
||||
case LDOM_Node::ELEMENT_NODE:
|
||||
{
|
||||
const LDOM_BasicElement& aBNodeElem = *(const LDOM_BasicElement*)aBNode;
|
||||
const char * aTagString = aBNodeElem.GetTagName();
|
||||
LDOM_BasicElement& aNewBNodeElem =
|
||||
LDOM_BasicElement::Create (aTagString, strlen(aTagString), aDocument);
|
||||
aNewBNodeElem.ReplaceElement (aBNodeElem, aDocument); //reccur
|
||||
aNewBNode = &aNewBNodeElem;
|
||||
break;
|
||||
}
|
||||
case LDOM_Node::ATTRIBUTE_NODE:
|
||||
goto loop_attr;
|
||||
case LDOM_Node::TEXT_NODE:
|
||||
case LDOM_Node::COMMENT_NODE:
|
||||
case LDOM_Node::CDATA_SECTION_NODE:
|
||||
{
|
||||
const LDOM_BasicText& aBNodeText = * (const LDOM_BasicText *) aBNode;
|
||||
aNewBNode = &LDOM_BasicText::Create (aNewNodeType,
|
||||
LDOMString(aBNodeText.GetData(),
|
||||
aDocument),
|
||||
aDocument);
|
||||
break;
|
||||
}
|
||||
default: continue;
|
||||
}
|
||||
if (GetFirstChild())
|
||||
(const LDOM_BasicNode *&) aLastChild -> mySibling = aNewBNode;
|
||||
else
|
||||
(const LDOM_BasicNode *&) myFirstChild = aNewBNode;
|
||||
(const LDOM_BasicNode *&) aLastChild = aNewBNode;
|
||||
}
|
||||
|
||||
// Loop on attributes (in the end of the list of children)
|
||||
loop_attr:
|
||||
LDOM_BasicNode * aLastAttr = (LDOM_BasicNode *) aLastChild;
|
||||
for (; aBNode != NULL; aBNode = aBNode -> GetSibling()) {
|
||||
Standard_Integer aHash;
|
||||
if (aBNode -> isNull()) continue;
|
||||
const LDOM_BasicAttribute * aBNodeAtt= (const LDOM_BasicAttribute *) aBNode;
|
||||
LDOM_BasicAttribute * aNewAtt =
|
||||
&LDOM_BasicAttribute::Create (aBNodeAtt -> GetName(), aDocument, aHash);
|
||||
aNewAtt -> SetValue (aBNodeAtt->myValue, aDocument);
|
||||
if (aLastAttr)
|
||||
aLastAttr -> SetSibling (aNewAtt);
|
||||
else
|
||||
myFirstChild = aNewAtt;
|
||||
aLastAttr = aNewAtt;
|
||||
}
|
||||
}
|
135
src/LDOM/LDOM_BasicElement.hxx
Executable file
135
src/LDOM/LDOM_BasicElement.hxx
Executable file
@@ -0,0 +1,135 @@
|
||||
// File: LDOM_BasicElement.hxx
|
||||
// Created: 26.06.01 20:04:27
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
// History: AGV 140202: Repl.(const char *) for (LDOMBasicString) => myTagName
|
||||
|
||||
#ifndef LDOM_BasicElement_HeaderFile
|
||||
#define LDOM_BasicElement_HeaderFile
|
||||
|
||||
#include <LDOM_BasicNode.hxx>
|
||||
#include <LDOMBasicString.hxx>
|
||||
#include <LDOM_Node.hxx>
|
||||
|
||||
class LDOM_XmlReader;
|
||||
class LDOMParser;
|
||||
class LDOM_NodeList;
|
||||
class LDOM_Element;
|
||||
class LDOM_BasicAttribute;
|
||||
|
||||
#ifdef WNT
|
||||
// Disable the warning: "operator new unmatched by delete"
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable:4291)
|
||||
#endif
|
||||
|
||||
// Class LDOM_BasicElement
|
||||
//
|
||||
|
||||
class LDOM_BasicElement : public LDOM_BasicNode
|
||||
{
|
||||
public:
|
||||
void * operator new (size_t, void * anAddress) { return anAddress; }
|
||||
|
||||
// ---------- PUBLIC METHODS ----------
|
||||
|
||||
LDOM_BasicElement ()
|
||||
: LDOM_BasicNode (LDOM_Node::UNKNOWN),
|
||||
myTagName (NULL),
|
||||
myAttributeMask (0),
|
||||
myFirstChild (NULL) {}
|
||||
// Empty constructor
|
||||
|
||||
static LDOM_BasicElement& Create (const char * aName,
|
||||
const Standard_Integer aLength,
|
||||
const Handle(LDOM_MemManager)& aDoc);
|
||||
|
||||
// Standard_EXPORT LDOM_BasicElement (const LDOM_BasicElement& theOther);
|
||||
// Copy constructor
|
||||
|
||||
Standard_EXPORT LDOM_BasicElement&
|
||||
operator = (const LDOM_NullPtr * aNull);
|
||||
// Nullify
|
||||
|
||||
Standard_EXPORT ~LDOM_BasicElement ();
|
||||
// Destructor
|
||||
|
||||
const char * GetTagName () const { return myTagName; }
|
||||
|
||||
const LDOM_BasicNode *
|
||||
GetFirstChild () const { return myFirstChild; }
|
||||
|
||||
Standard_EXPORT const LDOM_BasicNode *
|
||||
GetLastChild () const;
|
||||
|
||||
Standard_EXPORT const LDOM_BasicAttribute&
|
||||
GetAttribute (const LDOMBasicString& aName,
|
||||
const LDOM_BasicNode * aLastCh) const;
|
||||
// Search for attribute name, using or setting myFirstAttribute
|
||||
|
||||
protected:
|
||||
// ---------- PROTECTED METHODS ----------
|
||||
|
||||
// LDOM_BasicElement (const LDOM_Element& anElement);
|
||||
// Constructor
|
||||
|
||||
Standard_EXPORT const LDOM_BasicNode *
|
||||
AddAttribute (const LDOMBasicString& anAttrName,
|
||||
const LDOMBasicString& anAttrValue,
|
||||
const Handle(LDOM_MemManager)& aDoc,
|
||||
const LDOM_BasicNode * aLastCh);
|
||||
// add or replace an attribute to the element
|
||||
|
||||
Standard_EXPORT const LDOM_BasicNode *
|
||||
RemoveAttribute (const LDOMBasicString& aName,
|
||||
const LDOM_BasicNode * aLastCh) const;
|
||||
|
||||
Standard_EXPORT void
|
||||
RemoveChild (const LDOM_BasicNode * aChild) const;
|
||||
// remove a child element
|
||||
|
||||
Standard_EXPORT void
|
||||
AppendChild (const LDOM_BasicNode * aChild,
|
||||
const LDOM_BasicNode *& aLastCh) const;
|
||||
// append a child node to the end of the list
|
||||
|
||||
private:
|
||||
friend class LDOMParser;
|
||||
friend class LDOM_XmlReader;
|
||||
friend class LDOM_Document;
|
||||
friend class LDOM_Element;
|
||||
friend class LDOM_Node;
|
||||
// ---------- PRIVATE METHODS ----------
|
||||
|
||||
const LDOM_BasicAttribute *
|
||||
GetFirstAttribute (const LDOM_BasicNode *& aLastCh,
|
||||
const LDOM_BasicNode **& thePrN) const;
|
||||
|
||||
void RemoveNodes ();
|
||||
|
||||
void ReplaceElement (const LDOM_BasicElement& anOther,
|
||||
const Handle(LDOM_MemManager)& aDoc);
|
||||
// remark: recursive
|
||||
|
||||
void AddElementsByTagName (LDOM_NodeList& aList,
|
||||
const LDOMBasicString& aTagName) const;
|
||||
// remark: recursive
|
||||
|
||||
void AddAttributes (LDOM_NodeList& aList,
|
||||
const LDOM_BasicNode * aLastCh) const;
|
||||
// add attributes to list
|
||||
|
||||
private:
|
||||
// ---------- PRIVATE FIELDS ----------
|
||||
|
||||
// LDOMBasicString myTagName;
|
||||
const char * myTagName;
|
||||
unsigned long myAttributeMask;
|
||||
LDOM_BasicNode * myFirstChild;
|
||||
};
|
||||
|
||||
#ifdef WNT
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
#endif
|
120
src/LDOM/LDOM_BasicNode.cxx
Executable file
120
src/LDOM/LDOM_BasicNode.cxx
Executable file
@@ -0,0 +1,120 @@
|
||||
// File: LDOM_BasicNode.cxx
|
||||
// Created: 27.06.01 12:18:10
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
// History:
|
||||
|
||||
#include <LDOM_BasicNode.hxx>
|
||||
#include <LDOM_BasicElement.hxx>
|
||||
#include <LDOM_BasicAttribute.hxx>
|
||||
#include <LDOM_BasicText.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : operator =
|
||||
//purpose : Assignment
|
||||
//=======================================================================
|
||||
|
||||
LDOM_BasicNode& LDOM_BasicNode::operator = (const LDOM_BasicNode& anOther)
|
||||
{
|
||||
myNodeType = anOther.getNodeType();
|
||||
mySibling = anOther.GetSibling();
|
||||
return * this;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetSibling
|
||||
//purpose : also detaches NULL siblings
|
||||
//=======================================================================
|
||||
|
||||
const LDOM_BasicNode * LDOM_BasicNode::GetSibling () const
|
||||
{
|
||||
while (mySibling)
|
||||
if (mySibling -> isNull())
|
||||
(const LDOM_BasicNode *&) mySibling = mySibling -> mySibling;
|
||||
else break;
|
||||
return mySibling;
|
||||
}
|
||||
|
||||
#ifdef DEB
|
||||
#ifndef WNT
|
||||
//=======================================================================
|
||||
// Debug Function for DBX: use "print -p <Variable> or pp <Variable>"
|
||||
//=======================================================================
|
||||
#include <LDOM_OSStream.hxx>
|
||||
#define FLITERAL 0x10
|
||||
#define MAX_SIBLINGS 8
|
||||
char * db_pretty_print (const LDOM_BasicNode * aBNode, int fl, char *)
|
||||
{
|
||||
LDOM_OSStream out (128);
|
||||
switch (aBNode -> getNodeType()) {
|
||||
case LDOM_Node::ELEMENT_NODE:
|
||||
{
|
||||
const LDOM_BasicElement& aBElem = * (const LDOM_BasicElement *) aBNode;
|
||||
if ((fl & FLITERAL) == 0) out << "LDOM_BasicElement: ";
|
||||
out << '<' << aBElem.GetTagName();
|
||||
aBNode = aBElem.GetFirstChild();
|
||||
while (aBNode) {
|
||||
if (aBNode -> getNodeType() == LDOM_Node::ATTRIBUTE_NODE)
|
||||
out << ' ' <<
|
||||
db_pretty_print ((const LDOM_BasicAttribute *) aBNode, FLITERAL, 0);
|
||||
aBNode = aBNode -> GetSibling();
|
||||
}
|
||||
out << '>';
|
||||
if ((fl & FLITERAL) == 0) {
|
||||
aBNode = aBElem.GetFirstChild();
|
||||
int counter = MAX_SIBLINGS;
|
||||
if (aBNode) {
|
||||
out << endl << " == Children:" << endl;
|
||||
while (aBNode && counter--) {
|
||||
if (aBNode -> getNodeType() == LDOM_Node::ATTRIBUTE_NODE) break;
|
||||
out << " *(LDOM_BasicNode*)" << aBNode << " : " <<
|
||||
db_pretty_print (aBNode, FLITERAL, 0) << endl;
|
||||
aBNode = aBNode -> GetSibling();
|
||||
}
|
||||
}
|
||||
aBNode = aBElem.GetSibling();
|
||||
if (aBNode) {
|
||||
out << " == Siblings:" << endl;
|
||||
counter = MAX_SIBLINGS;
|
||||
while (aBNode && counter--) {
|
||||
if (aBNode -> getNodeType() == LDOM_Node::ATTRIBUTE_NODE) break;
|
||||
out << " *(LDOM_BasicNode*)" << aBNode << " : " <<
|
||||
db_pretty_print (aBNode, FLITERAL, 0) << endl;
|
||||
aBNode = aBNode -> GetSibling();
|
||||
}
|
||||
}
|
||||
}
|
||||
out << ends;
|
||||
break;
|
||||
}
|
||||
case LDOM_Node::ATTRIBUTE_NODE:
|
||||
{
|
||||
const LDOM_BasicAttribute& aBAtt = * (const LDOM_BasicAttribute *) aBNode;
|
||||
if ((fl & FLITERAL) == 0) out << "LDOM_BasicAttribute: ";
|
||||
out << aBAtt.GetName() << '='
|
||||
<< db_pretty_print (&aBAtt.GetValue(), FLITERAL, 0) << ends;
|
||||
break;
|
||||
}
|
||||
case LDOM_Node::TEXT_NODE:
|
||||
case LDOM_Node::COMMENT_NODE:
|
||||
case LDOM_Node::CDATA_SECTION_NODE:
|
||||
{
|
||||
const LDOM_BasicText& aBText = * (const LDOM_BasicText *) aBNode;
|
||||
if ((fl & FLITERAL) == 0) out << "LDOM_BasicText: ";
|
||||
out << db_pretty_print (&aBText.GetData(), FLITERAL, 0) << ends;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
out << "UNKNOWN" << ends;
|
||||
break;
|
||||
}
|
||||
return (char *)out.str();
|
||||
}
|
||||
|
||||
char * db_pretty_print (const LDOM_Node * aBNode, int fl, char * c)
|
||||
{
|
||||
return db_pretty_print (&aBNode -> Origin(), fl, c);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
60
src/LDOM/LDOM_BasicNode.hxx
Executable file
60
src/LDOM/LDOM_BasicNode.hxx
Executable file
@@ -0,0 +1,60 @@
|
||||
// File: LDOM_BasicNode.hxx
|
||||
// Created: 26.06.01 14:45:03
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
|
||||
|
||||
#ifndef LDOM_BasicNode_HeaderFile
|
||||
#define LDOM_BasicNode_HeaderFile
|
||||
|
||||
#include <LDOM_Node.hxx>
|
||||
|
||||
class LDOM_BasicElement;
|
||||
class LDOM_NullPtr;
|
||||
class LDOMParser;
|
||||
|
||||
// Block of comments describing class LDOM_BasicNode
|
||||
//
|
||||
|
||||
class LDOM_BasicNode
|
||||
{
|
||||
public:
|
||||
|
||||
Standard_Boolean isNull () const {return myNodeType ==LDOM_Node::UNKNOWN;}
|
||||
|
||||
LDOM_Node::NodeType getNodeType () const { return myNodeType; }
|
||||
|
||||
Standard_EXPORT const LDOM_BasicNode * GetSibling () const;
|
||||
|
||||
protected:
|
||||
// ---------- PROTECTED METHODS ----------
|
||||
|
||||
LDOM_BasicNode () : myNodeType (LDOM_Node::UNKNOWN), mySibling (NULL) {}
|
||||
// Empty constructor
|
||||
|
||||
LDOM_BasicNode (LDOM_Node::NodeType aType)
|
||||
: myNodeType (aType), mySibling (NULL) {}
|
||||
// Constructor
|
||||
|
||||
LDOM_BasicNode (const LDOM_BasicNode& anOther)
|
||||
: myNodeType (anOther.getNodeType()), mySibling (anOther.GetSibling()) {}
|
||||
// Copy constructor
|
||||
|
||||
LDOM_BasicNode& operator = (const LDOM_NullPtr * )
|
||||
{ myNodeType = LDOM_Node::UNKNOWN; return *this; }
|
||||
|
||||
Standard_EXPORT LDOM_BasicNode& operator = (const LDOM_BasicNode& anOther);
|
||||
|
||||
void SetSibling (const LDOM_BasicNode * anOther) { mySibling = anOther; }
|
||||
|
||||
protected:
|
||||
friend class LDOM_BasicElement;
|
||||
friend class LDOM_Node;
|
||||
friend class LDOMParser;
|
||||
// ---------- PROTECTED FIELDSS ----------
|
||||
|
||||
LDOM_Node::NodeType myNodeType;
|
||||
const LDOM_BasicNode * mySibling;
|
||||
};
|
||||
|
||||
#endif
|
49
src/LDOM/LDOM_BasicText.cxx
Executable file
49
src/LDOM/LDOM_BasicText.cxx
Executable file
@@ -0,0 +1,49 @@
|
||||
// File: LDOM_BasicText.cxx
|
||||
// Created: 26.07.01 19:18:50
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
// History:
|
||||
|
||||
|
||||
#include <LDOM_BasicText.hxx>
|
||||
#include <LDOM_MemManager.hxx>
|
||||
|
||||
#ifdef WNT
|
||||
// Disable the warning: "operator new unmatched by delete"
|
||||
#pragma warning (disable:4291)
|
||||
#endif
|
||||
|
||||
//=======================================================================
|
||||
//function : LDOM_BasicText()
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
|
||||
LDOM_BasicText::LDOM_BasicText (const LDOM_CharacterData& aText)
|
||||
: LDOM_BasicNode (aText.Origin()),
|
||||
myValue (aText.getData()) {}
|
||||
|
||||
//=======================================================================
|
||||
//function : Create
|
||||
//purpose : construction in the Document's data pool
|
||||
//=======================================================================
|
||||
|
||||
LDOM_BasicText& LDOM_BasicText::Create (const LDOM_Node::NodeType aType,
|
||||
const LDOMBasicString& aData,
|
||||
const Handle(LDOM_MemManager)& aDoc)
|
||||
{
|
||||
void * aMem = aDoc -> Allocate (sizeof(LDOM_BasicText));
|
||||
LDOM_BasicText * aNewText = new (aMem) LDOM_BasicText (aType, aData);
|
||||
return * aNewText;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator =
|
||||
//purpose : Assignment to NULL
|
||||
//=======================================================================
|
||||
|
||||
LDOM_BasicText& LDOM_BasicText::operator= (const LDOM_NullPtr * aNull)
|
||||
{
|
||||
myValue = aNull;
|
||||
LDOM_BasicNode::operator= (aNull);
|
||||
return * this;
|
||||
}
|
76
src/LDOM/LDOM_BasicText.hxx
Executable file
76
src/LDOM/LDOM_BasicText.hxx
Executable file
@@ -0,0 +1,76 @@
|
||||
// File: LDOM_BasicText.hxx
|
||||
// Created: 26.07.01 18:44:13
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
|
||||
|
||||
#ifndef LDOM_BasicText_HeaderFile
|
||||
#define LDOM_BasicText_HeaderFile
|
||||
|
||||
#include <LDOM_BasicNode.hxx>
|
||||
#include <LDOMBasicString.hxx>
|
||||
|
||||
class LDOM_Node;
|
||||
class LDOM_CharacterData;
|
||||
class LDOMParser;
|
||||
class LDOM_BasicElement;
|
||||
|
||||
#ifdef WNT
|
||||
// Disable the warning: "operator new unmatched by delete"
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable:4291)
|
||||
#endif
|
||||
|
||||
// Class LDOM_BasicText
|
||||
//
|
||||
|
||||
class LDOM_BasicText : public LDOM_BasicNode
|
||||
{
|
||||
public:
|
||||
void * operator new (size_t, void * anAddress) { return anAddress; }
|
||||
|
||||
// ---------- PUBLIC METHODS ----------
|
||||
|
||||
LDOM_BasicText () : LDOM_BasicNode (LDOM_Node::UNKNOWN) {}
|
||||
// Empty constructor
|
||||
|
||||
LDOM_BasicText& operator = (const LDOM_NullPtr * aNull);
|
||||
// Nullify
|
||||
|
||||
const LDOMBasicString& GetData () const
|
||||
{ return myValue; }
|
||||
|
||||
void SetData (const LDOMBasicString& aValue,
|
||||
const Handle(LDOM_MemManager)& aDoc)
|
||||
{ myValue = LDOMString (aValue, aDoc); }
|
||||
|
||||
private:
|
||||
// ---------- PRIVATE METHODS ----------
|
||||
friend class LDOM_Node;
|
||||
friend class LDOMParser;
|
||||
friend class LDOM_Document;
|
||||
friend class LDOM_BasicElement;
|
||||
|
||||
LDOM_BasicText (const LDOM_Node::NodeType aType,
|
||||
const LDOMBasicString& aData)
|
||||
: LDOM_BasicNode (aType), myValue (aData) {}
|
||||
// Constructor
|
||||
|
||||
LDOM_BasicText (const LDOM_CharacterData& aText);
|
||||
|
||||
static LDOM_BasicText& Create (const LDOM_Node::NodeType aType,
|
||||
const LDOMBasicString& aData,
|
||||
const Handle(LDOM_MemManager)& aDoc);
|
||||
// Creation
|
||||
|
||||
private:
|
||||
// ---------- PRIVATE FIELDS ----------
|
||||
|
||||
LDOMBasicString myValue;
|
||||
};
|
||||
|
||||
#ifdef WNT
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
#endif
|
42
src/LDOM/LDOM_CDATASection.hxx
Executable file
42
src/LDOM/LDOM_CDATASection.hxx
Executable file
@@ -0,0 +1,42 @@
|
||||
// File: LDOM_CDATASection.hxx
|
||||
// Created: 12.09.01 14:13:44
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: Open Cascade 2001
|
||||
|
||||
|
||||
#ifndef LDOM_CDATASection_HeaderFile
|
||||
#define LDOM_CDATASection_HeaderFile
|
||||
|
||||
#include <LDOM_Text.hxx>
|
||||
|
||||
// Class LDOM_CDATASection
|
||||
//
|
||||
|
||||
class LDOM_CDATASection : public LDOM_Text
|
||||
{
|
||||
public:
|
||||
// ---------- PUBLIC METHODS ----------
|
||||
|
||||
LDOM_CDATASection () {}
|
||||
// Empty constructor
|
||||
|
||||
LDOM_CDATASection (const LDOM_CDATASection& theOther): LDOM_Text (theOther) {}
|
||||
// Copy constructor
|
||||
|
||||
LDOM_CDATASection& operator = (const LDOM_NullPtr * theNull)
|
||||
{ return (LDOM_CDATASection&) LDOM_CharacterData::operator = (theNull);}
|
||||
// Nullify
|
||||
|
||||
LDOM_CDATASection& operator = (const LDOM_CDATASection& theOther)
|
||||
{ return (LDOM_CDATASection&) LDOM_CharacterData::operator= (theOther);}
|
||||
// Assignment
|
||||
|
||||
protected:
|
||||
friend class LDOM_Document;
|
||||
|
||||
LDOM_CDATASection (const LDOM_BasicText& theText,
|
||||
const Handle(LDOM_MemManager)& theDoc)
|
||||
: LDOM_Text (theText, theDoc) {}
|
||||
};
|
||||
|
||||
#endif
|
508
src/LDOM/LDOM_CharReference.cxx
Executable file
508
src/LDOM/LDOM_CharReference.cxx
Executable file
@@ -0,0 +1,508 @@
|
||||
// File: LDOM_CharReference.cxx
|
||||
// Created: 08.02.02 20:07:59
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: Open Cascade 2002
|
||||
|
||||
#include <LDOM_CharReference.hxx>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// Uncomment this line if you want that your XML files contain codes 0xc0-0xff
|
||||
// as defined in Latin-1 code set. Otherwise these codes are written
|
||||
// numerically as &#x..;
|
||||
//#define LDOM_ALLOW_LATIN_1
|
||||
|
||||
const int NORMAL_C = 0;
|
||||
const int CHAR_REF = -1;
|
||||
const int ENTI_AMP = 1;
|
||||
const int ENTI_LT = 2;
|
||||
const int ENTI_GT = 3;
|
||||
const int ENTI_QUOT = 4;
|
||||
const int ENTI_APOS = 5;
|
||||
|
||||
struct entityRef {
|
||||
const char * name;
|
||||
const int length;
|
||||
entityRef (const char * aName, const int aLen) : name(aName), length(aLen) {}
|
||||
};
|
||||
|
||||
//=======================================================================
|
||||
//function : Decode
|
||||
//purpose : Convertes entity and character references on input
|
||||
// Always returns the same string (shortened after replacements)
|
||||
//=======================================================================
|
||||
|
||||
char * LDOM_CharReference::Decode (char * theSrc, Standard_Integer& theLen)
|
||||
{
|
||||
#define IS_EQUAL(_ptr,_string) (!memcmp(_ptr, _string, sizeof(_string)-1))
|
||||
|
||||
char * aSrcPtr = theSrc, * aDstPtr = theSrc;
|
||||
Standard_Integer anIncrCount = 0;
|
||||
while (1) {
|
||||
char * aPtr = strchr (aSrcPtr, '&');
|
||||
if (aPtr == NULL) {
|
||||
// End of the loop
|
||||
aPtr = strchr (aSrcPtr, '\0');
|
||||
if (anIncrCount == 0)
|
||||
theLen = aPtr - theSrc;
|
||||
else {
|
||||
Standard_Integer aByteCount = aPtr - aSrcPtr;
|
||||
memmove (aDstPtr, aSrcPtr, aByteCount + 1);
|
||||
theLen = (aDstPtr - theSrc) + aByteCount;
|
||||
}
|
||||
break;
|
||||
}
|
||||
Standard_Integer aByteCount = aPtr - aSrcPtr;
|
||||
if (aByteCount > 0 && aDstPtr != aSrcPtr)
|
||||
memmove (aDstPtr, aSrcPtr, aByteCount);
|
||||
aSrcPtr = aPtr;
|
||||
if (aSrcPtr[1] == '#') {
|
||||
unsigned long aChar;
|
||||
char * aNewPtr;
|
||||
aDstPtr = aSrcPtr - anIncrCount + 1;
|
||||
if (aSrcPtr[2] == 'x')
|
||||
aChar = strtoul (&aSrcPtr[3], &aNewPtr, 16); // hex encoding
|
||||
else
|
||||
aChar = strtoul (&aSrcPtr[2], &aNewPtr, 10); // decimal encoding
|
||||
if (aNewPtr[0] != ';' || aChar == 0 || aChar > 255UL)
|
||||
// Error reading an XML string
|
||||
return NULL;
|
||||
aDstPtr[-1] = (char) aChar;
|
||||
anIncrCount += aNewPtr - aSrcPtr;
|
||||
aSrcPtr = &aNewPtr[1];
|
||||
}
|
||||
else if (IS_EQUAL(aSrcPtr+1, "amp;")) {
|
||||
aDstPtr = aSrcPtr - anIncrCount + 1;
|
||||
// aDstPtr[-1] = '&';
|
||||
anIncrCount += 4;
|
||||
aSrcPtr += 5;
|
||||
}
|
||||
else if (IS_EQUAL(aSrcPtr+1, "lt;")) {
|
||||
aDstPtr = aSrcPtr - anIncrCount + 1;
|
||||
aDstPtr[-1] = '<';
|
||||
anIncrCount += 3;
|
||||
aSrcPtr += 4;
|
||||
}
|
||||
else if (IS_EQUAL(aSrcPtr+1, "gt;")) {
|
||||
aDstPtr = aSrcPtr - anIncrCount + 1;
|
||||
aDstPtr[-1] = '>';
|
||||
anIncrCount += 3;
|
||||
aSrcPtr += 4;
|
||||
}
|
||||
else if (IS_EQUAL(aSrcPtr+1, "quot;")) {
|
||||
aDstPtr = aSrcPtr - anIncrCount + 1;
|
||||
aDstPtr[-1] = '\"';
|
||||
anIncrCount += 5;
|
||||
aSrcPtr += 6;
|
||||
}
|
||||
else if (IS_EQUAL(aSrcPtr+1, "apos;")) {
|
||||
aDstPtr = aSrcPtr - anIncrCount + 1;
|
||||
aDstPtr[-1] = '\'';
|
||||
anIncrCount += 5;
|
||||
aSrcPtr += 6;
|
||||
}
|
||||
else {
|
||||
aDstPtr = aSrcPtr - anIncrCount;
|
||||
* aDstPtr++ = * aSrcPtr++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return theSrc;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Encode
|
||||
//purpose : This method takes the input string theSrc and returns:
|
||||
// - the pointer equal to theSrc if there are no replacements, or
|
||||
// - the pointer to a newly allocated string with replacements
|
||||
// The output parameter theLen is assigned to the length of
|
||||
// the returned string (whatever the case)
|
||||
//=======================================================================
|
||||
|
||||
char * LDOM_CharReference::Encode (const char* theSrc, Standard_Integer& theLen,
|
||||
const Standard_Boolean isAttribute)
|
||||
{
|
||||
// Initialising the constants
|
||||
static const struct entityRef entity_ref[6] = {
|
||||
entityRef(NULL, 0),
|
||||
entityRef("&", 5),
|
||||
entityRef("<", 4),
|
||||
entityRef(">", 4),
|
||||
entityRef(""", 6),
|
||||
entityRef("'", 6)
|
||||
};
|
||||
|
||||
const char * endSrc, * ptrSrc = theSrc;
|
||||
char * aDest = (char *) theSrc;
|
||||
Standard_Integer aCount = 0;
|
||||
// Analyse if there is a non-standard character in the string
|
||||
while (1) {
|
||||
const unsigned int iSrc =
|
||||
(const unsigned int) * (const unsigned char *) ptrSrc;
|
||||
if (iSrc == 0) {
|
||||
endSrc = ptrSrc;
|
||||
break;
|
||||
}
|
||||
if (myTab[iSrc] != NORMAL_C)
|
||||
if (isAttribute || myTab[iSrc] != ENTI_QUOT)
|
||||
aCount++;
|
||||
ptrSrc++;
|
||||
}
|
||||
// If there are such, copy the string with replacements
|
||||
if (!aCount)
|
||||
theLen = endSrc - theSrc;
|
||||
else {
|
||||
char * ptrDest = new char [(endSrc - theSrc) + aCount * 5 + 1];
|
||||
aDest = ptrDest;
|
||||
for (ptrSrc = theSrc; ptrSrc < endSrc; ptrSrc++) {
|
||||
const unsigned int iSrc =
|
||||
(const unsigned int) * (const unsigned char *) ptrSrc;
|
||||
const int aCode = myTab[iSrc];
|
||||
if (aCode == NORMAL_C) // normal (regular) character
|
||||
* ptrDest++ = * ptrSrc;
|
||||
else if (aCode == CHAR_REF) { // character reference
|
||||
sprintf (ptrDest, "&#x%02x;", iSrc);
|
||||
ptrDest += 6;
|
||||
} else // predefined entity reference
|
||||
if (isAttribute == Standard_False && aCode == ENTI_QUOT)
|
||||
* ptrDest++ = * ptrSrc;
|
||||
else {
|
||||
memcpy (ptrDest, entity_ref[aCode].name, entity_ref[aCode].length+1);
|
||||
ptrDest += entity_ref[aCode].length;
|
||||
}
|
||||
}
|
||||
theLen = ptrDest - aDest;
|
||||
* ptrDest = '\0';
|
||||
}
|
||||
return aDest;
|
||||
}
|
||||
|
||||
int LDOM_CharReference::myTab [256] = {
|
||||
NORMAL_C, // 000
|
||||
CHAR_REF, // 001
|
||||
CHAR_REF, // 002
|
||||
CHAR_REF, // 003
|
||||
CHAR_REF, // 004
|
||||
CHAR_REF, // 005
|
||||
CHAR_REF, // 006
|
||||
CHAR_REF, // 007
|
||||
CHAR_REF, // 008
|
||||
NORMAL_C, // 009 TAB
|
||||
NORMAL_C, // 00a LF
|
||||
CHAR_REF, // 00b
|
||||
CHAR_REF, // 00c
|
||||
NORMAL_C, // 00d CR
|
||||
CHAR_REF, // 00e
|
||||
CHAR_REF, // 00f
|
||||
CHAR_REF, // 010
|
||||
CHAR_REF, // 011
|
||||
CHAR_REF, // 012
|
||||
CHAR_REF, // 013
|
||||
CHAR_REF, // 014
|
||||
CHAR_REF, // 015
|
||||
CHAR_REF, // 016
|
||||
CHAR_REF, // 017
|
||||
CHAR_REF, // 018
|
||||
CHAR_REF, // 019
|
||||
CHAR_REF, // 01a
|
||||
CHAR_REF, // 01b
|
||||
CHAR_REF, // 01c
|
||||
CHAR_REF, // 01d
|
||||
CHAR_REF, // 01e
|
||||
CHAR_REF, // 01f
|
||||
NORMAL_C, // 020:
|
||||
NORMAL_C, // 021: !
|
||||
ENTI_QUOT, // 022: "
|
||||
NORMAL_C, // 023: #
|
||||
NORMAL_C, // 024: $
|
||||
NORMAL_C, // 025: %
|
||||
ENTI_AMP, // 026: &
|
||||
// ENTI_APOS, // 027: ' Here we do never use apostrophe as delimiter
|
||||
NORMAL_C, // 027: '
|
||||
NORMAL_C, // 028: (
|
||||
NORMAL_C, // 029: )
|
||||
NORMAL_C, // 02a: *
|
||||
NORMAL_C, // 02b: +
|
||||
NORMAL_C, // 02c: ,
|
||||
NORMAL_C, // 02d: -
|
||||
NORMAL_C, // 02e: .
|
||||
NORMAL_C, // 02f: /
|
||||
NORMAL_C, // 030: 0
|
||||
NORMAL_C, // 031: 1
|
||||
NORMAL_C, // 032: 2
|
||||
NORMAL_C, // 033: 3
|
||||
NORMAL_C, // 034: 4
|
||||
NORMAL_C, // 035: 5
|
||||
NORMAL_C, // 036: 6
|
||||
NORMAL_C, // 037: 7
|
||||
NORMAL_C, // 038: 8
|
||||
NORMAL_C, // 039: 9
|
||||
NORMAL_C, // 03a: :
|
||||
NORMAL_C, // 03b: ;
|
||||
ENTI_LT, // 03c: <
|
||||
NORMAL_C, // 03d: =
|
||||
ENTI_GT, // 03e: >
|
||||
NORMAL_C, // 03f: ?
|
||||
NORMAL_C, // 040: @
|
||||
NORMAL_C, // 041: A
|
||||
NORMAL_C, // 042: B
|
||||
NORMAL_C, // 043: C
|
||||
NORMAL_C, // 044: D
|
||||
NORMAL_C, // 045: E
|
||||
NORMAL_C, // 046: F
|
||||
NORMAL_C, // 047: G
|
||||
NORMAL_C, // 048: H
|
||||
NORMAL_C, // 049: I
|
||||
NORMAL_C, // 04a: J
|
||||
NORMAL_C, // 04b: K
|
||||
NORMAL_C, // 04c: L
|
||||
NORMAL_C, // 04d: M
|
||||
NORMAL_C, // 04e: N
|
||||
NORMAL_C, // 04f: O
|
||||
NORMAL_C, // 050: P
|
||||
NORMAL_C, // 051: Q
|
||||
NORMAL_C, // 052: R
|
||||
NORMAL_C, // 053: S
|
||||
NORMAL_C, // 054: T
|
||||
NORMAL_C, // 055: U
|
||||
NORMAL_C, // 056: V
|
||||
NORMAL_C, // 057: W
|
||||
NORMAL_C, // 058: X
|
||||
NORMAL_C, // 059: Y
|
||||
NORMAL_C, // 05a: Z
|
||||
NORMAL_C, // 05b: [
|
||||
NORMAL_C, // 05c: \
|
||||
NORMAL_C, // 05d: ]
|
||||
NORMAL_C, // 05e: ^
|
||||
NORMAL_C, // 05f: _
|
||||
NORMAL_C, // 060: `
|
||||
NORMAL_C, // 061: a
|
||||
NORMAL_C, // 062: b
|
||||
NORMAL_C, // 063: c
|
||||
NORMAL_C, // 064: d
|
||||
NORMAL_C, // 065: e
|
||||
NORMAL_C, // 066: f
|
||||
NORMAL_C, // 067: g
|
||||
NORMAL_C, // 068: h
|
||||
NORMAL_C, // 069: i
|
||||
NORMAL_C, // 06a: j
|
||||
NORMAL_C, // 06b: k
|
||||
NORMAL_C, // 06c: l
|
||||
NORMAL_C, // 06d: m
|
||||
NORMAL_C, // 06e: n
|
||||
NORMAL_C, // 06f: o
|
||||
NORMAL_C, // 070: p
|
||||
NORMAL_C, // 071: q
|
||||
NORMAL_C, // 072: r
|
||||
NORMAL_C, // 073: s
|
||||
NORMAL_C, // 074: t
|
||||
NORMAL_C, // 075: u
|
||||
NORMAL_C, // 076: v
|
||||
NORMAL_C, // 077: w
|
||||
NORMAL_C, // 078: x
|
||||
NORMAL_C, // 079: y
|
||||
NORMAL_C, // 07a: z
|
||||
NORMAL_C, // 07b: {
|
||||
NORMAL_C, // 07c: |
|
||||
NORMAL_C, // 07d: }
|
||||
NORMAL_C, // 07e: ~
|
||||
NORMAL_C, // 07f:
|
||||
CHAR_REF, // 080
|
||||
CHAR_REF, // 081
|
||||
CHAR_REF, // 082
|
||||
CHAR_REF, // 083
|
||||
CHAR_REF, // 084
|
||||
CHAR_REF, // 085
|
||||
CHAR_REF, // 086
|
||||
CHAR_REF, // 087
|
||||
CHAR_REF, // 088
|
||||
CHAR_REF, // 089
|
||||
CHAR_REF, // 08a
|
||||
CHAR_REF, // 08b
|
||||
CHAR_REF, // 08c
|
||||
CHAR_REF, // 08d
|
||||
CHAR_REF, // 08e
|
||||
CHAR_REF, // 08f
|
||||
CHAR_REF, // 090
|
||||
CHAR_REF, // 091
|
||||
CHAR_REF, // 092
|
||||
CHAR_REF, // 093
|
||||
CHAR_REF, // 094
|
||||
CHAR_REF, // 095
|
||||
CHAR_REF, // 096
|
||||
CHAR_REF, // 097
|
||||
CHAR_REF, // 098
|
||||
CHAR_REF, // 099
|
||||
CHAR_REF, // 09a
|
||||
CHAR_REF, // 09b
|
||||
CHAR_REF, // 09c
|
||||
CHAR_REF, // 09d
|
||||
CHAR_REF, // 09e
|
||||
CHAR_REF, // 09f
|
||||
CHAR_REF, // 0a0
|
||||
CHAR_REF, // 0a1
|
||||
CHAR_REF, // 0a2
|
||||
CHAR_REF, // 0a3
|
||||
CHAR_REF, // 0a4
|
||||
CHAR_REF, // 0a5
|
||||
CHAR_REF, // 0a6
|
||||
CHAR_REF, // 0a7
|
||||
CHAR_REF, // 0a8
|
||||
CHAR_REF, // 0a9
|
||||
CHAR_REF, // 0aa
|
||||
CHAR_REF, // 0ab
|
||||
CHAR_REF, // 0ac
|
||||
CHAR_REF, // 0ad
|
||||
CHAR_REF, // 0ae
|
||||
CHAR_REF, // 0af
|
||||
CHAR_REF, // 0b0
|
||||
CHAR_REF, // 0b1
|
||||
CHAR_REF, // 0b2
|
||||
CHAR_REF, // 0b3
|
||||
CHAR_REF, // 0b4
|
||||
CHAR_REF, // 0b5
|
||||
CHAR_REF, // 0b6
|
||||
CHAR_REF, // 0b7
|
||||
CHAR_REF, // 0b8
|
||||
CHAR_REF, // 0b9
|
||||
CHAR_REF, // 0ba
|
||||
CHAR_REF, // 0bb
|
||||
CHAR_REF, // 0bc
|
||||
CHAR_REF, // 0bd
|
||||
CHAR_REF, // 0be
|
||||
CHAR_REF, // 0bf
|
||||
#ifdef LDOM_ALLOW_LATIN_1
|
||||
NORMAL_C, // 0c0
|
||||
NORMAL_C, // 0c1
|
||||
NORMAL_C, // 0c2
|
||||
NORMAL_C, // 0c3
|
||||
NORMAL_C, // 0c4
|
||||
NORMAL_C, // 0c5
|
||||
NORMAL_C, // 0c6
|
||||
NORMAL_C, // 0c7
|
||||
NORMAL_C, // 0c8
|
||||
NORMAL_C, // 0c9
|
||||
NORMAL_C, // 0ca
|
||||
NORMAL_C, // 0cb
|
||||
NORMAL_C, // 0cc
|
||||
NORMAL_C, // 0cd
|
||||
NORMAL_C, // 0ce
|
||||
NORMAL_C, // 0cf
|
||||
NORMAL_C, // 0d0
|
||||
NORMAL_C, // 0d1
|
||||
NORMAL_C, // 0d2
|
||||
NORMAL_C, // 0d3
|
||||
NORMAL_C, // 0d4
|
||||
NORMAL_C, // 0d5
|
||||
NORMAL_C, // 0d6
|
||||
// CHAR_REF, // 0d7
|
||||
NORMAL_C, // 0d7
|
||||
NORMAL_C, // 0d8
|
||||
NORMAL_C, // 0d9
|
||||
NORMAL_C, // 0da
|
||||
NORMAL_C, // 0db
|
||||
NORMAL_C, // 0dc
|
||||
NORMAL_C, // 0dd
|
||||
NORMAL_C, // 0de
|
||||
NORMAL_C, // 0df
|
||||
NORMAL_C, // 0e0
|
||||
NORMAL_C, // 0e1
|
||||
NORMAL_C, // 0e2
|
||||
NORMAL_C, // 0e3
|
||||
NORMAL_C, // 0e4
|
||||
NORMAL_C, // 0e5
|
||||
NORMAL_C, // 0e6
|
||||
NORMAL_C, // 0e7
|
||||
NORMAL_C, // 0e8
|
||||
NORMAL_C, // 0e9
|
||||
NORMAL_C, // 0ea
|
||||
NORMAL_C, // 0eb
|
||||
NORMAL_C, // 0ec
|
||||
NORMAL_C, // 0ed
|
||||
NORMAL_C, // 0ee
|
||||
NORMAL_C, // 0ef
|
||||
NORMAL_C, // 0f0
|
||||
NORMAL_C, // 0f1
|
||||
NORMAL_C, // 0f2
|
||||
NORMAL_C, // 0f3
|
||||
NORMAL_C, // 0f4
|
||||
NORMAL_C, // 0f5
|
||||
NORMAL_C, // 0f6
|
||||
// CHAR_REF, // 0f7
|
||||
NORMAL_C, // 0f7
|
||||
NORMAL_C, // 0f8
|
||||
NORMAL_C, // 0f9
|
||||
NORMAL_C, // 0fa
|
||||
NORMAL_C, // 0fb
|
||||
NORMAL_C, // 0fc
|
||||
NORMAL_C, // 0fd
|
||||
NORMAL_C, // 0fe
|
||||
NORMAL_C // 0ff
|
||||
#else
|
||||
CHAR_REF, // 0c0
|
||||
CHAR_REF, // 0c1
|
||||
CHAR_REF, // 0c2
|
||||
CHAR_REF, // 0c3
|
||||
CHAR_REF, // 0c4
|
||||
CHAR_REF, // 0c5
|
||||
CHAR_REF, // 0c6
|
||||
CHAR_REF, // 0c7
|
||||
CHAR_REF, // 0c8
|
||||
CHAR_REF, // 0c9
|
||||
CHAR_REF, // 0ca
|
||||
CHAR_REF, // 0cb
|
||||
CHAR_REF, // 0cc
|
||||
CHAR_REF, // 0cd
|
||||
CHAR_REF, // 0ce
|
||||
CHAR_REF, // 0cf
|
||||
CHAR_REF, // 0d0
|
||||
CHAR_REF, // 0d1
|
||||
CHAR_REF, // 0d2
|
||||
CHAR_REF, // 0d3
|
||||
CHAR_REF, // 0d4
|
||||
CHAR_REF, // 0d5
|
||||
CHAR_REF, // 0d6
|
||||
CHAR_REF, // 0d7
|
||||
CHAR_REF, // 0d8
|
||||
CHAR_REF, // 0d9
|
||||
CHAR_REF, // 0da
|
||||
CHAR_REF, // 0db
|
||||
CHAR_REF, // 0dc
|
||||
CHAR_REF, // 0dd
|
||||
CHAR_REF, // 0de
|
||||
CHAR_REF, // 0df
|
||||
CHAR_REF, // 0e0
|
||||
CHAR_REF, // 0e1
|
||||
CHAR_REF, // 0e2
|
||||
CHAR_REF, // 0e3
|
||||
CHAR_REF, // 0e4
|
||||
CHAR_REF, // 0e5
|
||||
CHAR_REF, // 0e6
|
||||
CHAR_REF, // 0e7
|
||||
CHAR_REF, // 0e8
|
||||
CHAR_REF, // 0e9
|
||||
CHAR_REF, // 0ea
|
||||
CHAR_REF, // 0eb
|
||||
CHAR_REF, // 0ec
|
||||
CHAR_REF, // 0ed
|
||||
CHAR_REF, // 0ee
|
||||
CHAR_REF, // 0ef
|
||||
CHAR_REF, // 0f0
|
||||
CHAR_REF, // 0f1
|
||||
CHAR_REF, // 0f2
|
||||
CHAR_REF, // 0f3
|
||||
CHAR_REF, // 0f4
|
||||
CHAR_REF, // 0f5
|
||||
CHAR_REF, // 0f6
|
||||
CHAR_REF, // 0f7
|
||||
CHAR_REF, // 0f8
|
||||
CHAR_REF, // 0f9
|
||||
CHAR_REF, // 0fa
|
||||
CHAR_REF, // 0fb
|
||||
CHAR_REF, // 0fc
|
||||
CHAR_REF, // 0fd
|
||||
CHAR_REF, // 0fe
|
||||
CHAR_REF // 0ff
|
||||
#endif // LDOM_ALLOW_LATIN_1
|
||||
};
|
55
src/LDOM/LDOM_CharReference.hxx
Executable file
55
src/LDOM/LDOM_CharReference.hxx
Executable file
@@ -0,0 +1,55 @@
|
||||
// File: LDOM_CharReference.hxx
|
||||
// Created: 08.02.02 19:53:39
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: Open Cascade 2001
|
||||
|
||||
|
||||
#ifndef LDOM_CharReference_HeaderFile
|
||||
#define LDOM_CharReference_HeaderFile
|
||||
|
||||
#include <Standard_TypeDef.hxx>
|
||||
|
||||
// Class LDOM_CharReference: treatment of character reference and internal
|
||||
// entities in input and output streams
|
||||
//
|
||||
// On output all 256 characters are classified as this:
|
||||
// For string values of attributes:
|
||||
// 0x09,0x0a,0x0d,0x20,0x21,0x23-0x25,0x27-0x3b,0x3d,0x3f-0x7f,0xc0-0xff
|
||||
// are treated as normal characters (no relacement)
|
||||
// 0x22("e;), 0x26(&), 0x3c(<), 0x3e(>)
|
||||
// are replaced by predefined entity reference.
|
||||
// 0x01-0x08,0x0b,0x0c,0x0e-0x1f,0x80-0xbf
|
||||
// are replaced by character references
|
||||
// For other strings (text):
|
||||
// 0x09,0x0a,0x0d,0x20-0x25,0x27-0x3b,0x3d,0x3f-0x7f,0xc0-0xff
|
||||
// are treated as normal characters (no relacement)
|
||||
// 0x26(&), 0x3c(<), 0x3e(>)
|
||||
// are replaced by predefined entity reference.
|
||||
// 0x01-0x08,0x0b,0x0c,0x0e-0x1f,0x80-0xbf
|
||||
// are replaced by character references
|
||||
// For CDATA, element tag names and attribute names no replacements are made
|
||||
// Note that apostrophe (\') is not treated as markup on output (all relevant
|
||||
// markup is produced by quote characters (\")).
|
||||
|
||||
class LDOM_CharReference
|
||||
{
|
||||
public:
|
||||
// ---------- PUBLIC METHODS ----------
|
||||
|
||||
static char * Decode (char * theSrc, Standard_Integer& theLen);
|
||||
|
||||
static char * Encode (const char * theSrc, Standard_Integer& theLen,
|
||||
const Standard_Boolean isAttribute);
|
||||
// Encodes the string theSrc containing any byte characters 0x00-0xFF
|
||||
// Returns the encoded string. If (return value) != theSrc the returned
|
||||
// string should be deleted in caller routine (via delete[]).
|
||||
// The output parameter theLen gives the length of the encoded string
|
||||
// With isAttribute==True additionally encodes to $quot; for attr values
|
||||
|
||||
private:
|
||||
// ---------- PRIVATE FIELDS ----------
|
||||
|
||||
static int myTab [256];
|
||||
};
|
||||
|
||||
#endif
|
69
src/LDOM/LDOM_CharacterData.cxx
Executable file
69
src/LDOM/LDOM_CharacterData.cxx
Executable file
@@ -0,0 +1,69 @@
|
||||
// File: LDOM_CharacterData.cxx
|
||||
// Created: 12.09.01 15:05:37
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: Open Cascade 2001
|
||||
// History:
|
||||
|
||||
#include <LDOM_CharacterData.hxx>
|
||||
#include <LDOM_BasicText.hxx>
|
||||
#include <Standard_ProgramError.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : LDOM_CharacterData
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_CharacterData::LDOM_CharacterData (const LDOM_BasicText& aText,
|
||||
const Handle(LDOM_MemManager)& aDoc)
|
||||
: LDOM_Node (aText, aDoc), myLength (-1) {}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator =
|
||||
//purpose : Nullify
|
||||
//=======================================================================
|
||||
|
||||
LDOM_CharacterData& LDOM_CharacterData::operator = (const LDOM_NullPtr* theNull)
|
||||
{
|
||||
LDOM_Node::operator = (theNull);
|
||||
myLength = -1;
|
||||
return * this;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator =
|
||||
//purpose : Assignment
|
||||
//=======================================================================
|
||||
|
||||
LDOM_CharacterData& LDOM_CharacterData::operator =
|
||||
(const LDOM_CharacterData& theOther)
|
||||
{
|
||||
LDOM_Node::operator = (theOther);
|
||||
myLength = theOther.myLength;
|
||||
return * this;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : setData
|
||||
//purpose : replace the data
|
||||
//=======================================================================
|
||||
|
||||
void LDOM_CharacterData::setData (const LDOMString& theValue)
|
||||
{
|
||||
LDOM_BasicText& aText = (LDOM_BasicText&) Origin ();
|
||||
if (&aText == NULL)
|
||||
Standard_ProgramError::Raise("LDOM_CharacterData::setData: called on void");
|
||||
aText.SetData (theValue, myDocument);
|
||||
myLength = -1;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getLength
|
||||
//purpose : query the data length
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer LDOM_CharacterData::getLength () const
|
||||
{
|
||||
if (myLength < 0)
|
||||
(Standard_Integer&)myLength = strlen (getNodeValue().GetString());
|
||||
return myLength;
|
||||
}
|
58
src/LDOM/LDOM_CharacterData.hxx
Executable file
58
src/LDOM/LDOM_CharacterData.hxx
Executable file
@@ -0,0 +1,58 @@
|
||||
// File: LDOM_CharacterData.hxx
|
||||
// Created: 12.09.01 14:53:13
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: Open Cascade 2001
|
||||
|
||||
|
||||
#ifndef LDOM_CharacterData_HeaderFile
|
||||
#define LDOM_CharacterData_HeaderFile
|
||||
|
||||
#include <LDOM_Node.hxx>
|
||||
|
||||
class LDOM_BasicText;
|
||||
|
||||
// Class LDOM_CharacterData
|
||||
//
|
||||
|
||||
class LDOM_CharacterData : public LDOM_Node
|
||||
{
|
||||
public:
|
||||
// ---------- PUBLIC METHODS ----------
|
||||
|
||||
LDOM_CharacterData () : myLength (-1) {}
|
||||
// Empty constructor
|
||||
|
||||
LDOM_CharacterData (const LDOM_CharacterData& theOther)
|
||||
: LDOM_Node (theOther), myLength (-1) {}
|
||||
// Copy constructor
|
||||
|
||||
Standard_EXPORT LDOM_CharacterData&
|
||||
operator = (const LDOM_NullPtr * aNull);
|
||||
// Nullify
|
||||
|
||||
Standard_EXPORT LDOM_CharacterData&
|
||||
operator = (const LDOM_CharacterData& anOther);
|
||||
// Assignment
|
||||
|
||||
LDOMString getData () const { return getNodeValue(); }
|
||||
// Query data
|
||||
|
||||
Standard_EXPORT void setData (const LDOMString& aValue);
|
||||
// Assign to data
|
||||
|
||||
Standard_EXPORT Standard_Integer
|
||||
getLength () const;
|
||||
// Length of the string
|
||||
|
||||
protected:
|
||||
// ---------- PROTECTED METHODS ----------
|
||||
|
||||
LDOM_CharacterData (const LDOM_BasicText& aText,
|
||||
const Handle(LDOM_MemManager)& aDoc);
|
||||
private:
|
||||
// ------------ PRIVATE FIELDS -----------
|
||||
Standard_Integer myLength;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
42
src/LDOM/LDOM_Comment.hxx
Executable file
42
src/LDOM/LDOM_Comment.hxx
Executable file
@@ -0,0 +1,42 @@
|
||||
// File: LDOM_Comment.hxx
|
||||
// Created: 12.09.01 17:13:32
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: Open Cascade 2001
|
||||
|
||||
#ifndef LDOM_Comment_HeaderFile
|
||||
#define LDOM_Comment_HeaderFile
|
||||
|
||||
#include <LDOM_CharacterData.hxx>
|
||||
|
||||
// Class LDOM_Comment
|
||||
//
|
||||
|
||||
class LDOM_Comment : public LDOM_CharacterData
|
||||
{
|
||||
public:
|
||||
// ---------- PUBLIC METHODS ----------
|
||||
|
||||
LDOM_Comment () {}
|
||||
// Empty constructor
|
||||
|
||||
LDOM_Comment (const LDOM_Comment& theOther) : LDOM_CharacterData (theOther) {}
|
||||
// Copy constructor
|
||||
|
||||
LDOM_Comment& operator = (const LDOM_NullPtr * theNull)
|
||||
{ return (LDOM_Comment&) LDOM_CharacterData::operator = (theNull); }
|
||||
// Nullify
|
||||
|
||||
LDOM_Comment& operator = (const LDOM_Comment& theOther)
|
||||
{ return (LDOM_Comment&) LDOM_CharacterData::operator = (theOther); }
|
||||
// Assignment
|
||||
|
||||
protected:
|
||||
friend class LDOM_Document;
|
||||
// ---------- PROTECTED METHODS ----------
|
||||
|
||||
LDOM_Comment (const LDOM_BasicText& theText,
|
||||
const Handle(LDOM_MemManager)& theDoc)
|
||||
: LDOM_CharacterData (theText, theDoc) {}
|
||||
};
|
||||
|
||||
#endif
|
256
src/LDOM/LDOM_DeclareSequence.hxx
Executable file
256
src/LDOM/LDOM_DeclareSequence.hxx
Executable file
@@ -0,0 +1,256 @@
|
||||
// File: LH3D_DeclareSequence.hxx
|
||||
// Created: 29.01.01 15:36:46
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
|
||||
#ifndef _Sequence_Declare_HeaderFile
|
||||
#define _Sequence_Declare_HeaderFile
|
||||
|
||||
#ifndef _Standard_Macro_HeaderFile
|
||||
#include <Standard_Macro.hxx>
|
||||
#endif
|
||||
|
||||
// Declaration of Sequence (numbered list) class.
|
||||
// Remarks on the current implementation:
|
||||
//
|
||||
// 1. Methods First() and Last() added
|
||||
// 2. The method InsertAt(anIndex) replaces InsertBefore and InsertAfter.
|
||||
// This method never throws exception "OutOfRange". Its behaviour:
|
||||
// anIndex <= 1 => equivalent to Prepend()
|
||||
// anIndex > Length() => equivalent to Append()
|
||||
// else => equivalent to InsertBefore.
|
||||
|
||||
// *******************************************************************
|
||||
// use the following somewhere in a header file;
|
||||
// ClassName - name of the list class to create
|
||||
// Type - type of members of the list
|
||||
// *******************************************************************
|
||||
|
||||
#define DECLARE_SEQUENCE( ClassName, Type ) \
|
||||
\
|
||||
class ClassName { \
|
||||
public: \
|
||||
inline ClassName (); \
|
||||
inline ClassName (const ClassName& anOther); \
|
||||
inline ClassName& operator= (const ClassName& anOther); \
|
||||
inline Standard_Integer Length () const; \
|
||||
inline const Type& First () const; \
|
||||
inline const Type& Last () const; \
|
||||
inline const Type& Value (const Standard_Integer)const;\
|
||||
inline Type& ChangeValue (const Standard_Integer); \
|
||||
inline const Type& operator () (const Standard_Integer)const;\
|
||||
inline Type& operator () (const Standard_Integer); \
|
||||
\
|
||||
Standard_EXPORT virtual ~ClassName (); \
|
||||
Standard_EXPORT void Append (const Type& aVal); \
|
||||
Standard_EXPORT void Prepend (const Type& aVal); \
|
||||
Standard_EXPORT void InsertAt (const Standard_Integer, \
|
||||
const Type& aVal); \
|
||||
Standard_EXPORT void Clear (); \
|
||||
Standard_EXPORT void Remove (const Standard_Integer); \
|
||||
\
|
||||
private: \
|
||||
class Node { \
|
||||
private: \
|
||||
Type myValue; \
|
||||
Node * myPrev; \
|
||||
Node * myNext; \
|
||||
public: \
|
||||
Node (const Type& aValue, Node * aPrv, Node * aNxt) \
|
||||
: myValue (aValue), myPrev (aPrv), myNext (aNxt) {} \
|
||||
const Type& Value () const { return myValue; } \
|
||||
Type& ChangeValue () { return myValue; } \
|
||||
friend class ClassName; \
|
||||
}; \
|
||||
\
|
||||
Standard_EXPORT const void * FindItem (const Standard_Integer)const;\
|
||||
Standard_EXPORT void Assign (const ClassName& anOther); \
|
||||
\
|
||||
Node * myFirst; \
|
||||
Node * myLast; \
|
||||
Node * myCurrent; \
|
||||
Standard_Integer myICur; \
|
||||
Standard_Integer myLength; \
|
||||
}; \
|
||||
\
|
||||
inline ClassName::ClassName () : \
|
||||
myFirst (NULL), \
|
||||
myLast (NULL), \
|
||||
myCurrent (NULL), \
|
||||
myICur (0), \
|
||||
myLength (0) {} \
|
||||
\
|
||||
inline ClassName::ClassName (const ClassName& anOther) : \
|
||||
myFirst (NULL) \
|
||||
{ \
|
||||
Assign (anOther); \
|
||||
} \
|
||||
\
|
||||
inline ClassName& ClassName::operator= (const ClassName& anOther) \
|
||||
{ \
|
||||
Assign (anOther); \
|
||||
return * this; \
|
||||
} \
|
||||
\
|
||||
inline Standard_Integer ClassName::Length () const{ \
|
||||
return myLength; \
|
||||
} \
|
||||
\
|
||||
inline const Type& ClassName::First () const \
|
||||
{ \
|
||||
return myFirst -> Value (); /* exception if out of range */ \
|
||||
} \
|
||||
\
|
||||
inline const Type& ClassName::Last () const \
|
||||
{ \
|
||||
return myLast -> Value(); /* exception if out of range */ \
|
||||
} \
|
||||
\
|
||||
inline const Type& ClassName::Value (const Standard_Integer anI) const \
|
||||
{ \
|
||||
const Node * anItem = (const Node *) FindItem (anI); \
|
||||
return anItem -> Value (); /* exception if out of range */ \
|
||||
} \
|
||||
\
|
||||
inline Type& ClassName::ChangeValue (const Standard_Integer anI) \
|
||||
{ \
|
||||
Node * anItem = (Node *) FindItem (anI); \
|
||||
return anItem -> ChangeValue (); /* exception if out of range */ \
|
||||
} \
|
||||
\
|
||||
inline const Type& ClassName::operator() (const Standard_Integer anI) const \
|
||||
{ \
|
||||
return Value (anI); \
|
||||
} \
|
||||
\
|
||||
inline Type& ClassName::operator() (const Standard_Integer anI) \
|
||||
{ \
|
||||
return ChangeValue (anI); \
|
||||
} \
|
||||
|
||||
// *******************************************************************
|
||||
// use the following in a translation unit (*.cxx);
|
||||
//
|
||||
// *******************************************************************
|
||||
#define IMPLEMENT_SEQUENCE( ClassName, Type ) \
|
||||
const void * ClassName::FindItem (const Standard_Integer anI) const \
|
||||
{ \
|
||||
if (anI < 1 || anI > myLength) return NULL; \
|
||||
Standard_Integer aCounter; \
|
||||
Node * aCurrent = (Node *) myCurrent; \
|
||||
Standard_Boolean aDir (Standard_False); \
|
||||
if (aCurrent == NULL) { \
|
||||
aCurrent = myFirst; \
|
||||
aCounter = anI - 1; \
|
||||
aDir = Standard_True; \
|
||||
}else{ \
|
||||
aCounter = Abs (anI - myICur); \
|
||||
if (anI <= aCounter) { \
|
||||
aCurrent = myFirst; \
|
||||
aCounter = anI - 1; \
|
||||
aDir = Standard_True; \
|
||||
}else if (myLength - anI < aCounter) { \
|
||||
aCurrent = myLast; \
|
||||
aCounter = myLength - anI; \
|
||||
}else if (anI > myICur) \
|
||||
aDir = Standard_True; \
|
||||
} \
|
||||
if (aDir) \
|
||||
while (aCounter--) aCurrent = aCurrent -> myNext; \
|
||||
else \
|
||||
while (aCounter--) aCurrent = aCurrent -> myPrev; \
|
||||
(Standard_Integer&) myICur = anI; \
|
||||
(Node *&) myCurrent = aCurrent; \
|
||||
return aCurrent; \
|
||||
} \
|
||||
\
|
||||
ClassName::~ClassName () \
|
||||
{ \
|
||||
Clear (); \
|
||||
} \
|
||||
\
|
||||
void ClassName::Append (const Type& aVal) \
|
||||
{ \
|
||||
Node * anItem = new Node (aVal, myLast, NULL); \
|
||||
if (myLength == 0) \
|
||||
myFirst = anItem; \
|
||||
else \
|
||||
myLast -> myNext = anItem; \
|
||||
myLast = anItem; \
|
||||
myLength++; \
|
||||
} \
|
||||
\
|
||||
void ClassName::Prepend (const Type& aVal) \
|
||||
{ \
|
||||
Node * anItem = new Node (aVal, NULL, myFirst); \
|
||||
if (myLength == 0) \
|
||||
myLast = anItem; \
|
||||
else \
|
||||
myFirst -> myPrev = anItem; \
|
||||
myFirst = anItem; \
|
||||
myLength++; \
|
||||
if (myICur > 0) myICur++; \
|
||||
} \
|
||||
\
|
||||
void ClassName::InsertAt (const Standard_Integer anI, const Type& aVal) \
|
||||
{ \
|
||||
if (anI <= 1) Prepend (aVal); \
|
||||
else if (anI > myLength) Append (aVal); \
|
||||
else if (FindItem(anI)) { \
|
||||
Node * anItem = new Node (aVal, myCurrent -> myPrev, myCurrent); \
|
||||
myCurrent -> myPrev = anItem; \
|
||||
if (anItem -> myPrev) anItem -> myPrev -> myNext = anItem; \
|
||||
myLength++; \
|
||||
myICur++; \
|
||||
} else ; \
|
||||
} \
|
||||
\
|
||||
void ClassName::Clear () \
|
||||
{ \
|
||||
while (myFirst) { \
|
||||
Node * aCurr = myFirst -> myNext; \
|
||||
delete myFirst; \
|
||||
myFirst = aCurr; \
|
||||
} \
|
||||
myFirst = myLast = myCurrent = NULL; \
|
||||
myLength = 0; \
|
||||
myICur = 0; \
|
||||
} \
|
||||
\
|
||||
void ClassName::Remove (const Standard_Integer anI) \
|
||||
{ \
|
||||
Node * anItem = (Node *) FindItem (anI); \
|
||||
if (anItem) { \
|
||||
if (myCurrent -> myPrev) { \
|
||||
myCurrent -> myPrev -> myNext = myCurrent -> myNext; \
|
||||
} \
|
||||
if (myCurrent -> myNext) { \
|
||||
myCurrent -> myNext -> myPrev = myCurrent -> myPrev; \
|
||||
myCurrent = myCurrent -> myNext; \
|
||||
}else{ \
|
||||
myCurrent = myCurrent -> myPrev; \
|
||||
myICur--; \
|
||||
} \
|
||||
if (myFirst == anItem) myFirst = myFirst -> myNext; \
|
||||
if (myLast == anItem) myLast = myLast -> myPrev; \
|
||||
delete anItem; \
|
||||
myLength--; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
void ClassName::Assign (const ClassName& anOther) \
|
||||
{ \
|
||||
Clear (); \
|
||||
if (anOther.Length () == 0) return; \
|
||||
myFirst = new Node (anOther.First(), NULL, NULL); \
|
||||
Node * aPrevious = myFirst; \
|
||||
myLength = 1; \
|
||||
while (myLength < anOther.Length()) { \
|
||||
myLength++; \
|
||||
Node * aCurrent = new Node (anOther.Value(myLength), aPrevious, NULL); \
|
||||
aPrevious = aPrevious -> myNext = aCurrent; \
|
||||
} \
|
||||
myLast = aPrevious; \
|
||||
} \
|
||||
|
||||
#endif
|
185
src/LDOM/LDOM_Document.cxx
Executable file
185
src/LDOM/LDOM_Document.cxx
Executable file
@@ -0,0 +1,185 @@
|
||||
// File: LDOM_Document.cxx
|
||||
// Created: 26.06.01 10:18:05
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
// History:
|
||||
|
||||
|
||||
#include <LDOM_Document.hxx>
|
||||
#include <LDOM_MemManager.hxx>
|
||||
#include <LDOM_BasicElement.hxx>
|
||||
#include <LDOM_BasicText.hxx>
|
||||
|
||||
#define MEMORY_GRANULE 10000
|
||||
|
||||
//=======================================================================
|
||||
//function : LDOM_Document()
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Document::LDOM_Document ()
|
||||
{
|
||||
myMemManager = new LDOM_MemManager (MEMORY_GRANULE);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : LDOM_Document
|
||||
//purpose : Constructor to be used in LDOM_MemManager::Doc()
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Document::LDOM_Document (const LDOM_MemManager& aMemManager)
|
||||
{
|
||||
myMemManager = &aMemManager;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ~LDOM_Document
|
||||
//purpose : Destructor
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Document::~LDOM_Document ()
|
||||
{}
|
||||
|
||||
//=======================================================================
|
||||
//function : isNull
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean LDOM_Document::isNull () const
|
||||
{
|
||||
const LDOM_BasicElement * const aRootElement = myMemManager -> RootElement();
|
||||
if (aRootElement == NULL) return Standard_True;
|
||||
return aRootElement -> isNull();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getDocumentElement
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Element LDOM_Document::getDocumentElement () const
|
||||
{
|
||||
return LDOM_Element (* myMemManager -> RootElement(), myMemManager);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getElementsByTagName
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_NodeList LDOM_Document::getElementsByTagName
|
||||
(const LDOMString& theTagName) const
|
||||
{
|
||||
LDOM_NodeList aList (myMemManager);
|
||||
LDOM_BasicElement * anElem = (LDOM_BasicElement *)myMemManager->RootElement();
|
||||
const char * aTagString = theTagName.GetString();
|
||||
if (anElem) {
|
||||
// if (anElem -> GetTagName().equals(theTagName))
|
||||
if (strcmp (anElem -> GetTagName(), aTagString) == 0)
|
||||
aList.Append (* anElem);
|
||||
anElem -> AddElementsByTagName (aList, theTagName);
|
||||
}
|
||||
return aList;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : createDocument (static)
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Document LDOM_Document::createDocument (const LDOMString& theQualifiedName)
|
||||
{
|
||||
LDOM_Document aDoc;
|
||||
const char * aString = theQualifiedName.GetString();
|
||||
if (strlen(aString) == 0)
|
||||
aString = "document";
|
||||
aDoc.myMemManager -> myRootElement =
|
||||
& LDOM_BasicElement::Create (aString, strlen(aString), aDoc.myMemManager);
|
||||
return aDoc;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : createElement
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Element LDOM_Document::createElement (const LDOMString& theTagName)
|
||||
{
|
||||
const char * aTagString = theTagName.GetString();
|
||||
LDOM_BasicElement& aBasicElem = LDOM_BasicElement::Create (aTagString,
|
||||
strlen(aTagString),
|
||||
myMemManager);
|
||||
return LDOM_Element (aBasicElem, myMemManager);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : createTextNode
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Text LDOM_Document::createTextNode (const LDOMString& theData)
|
||||
{
|
||||
LDOM_BasicText& aBasicText
|
||||
= LDOM_BasicText::Create (LDOM_Node::TEXT_NODE,
|
||||
LDOMString (theData, myMemManager), myMemManager);
|
||||
return LDOM_Text (aBasicText, myMemManager);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : createCDATASection
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_CDATASection LDOM_Document::createCDATASection (const LDOMString& theData)
|
||||
{
|
||||
LDOM_BasicText& aBasicText =
|
||||
LDOM_BasicText::Create (LDOM_Node::CDATA_SECTION_NODE,
|
||||
LDOMString (theData, myMemManager), myMemManager);
|
||||
const LDOM_CDATASection aNewNode (aBasicText, myMemManager);
|
||||
aNewNode.SetValueClear(); // no use to beware markup characters
|
||||
return aNewNode;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : createComment
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Comment LDOM_Document::createComment (const LDOMString& theData)
|
||||
{
|
||||
LDOM_BasicText& aBasicText =
|
||||
LDOM_BasicText::Create (LDOM_Node::COMMENT_NODE,
|
||||
LDOMString (theData, myMemManager), myMemManager);
|
||||
return LDOM_Comment (aBasicText, myMemManager);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator =
|
||||
//purpose : Nullify
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Document& LDOM_Document::operator = (const LDOM_NullPtr *)
|
||||
{
|
||||
myMemManager = new LDOM_MemManager (MEMORY_GRANULE);
|
||||
return * this;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator ==
|
||||
//purpose : Compare to NULL
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean LDOM_Document::operator == (const LDOM_NullPtr *) const
|
||||
{
|
||||
return myMemManager -> RootElement() == NULL;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator !=
|
||||
//purpose : Compare to NULL
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean LDOM_Document::operator != (const LDOM_NullPtr *) const
|
||||
{
|
||||
return myMemManager -> RootElement() != NULL;
|
||||
}
|
97
src/LDOM/LDOM_Document.hxx
Executable file
97
src/LDOM/LDOM_Document.hxx
Executable file
@@ -0,0 +1,97 @@
|
||||
// File: LDOM_Document.hxx
|
||||
// Created: 25.06.01 12:41:02
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
|
||||
|
||||
#ifndef LDOM_Document_HeaderFile
|
||||
#define LDOM_Document_HeaderFile
|
||||
|
||||
#include <LDOM_Element.hxx>
|
||||
#include <Handle_LDOM_MemManager.hxx>
|
||||
#include <LDOM_Text.hxx>
|
||||
#include <LDOM_CDATASection.hxx>
|
||||
#include <LDOM_Comment.hxx>
|
||||
|
||||
// Class LDOM_Document
|
||||
//
|
||||
|
||||
class LDOM_Document
|
||||
{
|
||||
public:
|
||||
// ---------- PUBLIC METHODS ----------
|
||||
Standard_EXPORT LDOM_Document ();
|
||||
// Empty constructor
|
||||
|
||||
Standard_EXPORT LDOM_Document (const LDOM_MemManager& aMemManager);
|
||||
// Called by LDOM_MemManager::Doc()
|
||||
|
||||
// Standard_EXPORT LDOM_Document (const LDOM_Document& theOther);
|
||||
// Copy constructor
|
||||
|
||||
Standard_EXPORT ~LDOM_Document ();
|
||||
// Destructor
|
||||
|
||||
// ---- CREATE ----
|
||||
|
||||
static Standard_EXPORT LDOM_Document
|
||||
createDocument (const LDOMString& theQualifiedName);
|
||||
// Create an empty document
|
||||
|
||||
Standard_EXPORT LDOM_Element
|
||||
createElement (const LDOMString& theTagName);
|
||||
|
||||
// Standard_EXPORT LDOM_Element
|
||||
// createElementNS (const LDOMString& theNSuri,
|
||||
// const LDOMString& theQualName);
|
||||
|
||||
Standard_EXPORT LDOM_CDATASection
|
||||
createCDATASection (const LDOMString& theData);
|
||||
|
||||
Standard_EXPORT LDOM_Comment
|
||||
createComment (const LDOMString& theData);
|
||||
|
||||
Standard_EXPORT LDOM_Text
|
||||
createTextNode (const LDOMString& theData);
|
||||
|
||||
// ---- GET ----
|
||||
|
||||
Standard_EXPORT LDOM_Element
|
||||
getDocumentElement () const;
|
||||
|
||||
Standard_EXPORT LDOM_NodeList
|
||||
getElementsByTagName (const LDOMString& theTagName) const;
|
||||
|
||||
// ---- COMPARE ----
|
||||
|
||||
Standard_Boolean
|
||||
operator == (const LDOM_Document& anOther) const
|
||||
{ return myMemManager == anOther.myMemManager; }
|
||||
|
||||
Standard_Boolean
|
||||
operator != (const LDOM_Document& anOther) const
|
||||
{ return myMemManager != anOther.myMemManager; }
|
||||
|
||||
Standard_Boolean
|
||||
operator == (const LDOM_NullPtr *) const;
|
||||
Standard_Boolean
|
||||
operator != (const LDOM_NullPtr *) const;
|
||||
|
||||
Standard_EXPORT Standard_Boolean
|
||||
isNull () const;
|
||||
|
||||
// ---- UTIL ----
|
||||
|
||||
Standard_EXPORT LDOM_Document&
|
||||
operator = (const LDOM_NullPtr *);
|
||||
|
||||
private:
|
||||
friend class LDOM_LDOMImplementation;
|
||||
friend class LDOMString;
|
||||
friend class LDOM_Node;
|
||||
// ---------- PRIVATE FIELDS ----------
|
||||
|
||||
Handle(LDOM_MemManager) myMemManager;
|
||||
};
|
||||
|
||||
#endif
|
23
src/LDOM/LDOM_DocumentType.hxx
Executable file
23
src/LDOM/LDOM_DocumentType.hxx
Executable file
@@ -0,0 +1,23 @@
|
||||
// File: LDOM_DocumentType.hxx
|
||||
// Created: 28.06.01 09:42:54
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
|
||||
|
||||
#ifndef LDOM_DocumentType_HeaderFile
|
||||
#define LDOM_DocumentType_HeaderFile
|
||||
|
||||
// Block of comments describing class LDOM_DocumentType
|
||||
//
|
||||
|
||||
class LDOM_DocumentType
|
||||
{
|
||||
public:
|
||||
// ---------- PUBLIC METHODS ----------
|
||||
|
||||
LDOM_DocumentType () {}
|
||||
// Empty constructor
|
||||
|
||||
};
|
||||
|
||||
#endif
|
237
src/LDOM/LDOM_Element.cxx
Executable file
237
src/LDOM/LDOM_Element.cxx
Executable file
@@ -0,0 +1,237 @@
|
||||
// File: LDOM_Element.cxx
|
||||
// Created: 27.06.01 14:22:45
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
// History:
|
||||
|
||||
|
||||
#include <LDOM_MemManager.hxx>
|
||||
#include <LDOM_BasicElement.hxx>
|
||||
#include <LDOM_BasicAttribute.hxx>
|
||||
|
||||
#include <Standard_ProgramError.hxx>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
//=======================================================================
|
||||
//function : LDOM_Element
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Element::LDOM_Element (const LDOM_BasicElement& anElem,
|
||||
const Handle(LDOM_MemManager)& aDoc)
|
||||
: LDOM_Node (anElem, aDoc) {}
|
||||
|
||||
//=======================================================================
|
||||
//function : getAttribute
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOMString LDOM_Element::getAttribute (const LDOMString& aName) const
|
||||
{
|
||||
const LDOM_BasicElement& anElem = (const LDOM_BasicElement&) Origin();
|
||||
if (anElem.isNull()) return LDOMString ();
|
||||
if (myLastChild == NULL) {
|
||||
const LDOM_BasicNode * aNode = anElem.GetFirstChild();
|
||||
if (aNode && aNode -> getNodeType () != LDOM_Node::ATTRIBUTE_NODE)
|
||||
while (1) {
|
||||
const LDOM_BasicNode * aSibling = aNode -> GetSibling();
|
||||
if (aSibling == NULL)
|
||||
return LDOMString ();
|
||||
if (aSibling -> getNodeType () == LDOM_Node::ATTRIBUTE_NODE) {
|
||||
(const LDOM_BasicNode *&) myLastChild = aNode;
|
||||
break;
|
||||
}
|
||||
aNode = aSibling;
|
||||
}
|
||||
}
|
||||
const LDOM_BasicAttribute& anAttr = anElem.GetAttribute (aName, myLastChild);
|
||||
if (anAttr.isNull())
|
||||
return LDOMString ();
|
||||
return LDOMString (anAttr.GetValue(), myDocument -> Self());
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getAttributeNode
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Attr LDOM_Element::getAttributeNode (const LDOMString& aName) const
|
||||
{
|
||||
const LDOM_BasicElement& anElem = (const LDOM_BasicElement&) Origin();
|
||||
if (anElem.isNull()) return LDOM_Attr ();
|
||||
if (myLastChild == NULL) {
|
||||
const LDOM_BasicNode * aNode = anElem.GetFirstChild();
|
||||
if (aNode && aNode -> getNodeType () != LDOM_Node::ATTRIBUTE_NODE)
|
||||
while (1) {
|
||||
const LDOM_BasicNode * aSibling = aNode -> GetSibling();
|
||||
if (aSibling -> getNodeType () == LDOM_Node::ATTRIBUTE_NODE) {
|
||||
(const LDOM_BasicNode *&) myLastChild = aSibling;
|
||||
break;
|
||||
}
|
||||
if (aSibling == NULL)
|
||||
return LDOM_Attr ();
|
||||
aNode = aSibling;
|
||||
}
|
||||
}
|
||||
const LDOM_BasicAttribute& anAttr = anElem.GetAttribute (aName, myLastChild);
|
||||
return LDOM_Attr (anAttr, myDocument);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getElementsByTagName
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_NodeList LDOM_Element::getElementsByTagName
|
||||
(const LDOMString& theTagName) const
|
||||
{
|
||||
LDOM_NodeList aList (myDocument);
|
||||
if (isNull() == Standard_False) {
|
||||
const LDOM_BasicElement& anElem = (const LDOM_BasicElement&) Origin();
|
||||
// if (anElem.GetTagName().equals(theTagName))
|
||||
if (strcmp (anElem.GetTagName(), theTagName.GetString()) == 0)
|
||||
aList.Append (anElem);
|
||||
anElem.AddElementsByTagName (aList, theTagName);
|
||||
}
|
||||
return aList;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : setAttribute
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void LDOM_Element::setAttribute (const LDOMString& aName,const LDOMString& aVal)
|
||||
{
|
||||
LDOM_BasicElement& anElem = (LDOM_BasicElement&) Origin();
|
||||
if (anElem.isNull()) return;
|
||||
|
||||
myLastChild = anElem.AddAttribute (aName, LDOMString (aVal, myDocument),
|
||||
myDocument, myLastChild);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : setAttributeNode
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void LDOM_Element::setAttributeNode (const LDOM_Attr& aNewAttr)
|
||||
{
|
||||
setAttribute (aNewAttr.getName(), aNewAttr.getValue());
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : removeAttribute
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void LDOM_Element::removeAttribute (const LDOMString& aName)
|
||||
{
|
||||
const LDOM_BasicElement& anElem = (const LDOM_BasicElement&) Origin();
|
||||
if (anElem.isNull()) return;
|
||||
anElem.RemoveAttribute (aName, myLastChild);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetChildByTagName
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Element LDOM_Element::GetChildByTagName (const LDOMString& aTagName) const
|
||||
{
|
||||
// Verify preconditions
|
||||
LDOM_Element aVoidElement;
|
||||
if (isNull() || aTagName == NULL)
|
||||
return aVoidElement;
|
||||
|
||||
// Take the first child. If it doesn't match look for other ones in a loop
|
||||
LDOM_Node aChildNode = getFirstChild();
|
||||
while (aChildNode != NULL)
|
||||
{
|
||||
const LDOM_Node::NodeType aNodeType = aChildNode.getNodeType();
|
||||
if (aNodeType == LDOM_Node::ATTRIBUTE_NODE)
|
||||
break;
|
||||
if (aNodeType == LDOM_Node::ELEMENT_NODE)
|
||||
{
|
||||
LDOMString
|
||||
#ifdef DOM2_MODEL
|
||||
aNodeName = aChildNode.getLocalName(); // try DOM2/namespaces
|
||||
if (aNodeName == NULL)
|
||||
#endif
|
||||
aNodeName = aChildNode.getNodeName(); // use DOM1
|
||||
if (aNodeName.equals(aTagName))
|
||||
return (LDOM_Element&) aChildNode; // a match has been found
|
||||
}
|
||||
aChildNode = aChildNode.getNextSibling();
|
||||
}
|
||||
return aVoidElement;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetSiblingByTagName
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Element LDOM_Element::GetSiblingByTagName () const
|
||||
{
|
||||
// Verify preconditions
|
||||
LDOM_Element aVoidElement;
|
||||
if (isNull()) return aVoidElement;
|
||||
|
||||
LDOMString aTagName = getTagName();
|
||||
|
||||
// Take the first child. If it doesn't match look for other ones in a loop
|
||||
LDOM_Node aNextNode = getNextSibling();
|
||||
while (aNextNode != NULL)
|
||||
{
|
||||
const LDOM_Node::NodeType aNodeType = aNextNode.getNodeType();
|
||||
if (aNodeType == LDOM_Node::ATTRIBUTE_NODE)
|
||||
break;
|
||||
if (aNodeType == LDOM_Node::ELEMENT_NODE)
|
||||
{
|
||||
LDOM_Element aNextElement = (LDOM_Element&) aNextNode;
|
||||
if (aNextElement.getTagName().equals(aTagName))
|
||||
return aNextElement; // a match has been found
|
||||
}
|
||||
aNextNode = aNextNode.getNextSibling();
|
||||
}
|
||||
return aVoidElement;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ReplaceElement
|
||||
//purpose : Permanently replace the element erasing the old data though the
|
||||
// children are not erased.
|
||||
// If anOther belongs to different Document, full copy of all its
|
||||
// children is performed.
|
||||
//=======================================================================
|
||||
|
||||
void LDOM_Element::ReplaceElement (const LDOM_Element& anOther)
|
||||
{
|
||||
LDOM_BasicElement& anElem = (LDOM_BasicElement&) Origin();
|
||||
const LDOM_BasicElement& anOtherElem =
|
||||
(const LDOM_BasicElement&) anOther.Origin();
|
||||
if (myDocument == anOther.myDocument) {
|
||||
anElem.myTagName = anOtherElem.myTagName;
|
||||
anElem.myAttributeMask = anOtherElem.myAttributeMask;
|
||||
anElem.myFirstChild = anOtherElem.myFirstChild;
|
||||
(const LDOM_BasicNode *&) myLastChild = anOther.myLastChild;
|
||||
} else {
|
||||
anElem.ReplaceElement (anOtherElem, myDocument);
|
||||
(const LDOM_BasicNode *&) myLastChild = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetAttributesList
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_NodeList LDOM_Element::GetAttributesList () const
|
||||
{
|
||||
LDOM_NodeList aList (myDocument);
|
||||
const LDOM_BasicElement& anElem = (const LDOM_BasicElement&) Origin();
|
||||
anElem.AddAttributes (aList, myLastChild);
|
||||
return aList;
|
||||
}
|
85
src/LDOM/LDOM_Element.hxx
Executable file
85
src/LDOM/LDOM_Element.hxx
Executable file
@@ -0,0 +1,85 @@
|
||||
// File: LDOM_Element.hxx
|
||||
// Created: 26.06.01 12:39:31
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
|
||||
|
||||
#ifndef LDOM_Element_HeaderFile
|
||||
#define LDOM_Element_HeaderFile
|
||||
|
||||
#include <LDOM_Attr.hxx>
|
||||
#include <LDOM_NodeList.hxx>
|
||||
|
||||
class LDOMParser;
|
||||
class LDOM_BasicElement;
|
||||
|
||||
// Class LDOM_Element
|
||||
//
|
||||
|
||||
class LDOM_Element : public LDOM_Node
|
||||
{
|
||||
public:
|
||||
// ---------- PUBLIC METHODS ----------
|
||||
|
||||
LDOM_Element () {}
|
||||
// Empty constructor
|
||||
|
||||
LDOM_Element (const LDOM_Element& anOther) : LDOM_Node (anOther) {}
|
||||
// Copy constructor
|
||||
|
||||
LDOM_Element& operator = (const LDOM_Element& anOther)
|
||||
{ return (LDOM_Element&) LDOM_Node::operator = (anOther); }
|
||||
// Assignment
|
||||
|
||||
Standard_EXPORT LDOM_Element&
|
||||
operator = (const LDOM_NullPtr * aNull)
|
||||
{ return (LDOM_Element&) LDOM_Node::operator = (aNull); }
|
||||
// Nullify
|
||||
|
||||
LDOMString getTagName () const { return getNodeName(); }
|
||||
|
||||
Standard_EXPORT LDOMString
|
||||
getAttribute (const LDOMString& aName) const;
|
||||
|
||||
Standard_EXPORT LDOM_Attr
|
||||
getAttributeNode (const LDOMString& aName) const;
|
||||
|
||||
Standard_EXPORT LDOM_NodeList
|
||||
getElementsByTagName (const LDOMString& aName) const;
|
||||
|
||||
Standard_EXPORT void setAttribute (const LDOMString& aName,
|
||||
const LDOMString& aValue);
|
||||
|
||||
Standard_EXPORT void setAttributeNode(const LDOM_Attr& aNewAttr);
|
||||
|
||||
Standard_EXPORT void removeAttribute (const LDOMString& aName);
|
||||
|
||||
// AGV auxiliary API
|
||||
Standard_EXPORT LDOM_Element
|
||||
GetChildByTagName (const LDOMString& aTagName) const;
|
||||
|
||||
Standard_EXPORT LDOM_Element
|
||||
GetSiblingByTagName () const;
|
||||
|
||||
Standard_EXPORT void
|
||||
ReplaceElement (const LDOM_Element& anOther);
|
||||
// The old element is destroyed by the new one
|
||||
|
||||
Standard_EXPORT LDOM_NodeList
|
||||
GetAttributesList () const;
|
||||
|
||||
protected:
|
||||
friend class LDOM_Document;
|
||||
friend class LDOMParser;
|
||||
// ---------- PROTECTED METHODS ----------
|
||||
|
||||
LDOM_Element (const LDOM_BasicElement& anElem,
|
||||
const Handle(LDOM_MemManager)& aDoc);
|
||||
|
||||
private:
|
||||
// ---------- PRIVATE FIELDS ----------
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
21
src/LDOM/LDOM_LDOMImplementation.cxx
Executable file
21
src/LDOM/LDOM_LDOMImplementation.cxx
Executable file
@@ -0,0 +1,21 @@
|
||||
// File: LDOM_LDOMImplementation.cxx
|
||||
// Created: 28.06.01 09:36:21
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
// History:
|
||||
|
||||
#include <LDOM_LDOMImplementation.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : createDocument
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Document LDOM_LDOMImplementation::createDocument
|
||||
(const LDOMString& /*aNamespaceURI*/,
|
||||
const LDOMString& aQualifiedName,
|
||||
const LDOM_DocumentType& /*aDocType*/)
|
||||
{
|
||||
return LDOM_Document::createDocument (aQualifiedName);
|
||||
}
|
||||
|
30
src/LDOM/LDOM_LDOMImplementation.hxx
Executable file
30
src/LDOM/LDOM_LDOMImplementation.hxx
Executable file
@@ -0,0 +1,30 @@
|
||||
// File: LDOM_LDOMImplementation.hxx
|
||||
// Created: 28.06.01 09:30:17
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
|
||||
|
||||
#ifndef LDOM_LDOMImplementation_HeaderFile
|
||||
#define LDOM_LDOMImplementation_HeaderFile
|
||||
|
||||
#include <Standard_Type.hxx>
|
||||
#include <LDOM_Document.hxx>
|
||||
|
||||
class LDOM_DocumentType;
|
||||
|
||||
// Block of comments describing class LDOM_LDOMImplementation
|
||||
//
|
||||
|
||||
class LDOM_LDOMImplementation
|
||||
{
|
||||
public:
|
||||
// ---------- PUBLIC METHODS ----------
|
||||
|
||||
static Standard_EXPORT LDOM_Document createDocument
|
||||
(const LDOMString& aNamespaceURI,
|
||||
const LDOMString& aQualifiedName,
|
||||
const LDOM_DocumentType& aDocType);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
337
src/LDOM/LDOM_MemManager.cxx
Executable file
337
src/LDOM/LDOM_MemManager.cxx
Executable file
@@ -0,0 +1,337 @@
|
||||
// File: LDOM_MemManager.cxx
|
||||
// Created: 26.06.01 11:42:23
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
// History:
|
||||
|
||||
#include <LDOM_MemManager.hxx>
|
||||
#include <LDOMBasicString.hxx>
|
||||
|
||||
IMPLEMENT_STANDARD_HANDLE (LDOM_MemManager, MMgt_TShared)
|
||||
IMPLEMENT_STANDARD_RTTIEXT (LDOM_MemManager, MMgt_TShared)
|
||||
|
||||
#define HASH_MASK 255
|
||||
#define MINIMAL_ROOM 3
|
||||
|
||||
typedef unsigned char LDOM_HashValue; // allocating HASH_MASK integer
|
||||
|
||||
inline Standard_Integer convertBlockSize (const Standard_Integer aBlockSize)
|
||||
{
|
||||
return ((aBlockSize - 1) / sizeof(Standard_Integer)) + 1;
|
||||
}
|
||||
|
||||
inline Standard_Boolean compareStrings (char * const str,
|
||||
const char * theString,
|
||||
const Standard_Integer theLength)
|
||||
{
|
||||
// ** This is a bit dangerous (can override the boundary of allocated memory)
|
||||
// return (str[theLength] == '\0' &&
|
||||
// memcmp (str, theString, theLength) == 0);
|
||||
// ** This is a more stable (less performant) solution
|
||||
if (memcmp (str, theString, theLength)) return Standard_False;
|
||||
return (str[theLength] == '\0');
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : MemBlock::MemBlock
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline LDOM_MemManager::MemBlock::MemBlock (const Standard_Integer aSize,
|
||||
LDOM_MemManager::MemBlock * aFirst)
|
||||
: mySize (aSize), myNext (aFirst)
|
||||
{
|
||||
myFreeSpace = myBlock = new Standard_Integer [aSize];
|
||||
myEndBlock = myBlock + aSize;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : MemBlock::Allocate
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
inline void * LDOM_MemManager::MemBlock::Allocate (const Standard_Integer aSize)
|
||||
{
|
||||
void * aResult = NULL;
|
||||
if (aSize <= myEndBlock - myFreeSpace) {
|
||||
aResult = myFreeSpace;
|
||||
myFreeSpace += aSize;
|
||||
}
|
||||
return aResult;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : MemBlock::AllocateAndCheck
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void * LDOM_MemManager::MemBlock::AllocateAndCheck
|
||||
(const Standard_Integer aSize,
|
||||
const LDOM_MemManager::MemBlock *& aFirstWithoutRoom)
|
||||
{
|
||||
void * aResult = NULL;
|
||||
Standard_Integer aRoom = myEndBlock - myFreeSpace;
|
||||
if (aSize <= aRoom) {
|
||||
aResult = myFreeSpace;
|
||||
myFreeSpace += aSize;
|
||||
}
|
||||
if (aRoom < MINIMAL_ROOM) {
|
||||
if (aFirstWithoutRoom == NULL) aFirstWithoutRoom = this;
|
||||
} else
|
||||
aFirstWithoutRoom = NULL;
|
||||
return aResult;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ~MemBlock
|
||||
//purpose : Destructor
|
||||
//=======================================================================
|
||||
|
||||
LDOM_MemManager::MemBlock::~MemBlock ()
|
||||
{
|
||||
delete [] myBlock;
|
||||
delete myNext;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : HashTable
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
|
||||
LDOM_MemManager::HashTable::HashTable (/* const Standard_Integer aMask, */
|
||||
LDOM_MemManager& aMemManager)
|
||||
: myManager (aMemManager)
|
||||
{
|
||||
Standard_Integer m, nKeys = HASH_MASK + 1;
|
||||
/*
|
||||
Standard_Integer m = aMask;
|
||||
Standard_Integer nKeys = 1;
|
||||
while (m) {
|
||||
nKeys *= 2;
|
||||
m /= 2;
|
||||
}
|
||||
myMask = nKeys - 1;
|
||||
*/
|
||||
myTable = (TableItem *) myManager.Allocate (sizeof(TableItem) * nKeys);
|
||||
for (m = 0; m < nKeys; m += 2) {
|
||||
myTable[m].str = NULL;
|
||||
myTable[m].next = NULL;
|
||||
myTable[m+1].str = NULL;
|
||||
myTable[m+1].next = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Hash
|
||||
//purpose : CRC-16 hash function
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer LDOM_MemManager::HashTable::Hash (const char * aString,
|
||||
const Standard_Integer aLen)
|
||||
{
|
||||
static const unsigned int wCRC16a[16] =
|
||||
{
|
||||
0000000, 0140301, 0140601, 0000500,
|
||||
0141401, 0001700, 0001200, 0141101,
|
||||
0143001, 0003300, 0003600, 0143501,
|
||||
0002400, 0142701, 0142201, 0002100,
|
||||
};
|
||||
|
||||
static const unsigned int wCRC16b[16] =
|
||||
{
|
||||
0000000, 0146001, 0154001, 0012000,
|
||||
0170001, 0036000, 0024000, 0162001,
|
||||
0120001, 0066000, 0074000, 0132001,
|
||||
0050000, 0116001, 0104001, 0043000,
|
||||
};
|
||||
|
||||
unsigned int aCRC = 0;
|
||||
const unsigned char * aPtr = (const unsigned char *) aString;
|
||||
for (Standard_Integer i = aLen; i > 0; i--) {
|
||||
const unsigned int bTmp = aCRC ^ (const unsigned int) (* aPtr++);
|
||||
aCRC = ((aCRC >> 8) ^ wCRC16a[bTmp & 0x0F]) ^ wCRC16b[(bTmp >> 4) & 0x0F];
|
||||
}
|
||||
return Standard_Integer (aCRC & HASH_MASK /* myMask */);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : AddString
|
||||
//purpose : Add or find a string in the hash table
|
||||
//=======================================================================
|
||||
|
||||
const char * LDOM_MemManager::HashTable::AddString
|
||||
(const char * theString,
|
||||
const Standard_Integer theLen,
|
||||
Standard_Integer& theHashIndex)
|
||||
{
|
||||
const char * aResult = NULL;
|
||||
if (theString == NULL) return NULL;
|
||||
Standard_Integer aHashIndex = Hash (theString, theLen);
|
||||
TableItem * aNode = &myTable[aHashIndex];
|
||||
if (aNode -> str == NULL) {
|
||||
LDOM_HashValue * anAlloc = (LDOM_HashValue *)
|
||||
myManager.Allocate (theLen + 1 + sizeof(LDOM_HashValue));
|
||||
anAlloc[0] = LDOM_HashValue (aHashIndex);
|
||||
aNode -> str = (char *) &anAlloc[1];
|
||||
memcpy (aNode -> str, theString, theLen);
|
||||
aNode -> str [theLen] = '\0';
|
||||
aResult = aNode -> str;
|
||||
}else{
|
||||
if (compareStrings (aNode -> str, theString, theLen))
|
||||
aResult = aNode -> str;
|
||||
else
|
||||
while (aNode -> next) {
|
||||
aNode = aNode -> next;
|
||||
if (compareStrings (aNode -> str, theString, theLen)) {
|
||||
aResult = aNode -> str;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (aResult == NULL) {
|
||||
// Attention!!! We can make this allocation in a separate pool
|
||||
// improving performance
|
||||
aNode -> next = (TableItem *) myManager.Allocate (sizeof(TableItem));
|
||||
aNode = aNode -> next;
|
||||
LDOM_HashValue * anAlloc = (LDOM_HashValue *)
|
||||
myManager.Allocate (theLen + 1 + sizeof(LDOM_HashValue));
|
||||
anAlloc[0] = LDOM_HashValue (aHashIndex);
|
||||
aNode -> str = (char *) &anAlloc[1];
|
||||
memcpy (aNode -> str, theString, theLen);
|
||||
aNode -> str [theLen] = '\0';
|
||||
aResult = aNode -> str;
|
||||
aNode -> next = NULL;
|
||||
}
|
||||
}
|
||||
theHashIndex = aHashIndex;
|
||||
return aResult;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : LDOM_MemManager
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
|
||||
LDOM_MemManager::LDOM_MemManager (const Standard_Integer aBlockSize)
|
||||
: myRootElement (NULL),
|
||||
myFirstBlock (NULL),
|
||||
myFirstWithoutRoom (NULL),
|
||||
myBlockSize (convertBlockSize(aBlockSize)),
|
||||
myHashTable (NULL) {}
|
||||
|
||||
//=======================================================================
|
||||
//function : ~LDOM_MemManager
|
||||
//purpose : Destructor
|
||||
//=======================================================================
|
||||
|
||||
LDOM_MemManager::~LDOM_MemManager ()
|
||||
{
|
||||
#ifdef DEB
|
||||
Standard_Integer aSomme = 0, aCount = 0;
|
||||
MemBlock * aBlock = myFirstBlock;
|
||||
//FILE * out = fopen ("/tmp/dump","w");
|
||||
while (aBlock) {
|
||||
aCount ++;
|
||||
aSomme += aBlock -> mySize;
|
||||
// for (const Standard_Integer * aPtr = aBlock -> myBlock;
|
||||
// aPtr < aBlock -> myEndBlock; ) {
|
||||
// const char * aStr = (const char *) aPtr;
|
||||
// Standard_Integer aLen = strlen (aStr) + 1;
|
||||
// if (aLen > 1) fprintf (out, "%s\n", aStr);
|
||||
// aPtr += convertBlockSize (aLen);
|
||||
// }
|
||||
aBlock = aBlock -> Next();
|
||||
}
|
||||
if (aCount > 1)
|
||||
cout << ".. Destroying " << aCount << " LDOM memory allocations: "
|
||||
<< aSomme / 256 << " kB" << endl;
|
||||
//fclose (out);
|
||||
#endif
|
||||
delete myFirstBlock;
|
||||
if (myHashTable)
|
||||
delete myHashTable;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Allocate
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void * LDOM_MemManager::Allocate (const Standard_Integer theSize)
|
||||
{
|
||||
void * aResult = NULL;
|
||||
Standard_Integer aSize = convertBlockSize (theSize);
|
||||
|
||||
if (aSize >= myBlockSize) {
|
||||
myFirstBlock = new MemBlock (aSize, myFirstBlock);
|
||||
aResult = myFirstBlock -> Allocate (aSize);
|
||||
}else{
|
||||
MemBlock * aBlock = myFirstBlock;
|
||||
if (aBlock == NULL) {
|
||||
myFirstBlock = new MemBlock (myBlockSize, myFirstBlock);
|
||||
return myFirstBlock -> Allocate (aSize);
|
||||
}
|
||||
aResult = aBlock -> Allocate (aSize);
|
||||
if (aResult)
|
||||
return aResult;
|
||||
aBlock = aBlock -> Next();
|
||||
const MemBlock * aFirstWithoutRoom = NULL;
|
||||
while (aBlock != myFirstWithoutRoom) {
|
||||
aResult = aBlock -> AllocateAndCheck (aSize, aFirstWithoutRoom);
|
||||
if (aResult) break;
|
||||
aBlock = aBlock -> Next();
|
||||
}
|
||||
myFirstWithoutRoom = (MemBlock *&)aFirstWithoutRoom;
|
||||
if (aResult == NULL) {
|
||||
myFirstBlock = new MemBlock (myBlockSize, myFirstBlock);
|
||||
aResult = myFirstBlock -> Allocate (aSize);
|
||||
}
|
||||
}
|
||||
return aResult;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : HashedAllocate
|
||||
//purpose : Memory allocation with access via hash table. No new allocation
|
||||
// if already present
|
||||
//=======================================================================
|
||||
|
||||
const char * LDOM_MemManager::HashedAllocate (const char * theString,
|
||||
const Standard_Integer theLen,
|
||||
Standard_Integer& theHash)
|
||||
{
|
||||
if (myHashTable == NULL) myHashTable = new HashTable (* this);
|
||||
return myHashTable -> AddString (theString, theLen, theHash);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : HashedAllocate
|
||||
//purpose : Memory allocation with access via hash table. No new allocation
|
||||
// if already present
|
||||
//=======================================================================
|
||||
|
||||
void LDOM_MemManager::HashedAllocate (const char * aString,
|
||||
const Standard_Integer theLen,
|
||||
LDOMBasicString& theResult)
|
||||
{
|
||||
theResult.myType = LDOMBasicString::LDOM_AsciiHashed;
|
||||
Standard_Integer aDummy;
|
||||
const char * aHashedString = HashedAllocate (aString, theLen, aDummy);
|
||||
if (aHashedString != NULL)
|
||||
theResult.myVal.ptr = (void *) aHashedString;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : CompareStrings
|
||||
//purpose : Compare
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean LDOM_MemManager::CompareStrings
|
||||
(const char * theString,
|
||||
const Standard_Integer theHashValue,
|
||||
const char * theHashedStr)
|
||||
{
|
||||
if (((LDOM_HashValue *)theHashedStr)[-1] == LDOM_HashValue(theHashValue))
|
||||
if (!strcmp (theString, theHashedStr))
|
||||
return Standard_True;
|
||||
return Standard_False;
|
||||
}
|
122
src/LDOM/LDOM_MemManager.hxx
Executable file
122
src/LDOM/LDOM_MemManager.hxx
Executable file
@@ -0,0 +1,122 @@
|
||||
// File: LDOM_MemManager.hxx
|
||||
// Created: 26.06.01 11:30:08
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
|
||||
|
||||
#ifndef LDOM_MemManager_HeaderFile
|
||||
#define LDOM_MemManager_HeaderFile
|
||||
|
||||
#include <MMgt_TShared.hxx>
|
||||
#include <Standard_DefineHandle.hxx>
|
||||
#include <LDOM_Document.hxx>
|
||||
|
||||
class LDOM_BasicElement;
|
||||
|
||||
// Class LDOM_MemManager (underlying structure of LDOM_Document)
|
||||
//
|
||||
|
||||
class LDOM_MemManager : public MMgt_TShared
|
||||
{
|
||||
public:
|
||||
// ---------- PUBLIC METHODS ----------
|
||||
|
||||
Standard_EXPORT LDOM_MemManager (const Standard_Integer aBlockSize);
|
||||
// Constructor
|
||||
|
||||
Standard_EXPORT ~LDOM_MemManager ();
|
||||
// Destructor
|
||||
|
||||
Standard_EXPORT void * Allocate (const Standard_Integer aSize);
|
||||
// General Memory allocator
|
||||
|
||||
const char * HashedAllocate (const char * aString,
|
||||
const Standard_Integer theLen,
|
||||
Standard_Integer& theHash);
|
||||
// Memory allocation with access via hash table. No new allocation
|
||||
// if already present
|
||||
|
||||
void HashedAllocate (const char * aString,
|
||||
const Standard_Integer theLen,
|
||||
LDOMBasicString& theResult);
|
||||
// Memory allocation with access via hash table. No new allocation
|
||||
// if already present
|
||||
|
||||
static Standard_Integer Hash (const char * theString,
|
||||
const Standard_Integer theLen)
|
||||
{ return HashTable::Hash (theString, theLen); }
|
||||
|
||||
static Standard_Boolean CompareStrings(const char * theString,
|
||||
const Standard_Integer theHashValue,
|
||||
const char * theHashedStr);
|
||||
|
||||
LDOM_Document Doc () const
|
||||
{ return LDOM_Document (* this); }
|
||||
|
||||
const LDOM_MemManager& Self () const
|
||||
{ return * this; }
|
||||
|
||||
const LDOM_BasicElement * RootElement () const
|
||||
{ return myRootElement; }
|
||||
|
||||
private:
|
||||
friend class LDOM_Document;
|
||||
friend class LDOMParser;
|
||||
|
||||
// ---- CLASS MemBlock ----
|
||||
class MemBlock {
|
||||
friend class LDOM_MemManager;
|
||||
inline MemBlock (const Standard_Integer aSize, MemBlock * aFirst);
|
||||
inline void * Allocate (const Standard_Integer aSize);
|
||||
void * AllocateAndCheck (const Standard_Integer aSize, const MemBlock *&);
|
||||
~MemBlock ();
|
||||
MemBlock * Next () { return myNext; }
|
||||
|
||||
Standard_Integer mySize;
|
||||
Standard_Integer * myBlock;
|
||||
Standard_Integer * myEndBlock;
|
||||
Standard_Integer * myFreeSpace;
|
||||
MemBlock * myNext;
|
||||
};
|
||||
|
||||
// ---- CLASS HashTable ----
|
||||
class HashTable {
|
||||
friend class LDOM_MemManager;
|
||||
HashTable (/* const Standard_Integer theMask, */
|
||||
LDOM_MemManager& theMemManager);
|
||||
const char * AddString (const char * theString,
|
||||
const Standard_Integer theLen,
|
||||
Standard_Integer& theHashIndex);
|
||||
static Standard_Integer Hash(const char * theString,
|
||||
const Standard_Integer theLen);
|
||||
struct TableItem {
|
||||
char * str;
|
||||
struct TableItem * next;
|
||||
} * myTable;
|
||||
// Standard_Integer myMask;
|
||||
LDOM_MemManager& myManager;
|
||||
};
|
||||
|
||||
// ---- PROHIBITED (PRIVATE) METHODS ----
|
||||
LDOM_MemManager (const LDOM_MemManager& theOther);
|
||||
// Copy constructor
|
||||
|
||||
LDOM_MemManager& operator = (const LDOM_MemManager& theOther);
|
||||
// Assignment
|
||||
|
||||
// ---------- PRIVATE FIELDS ----------
|
||||
|
||||
const LDOM_BasicElement * myRootElement;
|
||||
MemBlock * myFirstBlock;
|
||||
MemBlock * myFirstWithoutRoom;
|
||||
Standard_Integer myBlockSize;
|
||||
HashTable * myHashTable;
|
||||
|
||||
public:
|
||||
// CASCADE RTTI
|
||||
DEFINE_STANDARD_RTTI (LDOM_MemManager)
|
||||
};
|
||||
|
||||
#include <Handle_LDOM_MemManager.hxx>
|
||||
|
||||
#endif
|
287
src/LDOM/LDOM_Node.cxx
Executable file
287
src/LDOM/LDOM_Node.cxx
Executable file
@@ -0,0 +1,287 @@
|
||||
// File: LDOM_Node.cxx
|
||||
// Created: 27.06.01 15:56:11
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
// History:
|
||||
|
||||
#include <LDOM_MemManager.hxx>
|
||||
#include <LDOM_BasicAttribute.hxx>
|
||||
#include <LDOM_BasicElement.hxx>
|
||||
#include <LDOM_BasicText.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : Origin
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const LDOM_BasicNode& LDOM_Node::Origin () const
|
||||
{
|
||||
if (myOrigin == NULL) {
|
||||
static LDOM_BasicNode aNullNode;
|
||||
return aNullNode;
|
||||
}
|
||||
return * myOrigin;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getOwnerDocument
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
const LDOM_MemManager& LDOM_Node::getOwnerDocument () const
|
||||
{
|
||||
return myDocument -> Self();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator =
|
||||
//purpose : Assignment
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Node& LDOM_Node::operator = (const LDOM_Node& theOther)
|
||||
{
|
||||
myDocument = theOther.myDocument;
|
||||
myOrigin = theOther.myOrigin;
|
||||
myLastChild = theOther.myLastChild;
|
||||
return * this;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator =
|
||||
//purpose : Nullify
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Node& LDOM_Node::operator = (const LDOM_NullPtr * /*aNull*/)
|
||||
{
|
||||
myDocument.Nullify();
|
||||
myOrigin = NULL;
|
||||
myLastChild = NULL;
|
||||
return * this;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : isNull
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean LDOM_Node::isNull () const
|
||||
{
|
||||
return myOrigin == NULL || myOrigin -> isNull();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator ==
|
||||
//purpose : Compare two Nodes
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean LDOM_Node::operator == (const LDOM_Node& anOther) const
|
||||
{
|
||||
if (isNull())
|
||||
return anOther.isNull();
|
||||
return myOrigin == anOther.myOrigin;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator !=
|
||||
//purpose : Compare two Nodes
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean LDOM_Node::operator != (const LDOM_Node& anOther) const
|
||||
{
|
||||
if (isNull())
|
||||
return !anOther.isNull();
|
||||
return myOrigin != anOther.myOrigin;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getNodeType
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Node::NodeType LDOM_Node::getNodeType () const
|
||||
{
|
||||
return myOrigin == NULL ? UNKNOWN : myOrigin -> getNodeType();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getNodeName
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOMString LDOM_Node::getNodeName () const
|
||||
{
|
||||
switch (getNodeType()) {
|
||||
case ELEMENT_NODE:
|
||||
{
|
||||
const LDOM_BasicElement& anElement= *(const LDOM_BasicElement *) myOrigin;
|
||||
return LDOMString::CreateDirectString (anElement.GetTagName(),
|
||||
myDocument -> Self());
|
||||
}
|
||||
case ATTRIBUTE_NODE:
|
||||
{
|
||||
const LDOM_BasicAttribute& anAttr= *(const LDOM_BasicAttribute*) myOrigin;
|
||||
return LDOMString::CreateDirectString (anAttr.GetName(),
|
||||
myDocument -> Self());
|
||||
}
|
||||
default: ;
|
||||
}
|
||||
return LDOMString ();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getNodeValue
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOMString LDOM_Node::getNodeValue () const
|
||||
{
|
||||
switch (getNodeType()) {
|
||||
case ATTRIBUTE_NODE:
|
||||
{
|
||||
const LDOM_BasicAttribute& anAttr= *(const LDOM_BasicAttribute*) myOrigin;
|
||||
return LDOMString (anAttr.GetValue(), myDocument -> Self());
|
||||
}
|
||||
case TEXT_NODE:
|
||||
case CDATA_SECTION_NODE:
|
||||
case COMMENT_NODE:
|
||||
{
|
||||
const LDOM_BasicText& aText = * (const LDOM_BasicText *) myOrigin;
|
||||
return LDOMString (aText.GetData(), myDocument -> Self());
|
||||
}
|
||||
default: ;
|
||||
}
|
||||
return LDOMString ();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getFirstChild
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Node LDOM_Node::getFirstChild () const
|
||||
{
|
||||
const NodeType aType = getNodeType ();
|
||||
if (aType == ELEMENT_NODE) {
|
||||
const LDOM_BasicElement& anElement = * (const LDOM_BasicElement *) myOrigin;
|
||||
const LDOM_BasicNode * aChild = anElement.GetFirstChild();
|
||||
if (aChild)
|
||||
if (aChild -> getNodeType() != LDOM_Node::ATTRIBUTE_NODE)
|
||||
return LDOM_Node (* aChild, myDocument);
|
||||
}
|
||||
return LDOM_Node ();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getLastChild
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Node LDOM_Node::getLastChild () const
|
||||
{
|
||||
const NodeType aType = getNodeType ();
|
||||
if (aType == ELEMENT_NODE) {
|
||||
if (myLastChild == NULL) {
|
||||
const LDOM_BasicElement& anElement = *(const LDOM_BasicElement*) myOrigin;
|
||||
(const LDOM_BasicNode *&) myLastChild = anElement.GetLastChild();
|
||||
}
|
||||
return LDOM_Node (* myLastChild, myDocument);
|
||||
}
|
||||
return LDOM_Node ();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getNextSibling
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Node LDOM_Node::getNextSibling () const
|
||||
{
|
||||
const LDOM_BasicNode * aSibling = myOrigin -> mySibling;
|
||||
if (aSibling)
|
||||
if (aSibling -> getNodeType () != ATTRIBUTE_NODE)
|
||||
return LDOM_Node (* aSibling, myDocument);
|
||||
return LDOM_Node ();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : removeChild
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void LDOM_Node::removeChild (const LDOM_Node& aChild)
|
||||
{
|
||||
const NodeType aType = getNodeType ();
|
||||
if (aType == ELEMENT_NODE) {
|
||||
const LDOM_BasicElement& anElement = * (LDOM_BasicElement *) myOrigin;
|
||||
if (aChild != NULL)
|
||||
anElement.RemoveChild (aChild.myOrigin);
|
||||
if (aChild.myOrigin == myLastChild)
|
||||
// myLastChild = anElement.GetLastChild();
|
||||
myLastChild = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : appendChild
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void LDOM_Node::appendChild (const LDOM_Node& aChild)
|
||||
{
|
||||
const NodeType aType = getNodeType ();
|
||||
if (aType == ELEMENT_NODE && aChild != NULL) {
|
||||
if (myLastChild) {
|
||||
aChild.myOrigin -> SetSibling (myLastChild -> mySibling);
|
||||
(const LDOM_BasicNode *&) myLastChild -> mySibling = aChild.myOrigin;
|
||||
}else{
|
||||
const LDOM_BasicElement& anElement = * (LDOM_BasicElement *) myOrigin;
|
||||
anElement.AppendChild (aChild.myOrigin, myLastChild);
|
||||
}
|
||||
myLastChild = aChild.myOrigin;
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : hasChildNodes
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean LDOM_Node::hasChildNodes () const
|
||||
{
|
||||
const NodeType aType = getNodeType ();
|
||||
if (aType == ELEMENT_NODE) {
|
||||
const LDOM_BasicElement& anElement = * (const LDOM_BasicElement *) myOrigin;
|
||||
const LDOM_BasicNode * aChild = anElement.GetFirstChild();
|
||||
if (aChild) return ! aChild -> isNull();
|
||||
}
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : SetValueClear
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void LDOM_Node::SetValueClear () const
|
||||
{
|
||||
LDOMBasicString * aValue = NULL;
|
||||
switch (getNodeType()) {
|
||||
case ATTRIBUTE_NODE:
|
||||
{
|
||||
const LDOM_BasicAttribute& anAttr= *(const LDOM_BasicAttribute*) myOrigin;
|
||||
aValue = (LDOMBasicString *) & anAttr.GetValue();
|
||||
break;
|
||||
}
|
||||
case TEXT_NODE:
|
||||
case CDATA_SECTION_NODE:
|
||||
case COMMENT_NODE:
|
||||
{
|
||||
const LDOM_BasicText& aText = * (const LDOM_BasicText *) myOrigin;
|
||||
aValue = (LDOMBasicString *) & aText.GetData();
|
||||
break;
|
||||
}
|
||||
default: return;
|
||||
}
|
||||
if (aValue -> Type() == LDOMBasicString::LDOM_AsciiDoc)
|
||||
aValue -> myType = LDOMBasicString::LDOM_AsciiDocClear;
|
||||
}
|
133
src/LDOM/LDOM_Node.hxx
Executable file
133
src/LDOM/LDOM_Node.hxx
Executable file
@@ -0,0 +1,133 @@
|
||||
// File: LDOM_Node.hxx
|
||||
// Created: 26.06.01 14:40:53
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
// History: AGV 120202: Replace myDocument for myPtrDocument for better
|
||||
// consistency of data
|
||||
|
||||
#ifndef LDOM_Node_HeaderFile
|
||||
#define LDOM_Node_HeaderFile
|
||||
|
||||
#include <Standard_Macro.hxx>
|
||||
#include <Standard_TypeDef.hxx>
|
||||
#include <Handle_LDOM_MemManager.hxx>
|
||||
#include <LDOMString.hxx>
|
||||
|
||||
class LDOM_BasicNode;
|
||||
|
||||
// LDOM_Node : base class for LDOM interface objects
|
||||
// references LDOM_BasicNode - the real data stored in Document
|
||||
// This type can be safely cast to any derived type, e.g. :
|
||||
// LDOM_Node aNode = MyGetElementNode();
|
||||
// LDOM_Element& anElemNode = (LDOM_Element&) aNode;
|
||||
// LDOMString anXcoord = anElemNode.getAtttribute("x");
|
||||
|
||||
class LDOM_Node
|
||||
{
|
||||
public:
|
||||
enum NodeType {
|
||||
UNKNOWN = 0,
|
||||
ELEMENT_NODE = 1,
|
||||
ATTRIBUTE_NODE = 2,
|
||||
TEXT_NODE = 3,
|
||||
CDATA_SECTION_NODE = 4,
|
||||
COMMENT_NODE = 8
|
||||
};
|
||||
|
||||
// ---------- PUBLIC METHODS ----------
|
||||
|
||||
LDOM_Node () : myOrigin (NULL),
|
||||
myLastChild (NULL) {}
|
||||
// Empty constructor
|
||||
|
||||
LDOM_Node (const LDOM_Node& anOther)
|
||||
: myDocument (anOther.myDocument),
|
||||
myOrigin (anOther.myOrigin),
|
||||
myLastChild (anOther.myLastChild) {}
|
||||
// Copy constructor
|
||||
|
||||
Standard_EXPORT const LDOM_MemManager& getOwnerDocument () const;
|
||||
|
||||
Standard_EXPORT LDOM_Node&
|
||||
operator = (const LDOM_Node& anOther);
|
||||
|
||||
Standard_EXPORT LDOM_Node&
|
||||
operator = (const LDOM_NullPtr * aNull);
|
||||
|
||||
Standard_Boolean operator == (const LDOM_NullPtr *) const
|
||||
{ return isNull(); }
|
||||
|
||||
Standard_Boolean operator != (const LDOM_NullPtr *) const
|
||||
{ return ! isNull(); }
|
||||
|
||||
Standard_EXPORT Standard_Boolean
|
||||
operator == (const LDOM_Node& anOther) const;
|
||||
|
||||
Standard_EXPORT Standard_Boolean
|
||||
operator != (const LDOM_Node& anOther) const;
|
||||
|
||||
Standard_EXPORT Standard_Boolean
|
||||
isNull () const;
|
||||
|
||||
Standard_EXPORT NodeType
|
||||
getNodeType () const;
|
||||
|
||||
Standard_EXPORT LDOMString
|
||||
getNodeName () const;
|
||||
|
||||
Standard_EXPORT LDOMString
|
||||
getNodeValue () const;
|
||||
|
||||
Standard_EXPORT LDOM_Node
|
||||
getFirstChild () const;
|
||||
|
||||
Standard_EXPORT LDOM_Node
|
||||
getLastChild () const;
|
||||
|
||||
Standard_EXPORT LDOM_Node
|
||||
getNextSibling () const;
|
||||
|
||||
Standard_EXPORT void removeChild (const LDOM_Node& aChild);
|
||||
|
||||
Standard_EXPORT void appendChild (const LDOM_Node& aChild);
|
||||
|
||||
Standard_EXPORT Standard_Boolean
|
||||
hasChildNodes () const;
|
||||
|
||||
Standard_EXPORT void SetValueClear () const;
|
||||
// Avoids checking for '<', '&', '\'', '\"', etc. on storage (saves time)
|
||||
// You MUST be pretty sure that the node value string is OK in this sense
|
||||
// NEVER call this method if you are not stuck on the performance
|
||||
|
||||
protected:
|
||||
friend class LDOM_BasicAttribute;
|
||||
friend class LDOM_BasicElement;
|
||||
friend class LDOM_BasicText;
|
||||
friend class LDOM_NodeList;
|
||||
// ---------- PROTECTED METHODS ----------
|
||||
|
||||
const LDOM_BasicNode& Origin () const;
|
||||
|
||||
LDOM_Node (const LDOM_BasicNode& anOrig, const Handle(LDOM_MemManager)& aDoc)
|
||||
: myDocument (aDoc),
|
||||
myOrigin ((LDOM_BasicNode *) &anOrig),
|
||||
myLastChild (NULL) {}
|
||||
// Copy constructor with assignment to Document
|
||||
|
||||
protected:
|
||||
// ---------- PROTECTED FIELDS ----------
|
||||
|
||||
// smart pointer to document owner of the node
|
||||
Handle(LDOM_MemManager) myDocument;
|
||||
|
||||
// pointer to (non-transient) node data in the document-managed memory
|
||||
LDOM_BasicNode * myOrigin;
|
||||
|
||||
// Transient data (only applicable to LDOM_Element type):
|
||||
// the last child; myLastChild->mySibling points to the first attribute
|
||||
const LDOM_BasicNode * myLastChild;
|
||||
|
||||
friend char * db_pretty_print (const LDOM_Node *, int, char *);
|
||||
};
|
||||
|
||||
#endif
|
134
src/LDOM/LDOM_NodeList.cxx
Executable file
134
src/LDOM/LDOM_NodeList.cxx
Executable file
@@ -0,0 +1,134 @@
|
||||
// File: LDOM_NodeList.cxx
|
||||
// Created: 28.06.01 15:05:19
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
// History:
|
||||
|
||||
#include <LDOM_DeclareSequence.hxx>
|
||||
#include <LDOM_NodeList.hxx>
|
||||
#include <LDOM_BasicNode.hxx>
|
||||
|
||||
typedef const LDOM_BasicNode * LDOM_BasicNodePtr;
|
||||
|
||||
DECLARE_SEQUENCE (LDOM_BasicNodeSequence, LDOM_BasicNodePtr)
|
||||
IMPLEMENT_SEQUENCE (LDOM_BasicNodeSequence, LDOM_BasicNodePtr)
|
||||
|
||||
//=======================================================================
|
||||
//function : LDOM_NodeList()
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
|
||||
LDOM_NodeList::LDOM_NodeList ( )
|
||||
{
|
||||
mySeq = new LDOM_BasicNodeSequence;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : LDOM_NodeList
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_NodeList::LDOM_NodeList (const Handle(LDOM_MemManager)& aDoc)
|
||||
: myDoc (aDoc)
|
||||
{
|
||||
mySeq = new LDOM_BasicNodeSequence;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Append
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void LDOM_NodeList::Append (const LDOM_BasicNode& aNode) const
|
||||
{
|
||||
mySeq -> Append (&aNode);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : LDOM_NodeList
|
||||
//purpose : Copy constructor
|
||||
//=======================================================================
|
||||
|
||||
LDOM_NodeList::LDOM_NodeList (const LDOM_NodeList& theOther)
|
||||
{
|
||||
mySeq = new LDOM_BasicNodeSequence;
|
||||
* mySeq = * theOther.mySeq;
|
||||
myDoc = theOther.myDoc;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ~LDOM_NodeList
|
||||
//purpose : Destructor
|
||||
//=======================================================================
|
||||
|
||||
LDOM_NodeList::~LDOM_NodeList ()
|
||||
{
|
||||
delete mySeq;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator =
|
||||
//purpose : Assignment
|
||||
//=======================================================================
|
||||
|
||||
LDOM_NodeList& LDOM_NodeList::operator = (const LDOM_NodeList& theOther)
|
||||
{
|
||||
myDoc = theOther.myDoc;
|
||||
* mySeq = * theOther.mySeq;
|
||||
return * this;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator =
|
||||
//purpose : Nullify
|
||||
//=======================================================================
|
||||
|
||||
LDOM_NodeList& LDOM_NodeList::operator = (const LDOM_NullPtr *)
|
||||
{
|
||||
myDoc.Nullify();
|
||||
mySeq -> Clear ();
|
||||
return * this;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator ==
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean LDOM_NodeList::operator == (const LDOM_NullPtr *) const
|
||||
{
|
||||
return myDoc.IsNull() || mySeq -> Length () == 0;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator !=
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean LDOM_NodeList::operator != (const LDOM_NullPtr *) const
|
||||
{
|
||||
return ! (myDoc.IsNull() || mySeq -> Length () == 0);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : item
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_Node LDOM_NodeList::item (const Standard_Integer anIndex) const
|
||||
{
|
||||
if (myDoc.IsNull() || anIndex < 0 || anIndex >= mySeq -> Length ())
|
||||
return LDOM_Node();
|
||||
return LDOM_Node (* mySeq -> Value(anIndex+1), myDoc);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getLength
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer LDOM_NodeList::getLength () const
|
||||
{
|
||||
return mySeq -> Length();
|
||||
}
|
||||
|
60
src/LDOM/LDOM_NodeList.hxx
Executable file
60
src/LDOM/LDOM_NodeList.hxx
Executable file
@@ -0,0 +1,60 @@
|
||||
// File: LDOM_NodeList.hxx
|
||||
// Created: 28.06.01 14:59:31
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
|
||||
|
||||
#ifndef LDOM_NodeList_HeaderFile
|
||||
#define LDOM_NodeList_HeaderFile
|
||||
|
||||
#include <LDOM_Node.hxx>
|
||||
|
||||
class LDOM_BasicNode;
|
||||
class LDOM_BasicNodeSequence;
|
||||
|
||||
// Class LDOM_NodeList
|
||||
//
|
||||
|
||||
class LDOM_NodeList
|
||||
{
|
||||
public:
|
||||
// ---------- PUBLIC METHODS ----------
|
||||
|
||||
Standard_EXPORT LDOM_NodeList ();
|
||||
// Empty constructor
|
||||
|
||||
Standard_EXPORT LDOM_NodeList (const LDOM_NodeList& theOther);
|
||||
// Copy constructor
|
||||
|
||||
Standard_EXPORT LDOM_NodeList& operator = (const LDOM_NodeList& theOther);
|
||||
// Copy constructor
|
||||
|
||||
Standard_EXPORT ~LDOM_NodeList ();
|
||||
// Destructor
|
||||
|
||||
Standard_EXPORT LDOM_NodeList& operator = (const LDOM_NullPtr *);
|
||||
// Nullify
|
||||
|
||||
Standard_EXPORT Standard_Boolean operator == (const LDOM_NullPtr *) const;
|
||||
|
||||
Standard_EXPORT Standard_Boolean operator != (const LDOM_NullPtr *) const;
|
||||
|
||||
Standard_EXPORT LDOM_Node item (const Standard_Integer) const;
|
||||
|
||||
Standard_EXPORT Standard_Integer getLength () const;
|
||||
|
||||
private:
|
||||
friend class LDOM_Document;
|
||||
friend class LDOM_Element;
|
||||
friend class LDOM_BasicElement;
|
||||
// ---------- PRIVATE FIELDS ----------
|
||||
|
||||
Standard_EXPORT LDOM_NodeList (const Handle(LDOM_MemManager)& aDoc);
|
||||
|
||||
Standard_EXPORT void Append (const LDOM_BasicNode& aNode) const;
|
||||
|
||||
Handle(LDOM_MemManager) myDoc;
|
||||
LDOM_BasicNodeSequence * mySeq;
|
||||
};
|
||||
|
||||
#endif
|
159
src/LDOM/LDOM_OSStream.cxx
Executable file
159
src/LDOM/LDOM_OSStream.cxx
Executable file
@@ -0,0 +1,159 @@
|
||||
// File: LDOM_OSStream.cxx
|
||||
// Created: 01.10.01 10:57:37
|
||||
// Author: Julia DOROVSKIKH
|
||||
// Copyright: Open Cascade 2001
|
||||
// History:
|
||||
|
||||
#include <LDOM_OSStream.hxx>
|
||||
#include <string.h>
|
||||
#include <Standard_Integer.hxx>
|
||||
|
||||
// One element of sequence
|
||||
class LDOM_StringElem
|
||||
{
|
||||
char* buf; // pointer on data string
|
||||
int len; // quantity of really written data
|
||||
LDOM_StringElem* next; // pointer on the next element of a sequence
|
||||
|
||||
LDOM_StringElem (int aLen)
|
||||
{
|
||||
buf = new char[aLen];
|
||||
len = 0;
|
||||
next = 0;
|
||||
}
|
||||
|
||||
~LDOM_StringElem ()
|
||||
{
|
||||
delete [] buf;
|
||||
if (next) delete next;
|
||||
}
|
||||
friend class LDOM_SBuffer;
|
||||
};
|
||||
|
||||
//=======================================================================
|
||||
//function : LDOM_SBuffer()
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
LDOM_SBuffer::LDOM_SBuffer (const Standard_Integer theMaxBuf)
|
||||
: myMaxBuf (theMaxBuf), myLength(0)
|
||||
{
|
||||
myFirstString = new LDOM_StringElem (theMaxBuf);
|
||||
myCurString = myFirstString;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ~LDOM_SBuffer()
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
LDOM_SBuffer::~LDOM_SBuffer ()
|
||||
{
|
||||
if (myFirstString) delete myFirstString;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Clear()
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void LDOM_SBuffer::Clear ()
|
||||
{
|
||||
if (myFirstString->next) delete myFirstString->next;
|
||||
myFirstString->next = 0;
|
||||
myFirstString->len = 0;
|
||||
myLength = 0;
|
||||
myCurString = myFirstString;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : str()
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Standard_CString LDOM_SBuffer::str () const
|
||||
{
|
||||
char* aRetStr = new char [myLength + 1];
|
||||
|
||||
LDOM_StringElem* aCurElem = myFirstString;
|
||||
int aCurLen = 0;
|
||||
while (aCurElem)
|
||||
{
|
||||
strncpy(aRetStr + aCurLen, aCurElem->buf, aCurElem->len);
|
||||
aCurLen += aCurElem->len;
|
||||
aCurElem = aCurElem->next;
|
||||
}
|
||||
*(aRetStr + myLength) = '\0';
|
||||
|
||||
return aRetStr;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : overflow()
|
||||
//purpose : redefined virtual
|
||||
//=======================================================================
|
||||
int LDOM_SBuffer::overflow(int c)
|
||||
{
|
||||
char cc = c;
|
||||
return xsputn(&cc,1);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : underflow
|
||||
//purpose : redefined virtual
|
||||
//=======================================================================
|
||||
|
||||
int LDOM_SBuffer::underflow()
|
||||
{
|
||||
return EOF;
|
||||
}
|
||||
|
||||
//int LDOM_SBuffer::uflow()
|
||||
//{ return EOF; }
|
||||
|
||||
//=======================================================================
|
||||
//function : xsputn()
|
||||
//purpose : redefined virtual
|
||||
//=======================================================================
|
||||
int LDOM_SBuffer::xsputn(const char* aStr, int n)
|
||||
{
|
||||
int aLen = n + 1;
|
||||
int freeLen = myMaxBuf - myCurString->len - 1;
|
||||
if (freeLen >= n)
|
||||
{
|
||||
strncpy(myCurString->buf + myCurString->len, aStr, aLen);
|
||||
}
|
||||
else if (freeLen <= 0)
|
||||
{
|
||||
LDOM_StringElem* aNextElem = new LDOM_StringElem(Max(aLen, myMaxBuf));
|
||||
myCurString->next = aNextElem;
|
||||
myCurString = aNextElem;
|
||||
strncpy(myCurString->buf + myCurString->len, aStr, aLen);
|
||||
}
|
||||
else // 0 < freeLen < n
|
||||
{
|
||||
// copy string by parts
|
||||
strncpy(myCurString->buf + myCurString->len, aStr, freeLen);
|
||||
myCurString->len += freeLen;
|
||||
*(myCurString->buf + myCurString->len) = '\0';
|
||||
aLen -= freeLen;
|
||||
LDOM_StringElem* aNextElem = new LDOM_StringElem(Max(aLen, myMaxBuf));
|
||||
myCurString->next = aNextElem;
|
||||
myCurString = aNextElem;
|
||||
strncpy(myCurString->buf + myCurString->len, aStr + freeLen, aLen);
|
||||
}
|
||||
myCurString->len += aLen - 1;
|
||||
*(myCurString->buf + myCurString->len) = '\0';
|
||||
|
||||
myLength += n;
|
||||
return n;
|
||||
}
|
||||
|
||||
//streamsize LDOM_SBuffer::xsgetn(char* s, streamsize n)
|
||||
//{ return _IO_default_xsgetn(this, s, n); }
|
||||
|
||||
//=======================================================================
|
||||
//function : LDOM_OSStream()
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
LDOM_OSStream::LDOM_OSStream (const Standard_Integer theMaxBuf)
|
||||
: Standard_OStream (&myBuffer), myBuffer (theMaxBuf)
|
||||
{
|
||||
init(&myBuffer);
|
||||
}
|
92
src/LDOM/LDOM_OSStream.hxx
Executable file
92
src/LDOM/LDOM_OSStream.hxx
Executable file
@@ -0,0 +1,92 @@
|
||||
// File: LDOM_OSStream.hxx
|
||||
// Created: 01.10.01 10:56:06
|
||||
// Author: Julia DOROVSKIKH
|
||||
// Copyright: Open Cascade 2001
|
||||
|
||||
#ifndef LDOM_OSStream_HeaderFile
|
||||
#define LDOM_OSStream_HeaderFile
|
||||
|
||||
// This implementation allows to increase performance
|
||||
// of outputting data into a string
|
||||
// avoiding reallocation of buffer.
|
||||
//
|
||||
// class LDOM_OSStream implements output into a sequence of
|
||||
// strings and getting the result as a string.
|
||||
// It inherits Standard_OStream (ostream).
|
||||
// Beside methods of ostream, it also has additional
|
||||
// useful methods: str(), Length() and Clear().
|
||||
//
|
||||
// struct LDOM_StringElem is one element of internal sequence
|
||||
//
|
||||
// class LDOM_SBuffer inherits streambuf and
|
||||
// redefines some virtual methods of it
|
||||
// (overflow() and xsputn())
|
||||
// This class contains pointers on first
|
||||
// and current element of sequence,
|
||||
// also it has methods for the sequence management.
|
||||
|
||||
#include <Standard_OStream.hxx>
|
||||
#include <Standard_Boolean.hxx>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h> /* EOF */
|
||||
|
||||
class LDOM_StringElem; // defined in cxx file
|
||||
|
||||
class LDOM_SBuffer : public streambuf
|
||||
{
|
||||
public:
|
||||
Standard_EXPORT LDOM_SBuffer (const Standard_Integer theMaxBuf);
|
||||
// Constructor. Sets a default value for the
|
||||
// length of each sequence element.
|
||||
|
||||
Standard_EXPORT Standard_CString str () const;
|
||||
// Concatenates strings of all sequence elements
|
||||
// into one string. Space for output string is allocated
|
||||
// with operator new.
|
||||
// Caller of this function is responsible
|
||||
// for memory release after the string usage.
|
||||
|
||||
Standard_Integer Length () const {return myLength;};
|
||||
// Returns full length of data contained
|
||||
|
||||
Standard_EXPORT void Clear ();
|
||||
// Clears first element of sequence and removes all others
|
||||
|
||||
// Methods of streambuf
|
||||
|
||||
Standard_EXPORT virtual int overflow(int c = EOF);
|
||||
Standard_EXPORT virtual int underflow();
|
||||
//virtual int uflow();
|
||||
|
||||
Standard_EXPORT virtual int xsputn(const char* s, int n);
|
||||
//virtual int xsgetn(char* s, int n);
|
||||
//virtual int sync();
|
||||
|
||||
Standard_EXPORT ~LDOM_SBuffer ();
|
||||
// Destructor
|
||||
|
||||
private:
|
||||
Standard_Integer myMaxBuf; // default length of one element
|
||||
Standard_Integer myLength; // full length of contained data
|
||||
LDOM_StringElem* myFirstString; // the head of the sequence
|
||||
LDOM_StringElem* myCurString; // current element of the sequence
|
||||
};
|
||||
|
||||
class LDOM_OSStream : public Standard_OStream
|
||||
{
|
||||
public:
|
||||
Standard_EXPORT LDOM_OSStream (const Standard_Integer theMaxBuf);
|
||||
// Constructor
|
||||
|
||||
Standard_CString str () const {return myBuffer.str();};
|
||||
|
||||
Standard_Integer Length () const {return myBuffer.Length();};
|
||||
|
||||
void Clear () { myBuffer.Clear(); };
|
||||
|
||||
private:
|
||||
LDOM_SBuffer myBuffer;
|
||||
};
|
||||
|
||||
#endif
|
43
src/LDOM/LDOM_Text.hxx
Executable file
43
src/LDOM/LDOM_Text.hxx
Executable file
@@ -0,0 +1,43 @@
|
||||
// File: LDOM_Text.hxx
|
||||
// Created: 26.07.01 19:29:54
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
|
||||
|
||||
#ifndef LDOM_Text_HeaderFile
|
||||
#define LDOM_Text_HeaderFile
|
||||
|
||||
#include <LDOM_CharacterData.hxx>
|
||||
|
||||
// Class LDOM_Text
|
||||
//
|
||||
|
||||
class LDOM_Text : public LDOM_CharacterData
|
||||
{
|
||||
public:
|
||||
// ---------- PUBLIC METHODS ----------
|
||||
|
||||
LDOM_Text () {}
|
||||
// Empty constructor
|
||||
|
||||
LDOM_Text (const LDOM_Text& anOther) : LDOM_CharacterData (anOther) {}
|
||||
// Copy constructor
|
||||
|
||||
LDOM_Text& operator = (const LDOM_NullPtr * theNull)
|
||||
{ return (LDOM_Text&) LDOM_CharacterData::operator= (theNull); }
|
||||
// Nullify
|
||||
|
||||
LDOM_Text& operator = (const LDOM_Text& theOther)
|
||||
{ return (LDOM_Text&) LDOM_CharacterData::operator= (theOther);}
|
||||
// Assignment
|
||||
|
||||
protected:
|
||||
friend class LDOM_Document;
|
||||
// ---------- PROTECTED METHODS ----------
|
||||
|
||||
LDOM_Text (const LDOM_BasicText& theText,
|
||||
const Handle(LDOM_MemManager)& theDoc)
|
||||
: LDOM_CharacterData (theText, theDoc) {}
|
||||
};
|
||||
|
||||
#endif
|
576
src/LDOM/LDOM_XmlReader.cxx
Executable file
576
src/LDOM/LDOM_XmlReader.cxx
Executable file
@@ -0,0 +1,576 @@
|
||||
// File: LDOM_XmlReader.cxx
|
||||
// Created: 20.07.01 15:38:15
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
// History: AGV 060302: Input from istream
|
||||
// AGV 130302: bug corr: was error if strlen(root_elem_name) < 7
|
||||
|
||||
#include <LDOM_XmlReader.hxx>
|
||||
#include <Standard_Stream.hxx>
|
||||
#include <LDOM_MemManager.hxx>
|
||||
#include <LDOM_BasicAttribute.hxx>
|
||||
#include <LDOM_CharReference.hxx>
|
||||
#include <LDOM_OSStream.hxx>
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#ifdef WNT
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
//#include <ctype.h>
|
||||
|
||||
const int XML_MIN_BUFFER = 10;
|
||||
const int MAX_ATTRIBUTES = 512;
|
||||
const int FILE_NONVALUE = -1;
|
||||
|
||||
typedef enum {
|
||||
STATE_WAITING = 0,
|
||||
STATE_HEADER,
|
||||
STATE_DOCTYPE,
|
||||
STATE_DOCTYPE_MARKUP,
|
||||
STATE_ELEMENT,
|
||||
STATE_ELEMENT_END,
|
||||
STATE_ATTRIBUTE_NAME,
|
||||
STATE_ATTRIBUTE_EQUAL,
|
||||
STATE_ATTRIBUTE_VALUE,
|
||||
STATE_COMMENT,
|
||||
STATE_CDATA,
|
||||
STATE_TEXT
|
||||
} ParserState;
|
||||
|
||||
#define TEXT_COMPARE(aPtr,aPattern) \
|
||||
(memcmp ((aPtr), (aPattern), sizeof(aPattern) - 1) == 0)
|
||||
|
||||
static Standard_Boolean isName (const char * aString,
|
||||
const char * aStringEnd,
|
||||
const char *& aNameEnd);
|
||||
|
||||
//=======================================================================
|
||||
//function : LDOM_XmlReader()
|
||||
//purpose : Constructor (file descriptor)
|
||||
//=======================================================================
|
||||
|
||||
LDOM_XmlReader::LDOM_XmlReader (const int aFileDes,
|
||||
const Handle(LDOM_MemManager)& aDocument,
|
||||
TCollection_AsciiString& anErrorString)
|
||||
: myEOF (Standard_False),
|
||||
myFileDes (aFileDes),
|
||||
#ifdef WNT
|
||||
myIStream (cin), // one quirk of MSVC6.0: can't initialise by 0
|
||||
#else
|
||||
myIStream (* (istream *) UndefinedHandleAddress),
|
||||
#endif
|
||||
myError (anErrorString),
|
||||
myDocument (aDocument),
|
||||
myPtr (&myBuffer[0]),
|
||||
myEndPtr (&myBuffer[0])
|
||||
{}
|
||||
|
||||
//=======================================================================
|
||||
//function : LDOM_XmlReader()
|
||||
//purpose : Constructor (istream)
|
||||
//=======================================================================
|
||||
|
||||
LDOM_XmlReader::LDOM_XmlReader (istream& anInput,
|
||||
const Handle(LDOM_MemManager)& aDocument,
|
||||
TCollection_AsciiString& anErrorString)
|
||||
: myEOF (Standard_False),
|
||||
myFileDes (FILE_NONVALUE),
|
||||
myIStream (anInput),
|
||||
myError (anErrorString),
|
||||
myDocument (aDocument),
|
||||
myPtr (&myBuffer[0]),
|
||||
myEndPtr (&myBuffer[0])
|
||||
{}
|
||||
|
||||
//=======================================================================
|
||||
//function : ReadRecord
|
||||
//purpose : Read a record from XML file
|
||||
//=======================================================================
|
||||
|
||||
LDOM_XmlReader::RecordType LDOM_XmlReader::ReadRecord
|
||||
(LDOM_OSStream& theData)
|
||||
{
|
||||
theData.Clear();
|
||||
myError.Clear();
|
||||
ParserState aState = STATE_WAITING;
|
||||
const char * aStartData = NULL, * aNameEnd, * aPtr;
|
||||
LDOMBasicString anAttrName, anAttrValue;
|
||||
char anAttDelimiter = '\0';
|
||||
|
||||
while (1) {
|
||||
// Check if the current file buffer is exhausted
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// There should always be some bytes available in the buffer for analysis
|
||||
Standard_Integer aBytesRest = myEndPtr - myPtr;
|
||||
if (aBytesRest < XML_MIN_BUFFER) {
|
||||
if (myEOF == Standard_True) {
|
||||
if (aBytesRest <= 0)
|
||||
break; // END of processing
|
||||
} else {
|
||||
// If we are reading some data, save the beginning and preserve the state
|
||||
if (aStartData /* && aState != STATE_WAITING */) {
|
||||
if (myPtr > aStartData)
|
||||
theData.rdbuf()->sputn(aStartData, myPtr - aStartData);
|
||||
aStartData = &myBuffer[0];
|
||||
}
|
||||
// Copy the rest of file data to the beginning of buffer
|
||||
if (aBytesRest > 0)
|
||||
memcpy (&myBuffer[0], myPtr, aBytesRest);
|
||||
|
||||
// Read the full buffer and reset start and end buffer pointers
|
||||
myPtr = &myBuffer[0];
|
||||
Standard_Integer aNBytes;
|
||||
if (myFileDes != FILE_NONVALUE)
|
||||
aNBytes = read (myFileDes, &myBuffer[aBytesRest],
|
||||
XML_BUFFER_SIZE - aBytesRest);
|
||||
else {
|
||||
myIStream.read (&myBuffer[aBytesRest],
|
||||
XML_BUFFER_SIZE - aBytesRest);
|
||||
aNBytes = myIStream.gcount();
|
||||
}
|
||||
if (aNBytes == 0)
|
||||
myEOF = Standard_True; // END-OF-FILE
|
||||
myEndPtr = &myBuffer[aBytesRest + aNBytes];
|
||||
myBuffer[aBytesRest + aNBytes] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
// Check the character data
|
||||
switch (aState) {
|
||||
|
||||
// Checking the characters in STATE_WAITING (blank, TEXT or markup)
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
case STATE_WAITING:
|
||||
switch (myPtr[0]) {
|
||||
case ' ':
|
||||
case '\t':
|
||||
case '\n':
|
||||
case '\r':
|
||||
++ myPtr;
|
||||
continue;
|
||||
case '<':
|
||||
// XML markup found, then make detect the record type
|
||||
switch (myPtr[1]) {
|
||||
case '?':
|
||||
aState = STATE_HEADER;
|
||||
myPtr += 2;
|
||||
aStartData = myPtr;
|
||||
continue;
|
||||
case '/':
|
||||
aState = STATE_ELEMENT_END;
|
||||
myPtr += 2;
|
||||
aStartData = myPtr;
|
||||
continue;
|
||||
case '!':
|
||||
if (myPtr[2] == '-' && myPtr[3] == '-') {
|
||||
aState = STATE_COMMENT;
|
||||
myPtr += 4;
|
||||
} else if (TEXT_COMPARE (&myPtr[2], "DOCTYPE")) {
|
||||
char ch = myPtr[9];
|
||||
if (ch != ' ' && ch != '\t' && ch != '\n' && ch != '\r')
|
||||
break;
|
||||
aState = STATE_DOCTYPE;
|
||||
myPtr += 10;
|
||||
} else if (TEXT_COMPARE (&myPtr[2], "[CDATA[")) {
|
||||
aState = STATE_CDATA;
|
||||
myPtr += 9;
|
||||
} else break; // ERROR
|
||||
aStartData = myPtr;
|
||||
continue;
|
||||
default:
|
||||
if (::isName (&myPtr[1], myEndPtr, aNameEnd)) {
|
||||
aStartData = myPtr + 1;
|
||||
myPtr = aNameEnd;
|
||||
if (myPtr < myEndPtr) {
|
||||
myElement = & LDOM_BasicElement::Create (aStartData,
|
||||
myPtr - aStartData,
|
||||
myDocument);
|
||||
myLastChild = NULL;
|
||||
aState = STATE_ATTRIBUTE_NAME;
|
||||
aStartData = NULL;
|
||||
}else
|
||||
aState = STATE_ELEMENT;
|
||||
continue;
|
||||
} // otherwise ERROR
|
||||
} // end of switch
|
||||
myError = "Unknown XML object: ";
|
||||
myError += TCollection_AsciiString ((const Standard_CString)myPtr,
|
||||
XML_MIN_BUFFER);
|
||||
return XML_UNKNOWN;
|
||||
case '\0':
|
||||
if (myEOF == Standard_True) continue;
|
||||
default:
|
||||
// Limitation: we do not treat '&' as special character
|
||||
aPtr = (const char *) memchr (myPtr, '<', myEndPtr - myPtr);
|
||||
if (aPtr) {
|
||||
// The end of text field reached
|
||||
theData.rdbuf()->sputn(myPtr, aPtr - myPtr);
|
||||
myPtr = aPtr;
|
||||
return XML_TEXT;
|
||||
}
|
||||
aState = STATE_TEXT;
|
||||
aStartData = myPtr;
|
||||
myPtr = myEndPtr;
|
||||
} // end of checking in STATE_WAITING
|
||||
continue;
|
||||
|
||||
// Checking the characters in STATE_HEADER, seek for "?>" sequence
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
case STATE_HEADER:
|
||||
aPtr = (const char *) memchr (aStartData, '?', (myEndPtr-1) - aStartData);
|
||||
if (aPtr) {
|
||||
// The end of XML declaration found
|
||||
if (aPtr[1] != '>') { // ERROR
|
||||
myError = "Character \'>\' is expected in the end of XML declaration";
|
||||
return XML_UNKNOWN;
|
||||
}
|
||||
// The XML declaration is retrieved
|
||||
theData.rdbuf()->sputn(aStartData, aPtr - aStartData);
|
||||
myPtr = aPtr + 2;
|
||||
return XML_HEADER;
|
||||
}
|
||||
myPtr = myEndPtr - 1;
|
||||
continue;
|
||||
|
||||
// Checking the characters in STATE_DOCTYPE, seek for "]>" sequence
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
case STATE_DOCTYPE:
|
||||
for (aPtr = aStartData; aPtr < myEndPtr-1; aPtr++) {
|
||||
const int aChar = aPtr[0];
|
||||
if (aChar == '[') {
|
||||
aState = STATE_DOCTYPE_MARKUP;
|
||||
aStartData = &aPtr[1];
|
||||
goto state_doctype_markup;
|
||||
}
|
||||
if (aChar == '>') {
|
||||
// The DOCTYPE declaration is retrieved
|
||||
theData.rdbuf()->sputn(aStartData, aPtr - aStartData - 1);
|
||||
myPtr = aPtr + 1;
|
||||
return XML_DOCTYPE;
|
||||
}
|
||||
}
|
||||
myPtr = myEndPtr - 1;
|
||||
continue;
|
||||
|
||||
state_doctype_markup:
|
||||
case STATE_DOCTYPE_MARKUP:
|
||||
aPtr = (const char *) memchr (aStartData, ']', (myEndPtr-1) - aStartData);
|
||||
if (aPtr) {
|
||||
// The end of DOCTYPE declaration found
|
||||
if (aPtr[1] != '>') { // ERROR
|
||||
myError =
|
||||
"Character \'>\' is expected in the end of DOCTYPE declaration";
|
||||
return XML_UNKNOWN;
|
||||
}
|
||||
// The DOCTYPE declaration is retrieved
|
||||
theData.rdbuf()->sputn(aStartData, aPtr - aStartData);
|
||||
myPtr = aPtr + 2;
|
||||
return XML_DOCTYPE;
|
||||
}
|
||||
myPtr = myEndPtr - 1;
|
||||
continue;
|
||||
|
||||
// Checking the characters in STATE_COMMENT, seek for "-->" sequence
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
case STATE_COMMENT:
|
||||
aPtr = aStartData;
|
||||
while (1) {
|
||||
aPtr = (const char *) memchr (aPtr, '-', (myEndPtr - 2) - aPtr);
|
||||
if (aPtr == NULL) break;
|
||||
if (aPtr[1] != '-') ++ aPtr;
|
||||
else {
|
||||
if (aPtr[2] != '>') { // ERROR
|
||||
myError = "Character \'>\' is expected in the end of comment";
|
||||
return XML_UNKNOWN;
|
||||
}
|
||||
theData.rdbuf()->sputn(aStartData, aPtr - aStartData);
|
||||
myPtr = aPtr + 3;
|
||||
return XML_COMMENT;
|
||||
}
|
||||
}
|
||||
myPtr = myEndPtr - 2;
|
||||
continue;
|
||||
|
||||
// Checking the characters in STATE_TEXT, seek for "<"
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
case STATE_TEXT:
|
||||
aPtr = (const char *) memchr (aStartData, '<', myEndPtr - aStartData);
|
||||
if (aPtr) {
|
||||
// The end of text field reached
|
||||
theData.rdbuf()->sputn(aStartData, aPtr - aStartData);
|
||||
myPtr = aPtr;
|
||||
return XML_TEXT;
|
||||
}
|
||||
myPtr = myEndPtr;
|
||||
continue;
|
||||
|
||||
// Checking the characters in STATE_CDATA, seek for "]]"
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
case STATE_CDATA:
|
||||
aPtr = aStartData;
|
||||
while (1) {
|
||||
aPtr = (const char *) memchr (aPtr, ']', (myEndPtr - 1) - aStartData);
|
||||
if (aPtr == NULL) break;
|
||||
if (aPtr[1] != ']') { // ERROR
|
||||
myError = "Characters \']]\' are expected in the end of CDATA";
|
||||
return XML_UNKNOWN;
|
||||
}
|
||||
theData.rdbuf()->sputn(aStartData, aPtr - aStartData);
|
||||
myPtr = aPtr + 2;
|
||||
return XML_CDATA;
|
||||
}
|
||||
myPtr = myEndPtr - 1;
|
||||
continue;
|
||||
|
||||
// Checking the characters in STATE_ELEMENT, seek the end of TagName
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
case STATE_ELEMENT:
|
||||
if (::isName (myPtr, myEndPtr, aNameEnd) == Standard_False)
|
||||
if (theData.Length() == 0 || aNameEnd != myPtr) {
|
||||
myError = "Invalid tag name";
|
||||
return XML_UNKNOWN;
|
||||
}
|
||||
{
|
||||
theData.rdbuf()->sputn(aStartData, aNameEnd - aStartData);
|
||||
char* aDataString = (char *)theData.str();
|
||||
myElement = & LDOM_BasicElement::Create (aDataString, theData.Length(),
|
||||
myDocument);
|
||||
theData.Clear();
|
||||
myLastChild = NULL;
|
||||
delete [] aDataString;
|
||||
aState = STATE_ATTRIBUTE_NAME;
|
||||
aStartData = NULL;
|
||||
myPtr = aNameEnd;
|
||||
continue;
|
||||
}
|
||||
// Parsing a single attribute (STATE_ATTRIBUTE)
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
case STATE_ATTRIBUTE_NAME: // attribute name
|
||||
switch (myPtr[0]) {
|
||||
case ' ' :
|
||||
case '\t':
|
||||
case '\n':
|
||||
case '\r':
|
||||
if (aStartData) goto attr_name;
|
||||
++ myPtr;
|
||||
continue;
|
||||
case '/' :
|
||||
if (aStartData)
|
||||
myError = "Inexpected end of attribute";
|
||||
else if (myPtr[1] != '>')
|
||||
myError = "Improper element tag termination";
|
||||
else {
|
||||
myPtr += 2;
|
||||
#ifdef DEB
|
||||
theData.Clear();
|
||||
theData << myElement->GetTagName();
|
||||
#endif
|
||||
return XML_FULL_ELEMENT;
|
||||
}
|
||||
return XML_UNKNOWN;
|
||||
case '>' :
|
||||
if (aStartData) {
|
||||
myError = "Inexpected end of attribute";
|
||||
return XML_UNKNOWN;
|
||||
}
|
||||
++ myPtr;
|
||||
#ifdef DEB
|
||||
theData.Clear();
|
||||
theData << myElement->GetTagName();
|
||||
#endif
|
||||
return XML_START_ELEMENT;
|
||||
default :
|
||||
if (::isName (myPtr, myEndPtr, aNameEnd) == Standard_False)
|
||||
if (theData.Length() == 0 || aNameEnd != myPtr) {
|
||||
myError = "Invalid attribute name";
|
||||
return XML_UNKNOWN;
|
||||
}
|
||||
if (aNameEnd >= myEndPtr)
|
||||
aStartData = myPtr;
|
||||
else {
|
||||
if (theData.Length() == 0)
|
||||
anAttrName = LDOMBasicString(myPtr, aNameEnd - myPtr, myDocument);
|
||||
else {
|
||||
theData.rdbuf()->sputn(myPtr, aNameEnd - myPtr);
|
||||
attr_name:
|
||||
char* aDataString = (char *)theData.str();
|
||||
theData.Clear();
|
||||
anAttrName = LDOMBasicString (aDataString, myDocument);
|
||||
delete [] aDataString;
|
||||
}
|
||||
aStartData = NULL;
|
||||
aState = STATE_ATTRIBUTE_EQUAL;
|
||||
}
|
||||
myPtr = aNameEnd;
|
||||
continue;
|
||||
}
|
||||
case STATE_ATTRIBUTE_EQUAL: // attribute 'equal' sign
|
||||
switch (myPtr[0]) {
|
||||
case '=' :
|
||||
aState = STATE_ATTRIBUTE_VALUE;
|
||||
case ' ' :
|
||||
case '\t':
|
||||
case '\n':
|
||||
case '\r':
|
||||
++ myPtr;
|
||||
continue;
|
||||
default:
|
||||
myError = "Equal sign expected in attribute definition";
|
||||
return XML_UNKNOWN;
|
||||
}
|
||||
|
||||
case STATE_ATTRIBUTE_VALUE: // attribute value
|
||||
switch (myPtr[0]) {
|
||||
case ' ' :
|
||||
case '\t':
|
||||
case '\n':
|
||||
case '\r':
|
||||
if (aStartData == NULL) {
|
||||
++ myPtr;
|
||||
continue;
|
||||
default:
|
||||
if (anAttDelimiter == '\0') {
|
||||
myError = "Expected an attribute value";
|
||||
return XML_UNKNOWN;
|
||||
case '\"':
|
||||
case '\'':
|
||||
if (aStartData == NULL) {
|
||||
aStartData = &myPtr[1];
|
||||
anAttDelimiter = myPtr[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
// Limitation: we do not take into account that '<' and '&'
|
||||
// are not allowed in attribute values
|
||||
aPtr = (const char *) memchr (aStartData, anAttDelimiter,
|
||||
myEndPtr - aStartData);
|
||||
if (aPtr) {
|
||||
(char&) aPtr[0] = '\0';
|
||||
anAttDelimiter = '\0';
|
||||
char * aDataString = (char *) aStartData;
|
||||
const char * ePtr = aPtr;
|
||||
|
||||
// Append the end of the string to previously taken data
|
||||
if (theData.Length() > 0) {
|
||||
theData.rdbuf()->sputn(aStartData, aPtr-aStartData);
|
||||
aDataString = (char *)theData.str();
|
||||
ePtr = strchr (aDataString, '\0');
|
||||
}
|
||||
|
||||
Standard_Integer aDataLen;
|
||||
aDataString = LDOM_CharReference::Decode (aDataString, aDataLen);
|
||||
if (IsDigit(aDataString[0])) {
|
||||
if (getInteger (anAttrValue, aDataString, ePtr))
|
||||
anAttrValue = LDOMBasicString (aDataString,aDataLen,myDocument);
|
||||
} else
|
||||
anAttrValue = LDOMBasicString (aDataString, aDataLen, myDocument);
|
||||
|
||||
if (theData.Length() > 0) {
|
||||
theData.Clear();
|
||||
delete [] aDataString;
|
||||
}
|
||||
// Create an attribute
|
||||
myLastChild = myElement -> AddAttribute (anAttrName, anAttrValue,
|
||||
myDocument, myLastChild);
|
||||
myPtr = aPtr + 1;
|
||||
aStartData = NULL;
|
||||
aState = STATE_ATTRIBUTE_NAME;
|
||||
} else
|
||||
myPtr = myEndPtr;
|
||||
continue;
|
||||
}
|
||||
// Checking the characters in STATE_ELEMENT_END, seek for ">"
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
case STATE_ELEMENT_END:
|
||||
aPtr = (const char *) memchr (aStartData, '>', myEndPtr - aStartData);
|
||||
if (aPtr) {
|
||||
// The end of the end-element markup
|
||||
theData.rdbuf()->sputn(aStartData, aPtr - aStartData);
|
||||
myPtr = aPtr + 1;
|
||||
return XML_END_ELEMENT;
|
||||
}
|
||||
myPtr = myEndPtr;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (aState != STATE_WAITING) {
|
||||
myError = "Unexpected end of file";
|
||||
return XML_UNKNOWN;
|
||||
}
|
||||
return XML_EOF;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : isName
|
||||
//type : static
|
||||
//purpose : Check if aString is a valid XML Name
|
||||
//=======================================================================
|
||||
|
||||
static Standard_Boolean isName (const char * aString,
|
||||
const char * aStringEnd,
|
||||
const char *& aNameEnd)
|
||||
{
|
||||
Standard_Boolean aResult;
|
||||
int aCh = aString[0];
|
||||
if (IsAlphabetic(aCh) || aCh == '_' || aCh == ':') {
|
||||
const char * aPtr = &aString[1];
|
||||
while (aPtr < aStringEnd) {
|
||||
aCh = * aPtr;
|
||||
switch (aCh) {
|
||||
case ' ' :
|
||||
case '\n':
|
||||
case '\r':
|
||||
case '\t':
|
||||
case '=' :
|
||||
case '\0':
|
||||
case '/' :
|
||||
case '>' :
|
||||
aNameEnd = aPtr;
|
||||
return Standard_True;
|
||||
default:
|
||||
if (IsAlphanumeric(aCh) == 0) {
|
||||
aNameEnd = aPtr;
|
||||
return Standard_False;
|
||||
}
|
||||
case '.' :
|
||||
case '-' :
|
||||
case '_' :
|
||||
case ':' :
|
||||
++ aPtr;
|
||||
}
|
||||
}
|
||||
aNameEnd = aPtr;
|
||||
aResult = Standard_True;
|
||||
} else {
|
||||
aNameEnd = aString;
|
||||
aResult = Standard_False;
|
||||
}
|
||||
return aResult;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : getInteger
|
||||
//purpose : Try to initialize theValue as Integer; return False on success
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean LDOM_XmlReader::getInteger (LDOMBasicString& theValue,
|
||||
const char * theStart,
|
||||
const char * theEnd)
|
||||
{
|
||||
char * ptr;
|
||||
errno = 0;
|
||||
if (theEnd - theStart == 1 || theStart[0] != '0')
|
||||
{
|
||||
long aResult = strtol (theStart, &ptr, 10);
|
||||
if (ptr == theEnd && errno == 0)
|
||||
{
|
||||
theValue = Standard_Integer(aResult);
|
||||
return Standard_False;
|
||||
}
|
||||
}
|
||||
return Standard_True;
|
||||
}
|
81
src/LDOM/LDOM_XmlReader.hxx
Executable file
81
src/LDOM/LDOM_XmlReader.hxx
Executable file
@@ -0,0 +1,81 @@
|
||||
// File: LDOM_XmlReader.hxx
|
||||
// Created: 20.07.01 15:27:57
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
// History: AGV 060302: Input from istream
|
||||
// AGV 130302: bug corr: was error if strlen(root_elem_name) < 7
|
||||
|
||||
#ifndef LDOM_XmlReader_HeaderFile
|
||||
#define LDOM_XmlReader_HeaderFile
|
||||
|
||||
//#define XML_BUFFER_SIZE 1000
|
||||
#define XML_BUFFER_SIZE 20480
|
||||
|
||||
#include <LDOM_BasicElement.hxx>
|
||||
|
||||
class TCollection_AsciiString;
|
||||
class LDOM_OSStream;
|
||||
|
||||
// Class LDOM_XmlReader
|
||||
//
|
||||
|
||||
class LDOM_XmlReader
|
||||
{
|
||||
public:
|
||||
enum RecordType {
|
||||
XML_UNKNOWN,
|
||||
XML_HEADER,
|
||||
XML_DOCTYPE,
|
||||
XML_COMMENT,
|
||||
XML_START_ELEMENT,
|
||||
XML_END_ELEMENT,
|
||||
XML_FULL_ELEMENT,
|
||||
XML_TEXT,
|
||||
XML_CDATA,
|
||||
XML_EOF
|
||||
};
|
||||
|
||||
// ---------- PUBLIC METHODS ----------
|
||||
LDOM_XmlReader (const int aFileDes, const Handle(LDOM_MemManager)& aDocument,
|
||||
TCollection_AsciiString& anErrorString);
|
||||
// Constructor - takes a file descriptor for input
|
||||
|
||||
LDOM_XmlReader (istream& anInput, const Handle(LDOM_MemManager)& aDocument,
|
||||
TCollection_AsciiString& anErrorString);
|
||||
// Constructor - takes an istream for input
|
||||
|
||||
RecordType ReadRecord (LDOM_OSStream& theData);
|
||||
// reading a markup or other element of XML format
|
||||
|
||||
LDOM_BasicElement& GetElement () const { return * myElement; }
|
||||
// get the last element retrieved from the stream
|
||||
|
||||
static Standard_Boolean getInteger (LDOMBasicString& theValue,
|
||||
const char * theStart,
|
||||
const char * theEnd);
|
||||
// try convert string theStart to LDOM_AsciiInteger, return False on success
|
||||
|
||||
private:
|
||||
// ---------- PRIVATE (PROHIBITED) METHODS ----------
|
||||
LDOM_XmlReader (const LDOM_XmlReader& theOther);
|
||||
// Copy constructor
|
||||
|
||||
LDOM_XmlReader& operator = (const LDOM_XmlReader& theOther);
|
||||
// Assignment
|
||||
|
||||
private:
|
||||
// ---------- PRIVATE FIELDS ----------
|
||||
|
||||
Standard_Boolean myEOF;
|
||||
int myFileDes; // alternative 1: file descriptor
|
||||
istream& myIStream; // alternative 2: istream
|
||||
TCollection_AsciiString & myError;
|
||||
Handle(LDOM_MemManager) myDocument;
|
||||
LDOM_BasicElement * myElement;
|
||||
const LDOM_BasicNode * myLastChild; // optim. reading attributes
|
||||
const char * myPtr;
|
||||
const char * myEndPtr;
|
||||
char myBuffer [XML_BUFFER_SIZE+4];
|
||||
};
|
||||
|
||||
#endif
|
406
src/LDOM/LDOM_XmlWriter.cxx
Executable file
406
src/LDOM/LDOM_XmlWriter.cxx
Executable file
@@ -0,0 +1,406 @@
|
||||
// File: LDOM_XmlWriter.cxx
|
||||
// Created: 28.06.01 10:32:53
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
// History:
|
||||
|
||||
|
||||
#include <LDOM_XmlWriter.hxx>
|
||||
#include <LDOM_Document.hxx>
|
||||
#include <LDOM_CharReference.hxx>
|
||||
|
||||
#define chOpenAngle '<'
|
||||
#define chCloseAngle '>'
|
||||
#define chOpenSquare '['
|
||||
#define chCloseSquare ']'
|
||||
#define chQuestion '?'
|
||||
#define chForwardSlash '/'
|
||||
#define chLF '\n'
|
||||
#define chNull '\0'
|
||||
#define chEqual '='
|
||||
#define chDash '-'
|
||||
#define chBang '!'
|
||||
#define chSpace ' '
|
||||
#define chDoubleQuote '\"'
|
||||
#define chZero '0'
|
||||
#define chOne '1'
|
||||
#define chTwo '2'
|
||||
#define chThree '3'
|
||||
#define chFour '4'
|
||||
#define chFive '5'
|
||||
#define chSix '6'
|
||||
#define chSeven '7'
|
||||
#define chEight '8'
|
||||
#define chNine '9'
|
||||
#define chLatin_a 'a'
|
||||
#define chLatin_b 'b'
|
||||
#define chLatin_c 'c'
|
||||
#define chLatin_d 'd'
|
||||
#define chLatin_e 'e'
|
||||
#define chLatin_f 'f'
|
||||
#define chLatin_g 'g'
|
||||
#define chLatin_h 'h'
|
||||
#define chLatin_i 'i'
|
||||
#define chLatin_j 'j'
|
||||
#define chLatin_k 'k'
|
||||
#define chLatin_l 'l'
|
||||
#define chLatin_m 'm'
|
||||
#define chLatin_n 'n'
|
||||
#define chLatin_o 'o'
|
||||
#define chLatin_p 'p'
|
||||
#define chLatin_q 'q'
|
||||
#define chLatin_r 'r'
|
||||
#define chLatin_s 's'
|
||||
#define chLatin_t 't'
|
||||
#define chLatin_u 'u'
|
||||
#define chLatin_v 'v'
|
||||
#define chLatin_w 'w'
|
||||
#define chLatin_x 'x'
|
||||
#define chLatin_y 'y'
|
||||
#define chLatin_z 'z'
|
||||
#define chLatin_A 'A'
|
||||
#define chLatin_B 'B'
|
||||
#define chLatin_C 'C'
|
||||
#define chLatin_D 'D'
|
||||
#define chLatin_E 'E'
|
||||
#define chLatin_F 'F'
|
||||
#define chLatin_G 'G'
|
||||
#define chLatin_H 'H'
|
||||
#define chLatin_I 'I'
|
||||
#define chLatin_J 'J'
|
||||
#define chLatin_K 'K'
|
||||
#define chLatin_L 'L'
|
||||
#define chLatin_M 'M'
|
||||
#define chLatin_N 'N'
|
||||
#define chLatin_O 'O'
|
||||
#define chLatin_P 'P'
|
||||
#define chLatin_Q 'Q'
|
||||
#define chLatin_R 'R'
|
||||
#define chLatin_S 'S'
|
||||
#define chLatin_T 'T'
|
||||
#define chLatin_U 'U'
|
||||
#define chLatin_V 'V'
|
||||
#define chLatin_W 'W'
|
||||
#define chLatin_X 'X'
|
||||
#define chLatin_Y 'Y'
|
||||
#define chLatin_Z 'Z'
|
||||
|
||||
static const LXMLCh gEndElement[] = { chOpenAngle, chForwardSlash, chNull };
|
||||
static const LXMLCh gEndElement1[]= { chForwardSlash, chNull };
|
||||
static const LXMLCh gEndPI[] = { chQuestion, chCloseAngle, chNull };
|
||||
static const LXMLCh gStartPI[] = { chOpenAngle, chQuestion, chNull };
|
||||
static const LXMLCh gXMLDecl1[] =
|
||||
{ chOpenAngle, chQuestion, chLatin_x, chLatin_m, chLatin_l
|
||||
, chSpace, chLatin_v, chLatin_e, chLatin_r, chLatin_s, chLatin_i
|
||||
, chLatin_o, chLatin_n, chEqual, chDoubleQuote, chNull
|
||||
};
|
||||
static const LXMLCh gXMLDecl2[] =
|
||||
{ chDoubleQuote, chSpace, chLatin_e, chLatin_n, chLatin_c
|
||||
, chLatin_o, chLatin_d, chLatin_i, chLatin_n, chLatin_g, chEqual
|
||||
, chDoubleQuote, chNull
|
||||
};
|
||||
static const LXMLCh gXMLDecl3[] =
|
||||
{ chDoubleQuote, chSpace, chLatin_s, chLatin_t, chLatin_a
|
||||
, chLatin_n, chLatin_d, chLatin_a, chLatin_l, chLatin_o
|
||||
, chLatin_n, chLatin_e, chEqual, chDoubleQuote, chNull
|
||||
};
|
||||
static const LXMLCh gXMLDecl4[] =
|
||||
{ chDoubleQuote, chQuestion, chCloseAngle
|
||||
, chLF, chNull
|
||||
};
|
||||
static const LXMLCh gStartCDATA[] =
|
||||
{ chOpenAngle, chBang, chOpenSquare, chLatin_C, chLatin_D,
|
||||
chLatin_A, chLatin_T, chLatin_A, chOpenSquare, chNull
|
||||
};
|
||||
static const LXMLCh gEndCDATA[] =
|
||||
{ chCloseSquare, chCloseSquare, chCloseAngle, chNull };
|
||||
static const LXMLCh gStartComment[] =
|
||||
{ chOpenAngle, chBang, chDash, chDash, chNull };
|
||||
static const LXMLCh gEndComment[] =
|
||||
{ chDash, chDash, chCloseAngle, chNull };
|
||||
static const LXMLCh gStartDoctype[] =
|
||||
{ chOpenAngle, chBang, chLatin_D, chLatin_O, chLatin_C, chLatin_T,
|
||||
chLatin_Y, chLatin_P, chLatin_E, chSpace, chNull
|
||||
};
|
||||
static const LXMLCh gPublic[] =
|
||||
{ chLatin_P, chLatin_U, chLatin_B, chLatin_L, chLatin_I,
|
||||
chLatin_C, chSpace, chDoubleQuote, chNull
|
||||
};
|
||||
static const LXMLCh gSystem[] =
|
||||
{ chLatin_S, chLatin_Y, chLatin_S, chLatin_T, chLatin_E,
|
||||
chLatin_M, chSpace, chDoubleQuote, chNull
|
||||
};
|
||||
static const LXMLCh gStartEntity[] =
|
||||
{ chOpenAngle, chBang, chLatin_E, chLatin_N, chLatin_T, chLatin_I,
|
||||
chLatin_T, chLatin_Y, chSpace, chNull
|
||||
};
|
||||
static const LXMLCh gNotation[] =
|
||||
{ chLatin_N, chLatin_D, chLatin_A, chLatin_T, chLatin_A,
|
||||
chSpace, chDoubleQuote, chNull
|
||||
};
|
||||
|
||||
static LXMLCh * getEncodingName (const LXMLCh * theEncodingName)
|
||||
{
|
||||
const LXMLCh * anEncoding = theEncodingName;
|
||||
if (theEncodingName == NULL)
|
||||
{
|
||||
// anEncoding = // US-ASCII
|
||||
// { chLatin_U, chLatin_S, chDash, chLatin_A, chLatin_S, chLatin_C, chLatin_I,
|
||||
// chLatin_I, chNull };
|
||||
static const LXMLCh anUTFEncoding [] = // UTF-8
|
||||
{ chLatin_U, chLatin_T, chLatin_F, chDash, chEight, chNull };
|
||||
anEncoding = anUTFEncoding;
|
||||
}
|
||||
Standard_Integer aLen = 0;
|
||||
while (anEncoding[aLen++] != chNull);
|
||||
LXMLCh * aResult = new LXMLCh [aLen];
|
||||
memcpy (aResult, anEncoding, aLen * sizeof (LXMLCh));
|
||||
return aResult;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : LH3D_LXMLWriter()
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
LDOM_XmlWriter::LDOM_XmlWriter (FILE * aFile,
|
||||
const LXMLCh * theEncoding)
|
||||
: myFile (aFile),
|
||||
myEncodingName (::getEncodingName (theEncoding)),
|
||||
myIndent (0),
|
||||
myCurIndent (0),
|
||||
myABuffer (NULL),
|
||||
myABufferLen (0)
|
||||
{}
|
||||
|
||||
//=======================================================================
|
||||
//function : ~LDOM_XmlWriter
|
||||
//purpose : Destructor
|
||||
//=======================================================================
|
||||
|
||||
LDOM_XmlWriter::~LDOM_XmlWriter ()
|
||||
{
|
||||
delete [] myEncodingName;
|
||||
if (myABuffer != NULL) delete [] myABuffer;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator <<
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
LDOM_XmlWriter& LDOM_XmlWriter::operator << (const LDOM_Document& aDoc)
|
||||
{
|
||||
const char * anXMLversion = "1.0";
|
||||
* this << gXMLDecl1 << anXMLversion
|
||||
<< gXMLDecl2 << myEncodingName << gXMLDecl4;
|
||||
|
||||
return (* this << aDoc.getDocumentElement());
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator <<
|
||||
//purpose : Stream out an LDOMString
|
||||
//=======================================================================
|
||||
|
||||
inline LDOM_XmlWriter& LDOM_XmlWriter::operator <<
|
||||
(const LDOMBasicString& aString)
|
||||
{
|
||||
switch (aString.Type()) {
|
||||
case LDOMBasicString::LDOM_Integer:
|
||||
{
|
||||
Standard_Integer aValue;
|
||||
aString.GetInteger (aValue);
|
||||
fprintf (myFile, "%d", aValue);
|
||||
break;
|
||||
}
|
||||
case LDOMBasicString::LDOM_AsciiHashed: // attr names and element tags
|
||||
case LDOMBasicString::LDOM_AsciiDocClear:
|
||||
{
|
||||
const char * str = aString.GetString();
|
||||
if (str) {
|
||||
const Standard_Integer aLen = strlen (str);
|
||||
if (aLen > 0) fwrite (str, aLen, 1, myFile);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LDOMBasicString::LDOM_AsciiFree:
|
||||
case LDOMBasicString::LDOM_AsciiDoc:
|
||||
{
|
||||
const char * str = aString.GetString();
|
||||
if (str) {
|
||||
Standard_Integer aLen;
|
||||
char * encStr = LDOM_CharReference::Encode(str, aLen, Standard_False);
|
||||
if (aLen > 0) fwrite (encStr, aLen, 1, myFile);
|
||||
if (encStr != str) delete [] encStr;
|
||||
}
|
||||
}
|
||||
default: ;
|
||||
}
|
||||
return * this;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator<<()
|
||||
//purpose : Stream out a char *.
|
||||
//=======================================================================
|
||||
inline LDOM_XmlWriter& LDOM_XmlWriter::operator << (const LXMLCh * aString)
|
||||
{
|
||||
unsigned int aLength = strlen (aString);
|
||||
if (aLength > 0) fwrite ((void *) aString, aLength, 1, myFile);
|
||||
return * this;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator<<()
|
||||
//purpose : Stream out a character.
|
||||
//=======================================================================
|
||||
inline LDOM_XmlWriter& LDOM_XmlWriter::operator << (const LXMLCh aChar)
|
||||
{
|
||||
fputc (aChar, myFile);
|
||||
return * this;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : WriteAttribute()
|
||||
//purpose : Stream out an XML attribute.
|
||||
//=======================================================================
|
||||
void LDOM_XmlWriter::WriteAttribute (const LDOM_Node& theAtt)
|
||||
{
|
||||
int aLength;
|
||||
const char * aName = theAtt.getNodeName().GetString();
|
||||
const LDOMString aValueStr = theAtt.getNodeValue();
|
||||
|
||||
// Integer attribute value
|
||||
if (aValueStr.Type() == LDOMBasicString::LDOM_Integer) {
|
||||
Standard_Integer anIntValue;
|
||||
aValueStr.GetInteger (anIntValue);
|
||||
aLength = 20 + strlen (aName);
|
||||
if (aLength > myABufferLen) {
|
||||
if (myABuffer != NULL) delete [] myABuffer;
|
||||
myABuffer = new char [aLength+1];
|
||||
myABufferLen = aLength;
|
||||
}
|
||||
sprintf (myABuffer, "%c%s%c%c%d%c", chSpace, aName,
|
||||
chEqual, chDoubleQuote, anIntValue, chDoubleQuote);
|
||||
aLength = strlen (myABuffer);
|
||||
|
||||
// String attribute value
|
||||
} else {
|
||||
const char * aValue = aValueStr.GetString();
|
||||
char * encStr;
|
||||
if (aValueStr.Type() == LDOMBasicString::LDOM_AsciiDocClear) {
|
||||
encStr = (char *) aValue;
|
||||
aLength = 4 + strlen (aValue) + strlen (aName);
|
||||
} else {
|
||||
encStr = LDOM_CharReference::Encode (aValue, aLength, Standard_True);
|
||||
aLength += 4 + strlen (aName);
|
||||
}
|
||||
if (aLength > myABufferLen) {
|
||||
if (myABuffer != NULL) delete [] myABuffer;
|
||||
myABuffer = new char [aLength+1];
|
||||
myABufferLen = aLength;
|
||||
}
|
||||
sprintf (myABuffer, "%c%s%c%c%s%c", chSpace, aName,
|
||||
chEqual, chDoubleQuote, encStr, chDoubleQuote);
|
||||
if (encStr != aValue) delete [] encStr;
|
||||
}
|
||||
fwrite ((void *) myABuffer, aLength, 1, myFile);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : operator<<()
|
||||
//purpose : Stream out a DOM node, and, recursively, all of its children.
|
||||
// This function is the heart of writing a DOM tree out as XML source.
|
||||
// Give it a document node and it will do the whole thing.
|
||||
//=======================================================================
|
||||
LDOM_XmlWriter& LDOM_XmlWriter::operator<< (const LDOM_Node& theNodeToWrite)
|
||||
{
|
||||
// Get the name and value out for convenience
|
||||
LDOMString aNodeName = theNodeToWrite.getNodeName();
|
||||
LDOMString aNodeValue = theNodeToWrite.getNodeValue();
|
||||
// unsigned long dwLent = aNodeValue.length();
|
||||
|
||||
switch (theNodeToWrite.getNodeType())
|
||||
{
|
||||
case LDOM_Node::TEXT_NODE :
|
||||
* this << aNodeValue;
|
||||
break;
|
||||
case LDOM_Node::ELEMENT_NODE :
|
||||
{
|
||||
const int aMaxNSpaces = 40;
|
||||
static LXMLCh aSpaces [] = {
|
||||
chSpace, chSpace, chSpace, chSpace, chSpace, chSpace, chSpace, chSpace,
|
||||
chSpace, chSpace, chSpace, chSpace, chSpace, chSpace, chSpace, chSpace,
|
||||
chSpace, chSpace, chSpace, chSpace, chSpace, chSpace, chSpace, chSpace,
|
||||
chSpace, chSpace, chSpace, chSpace, chSpace, chSpace, chSpace, chSpace,
|
||||
chSpace, chSpace, chSpace, chSpace, chSpace, chSpace, chSpace, chSpace,
|
||||
chOpenAngle, chNull };
|
||||
const LXMLCh * anIndentString = &aSpaces [aMaxNSpaces - myCurIndent];
|
||||
if (anIndentString < &aSpaces[0]) anIndentString = &aSpaces[0];
|
||||
|
||||
// Output the element start tag.
|
||||
* this << anIndentString << aNodeName.GetString();
|
||||
|
||||
// Output any attributes of this element
|
||||
const LDOM_Element& anElemToWrite = (const LDOM_Element&) theNodeToWrite;
|
||||
LDOM_NodeList aListAtt = anElemToWrite.GetAttributesList ();
|
||||
Standard_Integer aListInd = aListAtt.getLength();
|
||||
while (aListInd--) {
|
||||
LDOM_Node aChild = aListAtt.item (aListInd);
|
||||
WriteAttribute (aChild);
|
||||
}
|
||||
|
||||
// Test for the presence of children
|
||||
LDOM_Node aChild = theNodeToWrite.getFirstChild();
|
||||
if (aChild != 0)
|
||||
{
|
||||
// There are children. Close start-tag, and output children.
|
||||
* this << chCloseAngle;
|
||||
if (aChild.getNodeType() == LDOM_Node::ELEMENT_NODE && myIndent > 0)
|
||||
* this << chLF;
|
||||
Standard_Boolean isChildElem = Standard_False;
|
||||
while( aChild != 0)
|
||||
{
|
||||
isChildElem = (aChild.getNodeType() == LDOM_Node::ELEMENT_NODE);
|
||||
if (isChildElem) myCurIndent += myIndent;
|
||||
*this << aChild;
|
||||
if (isChildElem) myCurIndent -= myIndent;
|
||||
do aChild = aChild.getNextSibling();
|
||||
while (aChild.getNodeType() == LDOM_Node::ATTRIBUTE_NODE);
|
||||
}
|
||||
// Done with children. Output the end tag.
|
||||
//
|
||||
if (isChildElem)
|
||||
* this << anIndentString
|
||||
<< gEndElement1 << aNodeName.GetString() << chCloseAngle;
|
||||
else
|
||||
* this << gEndElement << aNodeName.GetString() << chCloseAngle;
|
||||
}
|
||||
else
|
||||
{
|
||||
// There were no children. Output the short form close of
|
||||
// the element start tag, making it an empty-element tag.
|
||||
* this << chForwardSlash << chCloseAngle;
|
||||
}
|
||||
if (myIndent > 0)
|
||||
* this << chLF;
|
||||
break;
|
||||
}
|
||||
case LDOM_Node::CDATA_SECTION_NODE:
|
||||
{
|
||||
* this << gStartCDATA << aNodeValue << gEndCDATA;
|
||||
break;
|
||||
}
|
||||
case LDOM_Node::COMMENT_NODE:
|
||||
{
|
||||
* this << gStartComment << aNodeValue << gEndComment;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
#ifndef WNT
|
||||
cerr << "Unrecognized node type = "
|
||||
<< (long)theNodeToWrite.getNodeType() << endl
|
||||
#endif
|
||||
; }
|
||||
return *this;
|
||||
}
|
69
src/LDOM/LDOM_XmlWriter.hxx
Executable file
69
src/LDOM/LDOM_XmlWriter.hxx
Executable file
@@ -0,0 +1,69 @@
|
||||
// File: LDOM_XmlWriter.hxx
|
||||
// Created: 28.06.01 10:26:52
|
||||
// Author: Alexander GRIGORIEV
|
||||
// Copyright: OpenCascade 2001
|
||||
|
||||
|
||||
#ifndef LDOM_XmlWriter_HeaderFile
|
||||
#define LDOM_XmlWriter_HeaderFile
|
||||
|
||||
#include <Standard_TypeDef.hxx>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef char LXMLCh;
|
||||
|
||||
class LDOM_Document;
|
||||
class LDOM_Node;
|
||||
class LDOMBasicString;
|
||||
|
||||
class LDOM_XmlWriter
|
||||
{
|
||||
public:
|
||||
|
||||
Standard_EXPORT LDOM_XmlWriter (FILE * aFile, const char * theEncoding= NULL);
|
||||
// Constructor
|
||||
|
||||
Standard_EXPORT ~LDOM_XmlWriter ();
|
||||
// Destructor
|
||||
|
||||
void SetIndentation (const Standard_Integer theIndent) { myIndent=theIndent; }
|
||||
// Set indentation for output (by default 0)
|
||||
|
||||
Standard_EXPORT LDOM_XmlWriter& operator<< (const LDOM_Document& aDoc);
|
||||
|
||||
Standard_EXPORT LDOM_XmlWriter& operator<< (const LDOM_Node& toWrite);
|
||||
// ostream << DOM_Node
|
||||
// Stream out a DOM node, and, recursively, all of its children. This
|
||||
// function is the heart of writing a DOM tree out as XML source. Give it
|
||||
// a document node and it will do the whole thing.
|
||||
|
||||
private:
|
||||
|
||||
void WriteAttribute (const LDOM_Node& theAtt);
|
||||
|
||||
LDOM_XmlWriter& operator<< (const LDOMBasicString&);
|
||||
// Stream out LDOM String
|
||||
|
||||
inline LDOM_XmlWriter& operator<< (const LXMLCh * toWrite);
|
||||
// Stream out a character string. Doing this requires that we first transcode
|
||||
// to char * form in the default code page for the system
|
||||
|
||||
inline LDOM_XmlWriter& operator << (const LXMLCh aChar);
|
||||
|
||||
LDOM_XmlWriter (const LDOM_XmlWriter& anOther);
|
||||
// Copy constructor - prohibited
|
||||
|
||||
LDOM_XmlWriter& operator = (const LDOM_XmlWriter& anOther);
|
||||
// Assignment operator - prohibited
|
||||
|
||||
private:
|
||||
|
||||
FILE * myFile;
|
||||
LXMLCh * myEncodingName;
|
||||
Standard_Integer myIndent;
|
||||
Standard_Integer myCurIndent;
|
||||
char * myABuffer; // for WriteAttribute()
|
||||
Standard_Integer myABufferLen; // for WriteAttribute()
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user