Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Xdmf
Xdmf
Commits
326d3866
Commit
326d3866
authored
Jul 13, 2010
by
Kenneth Leiter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ENH: First draft of xpointer respected reading.
parent
60362c29
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
18 deletions
+73
-18
core/XdmfCoreReader.cpp
core/XdmfCoreReader.cpp
+65
-16
core/XdmfCoreReader.hpp
core/XdmfCoreReader.hpp
+1
-1
core/XdmfWriter.cpp
core/XdmfWriter.cpp
+0
-1
tests/Cxx/TestXdmfXPath.cpp
tests/Cxx/TestXdmfXPath.cpp
+7
-0
No files found.
core/XdmfCoreReader.cpp
View file @
326d3866
// Kenneth Leiter
// Xdmf Smart Pointer Test
#include <libxml/xpointer.h>
#include <libxml/xmlreader.h>
#include "XdmfCoreItemFactory.hpp"
#include "XdmfCoreReader.hpp"
...
...
@@ -22,7 +23,7 @@ public:
{
};
std
::
vector
<
boost
::
shared_ptr
<
XdmfItem
>
>
read
(
xmlNodePtr
currNode
)
const
std
::
vector
<
boost
::
shared_ptr
<
XdmfItem
>
>
read
(
xmlNodePtr
currNode
)
{
std
::
vector
<
boost
::
shared_ptr
<
XdmfItem
>
>
myItems
;
...
...
@@ -30,32 +31,77 @@ public:
{
if
(
currNode
->
type
==
XML_ELEMENT_NODE
)
{
std
::
map
<
std
::
string
,
std
::
string
>
itemProperties
;
std
::
cout
<<
currNode
->
name
<<
std
::
endl
;
if
(
currNode
->
children
!=
NULL
)
if
(
xmlStrcmp
(
currNode
->
name
,
(
xmlChar
*
)
"include"
)
==
0
)
{
itemProperties
[
"Content"
]
=
(
const
char
*
)
currNode
->
children
->
content
;
xmlAttrPtr
currAttribute
=
currNode
->
properties
;
xmlChar
*
xpointer
;
while
(
currAttribute
!=
NULL
)
{
if
(
xmlStrcmp
(
currAttribute
->
name
,
(
xmlChar
*
)
"xpointer"
)
==
0
)
{
xpointer
=
currAttribute
->
children
->
content
;
break
;
}
}
xmlXPathObjectPtr
xPathObject
=
xmlXPtrEval
(
xpointer
,
mXPathContext
);
std
::
cout
<<
"HERE"
<<
std
::
endl
;
std
::
map
<
xmlNodePtr
,
boost
::
shared_ptr
<
XdmfItem
>
>::
const_iterator
iter
=
mXPathMap
.
find
(
xPathObject
->
nodesetval
->
nodeTab
[
0
]);
if
(
iter
!=
mXPathMap
.
end
())
{
myItems
.
push_back
(
iter
->
second
);
}
//this->read();
//for(unsigned int i=0; i<xPathObject->nodesetval->nodeNr; ++i)
//{
//std::cout << xPathObject->nodesetval->nodeTab[i]->type << std::endl;
//std::cout << xPathObject->nodesetval->nodeTab[i]->name << std::endl;
//this->read(xPathObject->nodesetval->nodeTab[i]);
//currNode = NULL;
//currNode = xPathObject->nodesetval->nodeTab[0];
//}
//xmlXPathFreeObject(xPathObject);
}
else
{
itemProperties
[
"Content"
]
=
""
;
std
::
map
<
xmlNodePtr
,
boost
::
shared_ptr
<
XdmfItem
>
>::
const_iterator
iter
=
mXPathMap
.
find
(
currNode
);
if
(
iter
!=
mXPathMap
.
end
())
{
myItems
.
push_back
(
iter
->
second
);
}
else
{
std
::
map
<
std
::
string
,
std
::
string
>
itemProperties
;
if
(
currNode
->
children
!=
NULL
)
{
itemProperties
[
"Content"
]
=
(
const
char
*
)
currNode
->
children
->
content
;
}
else
{
itemProperties
[
"Content"
]
=
""
;
}
xmlAttrPtr
currAttribute
=
currNode
->
properties
;
while
(
currAttribute
!=
NULL
)
{
itemProperties
[(
const
char
*
)
currAttribute
->
name
]
=
(
const
char
*
)
currAttribute
->
children
->
content
;
currAttribute
=
currAttribute
->
next
;
}
std
::
vector
<
boost
::
shared_ptr
<
XdmfItem
>
>
childItems
=
this
->
read
(
currNode
->
children
);
boost
::
shared_ptr
<
XdmfItem
>
newItem
=
mItemFactory
->
createItem
((
const
char
*
)
currNode
->
name
,
itemProperties
);
newItem
->
populateItem
(
itemProperties
,
childItems
);
myItems
.
push_back
(
newItem
);
mXPathMap
[
currNode
]
=
newItem
;
}
}
xmlAttrPtr
currAttribute
=
currNode
->
properties
;
while
(
currAttribute
!=
NULL
)
{
itemProperties
[(
const
char
*
)
currAttribute
->
name
]
=
(
const
char
*
)
currAttribute
->
children
->
content
;
currAttribute
=
currAttribute
->
next
;
}
std
::
vector
<
boost
::
shared_ptr
<
XdmfItem
>
>
childItems
=
this
->
read
(
currNode
->
children
);
boost
::
shared_ptr
<
XdmfItem
>
newItem
=
mItemFactory
->
createItem
((
const
char
*
)
currNode
->
name
,
itemProperties
);
newItem
->
populateItem
(
itemProperties
,
childItems
);
myItems
.
push_back
(
newItem
);
}
currNode
=
currNode
->
next
;
}
return
myItems
;
}
xmlXPathContextPtr
mXPathContext
;
std
::
map
<
xmlNodePtr
,
boost
::
shared_ptr
<
XdmfItem
>
>
mXPathMap
;
private:
const
boost
::
shared_ptr
<
XdmfCoreItemFactory
>
mItemFactory
;
...
...
@@ -79,6 +125,7 @@ boost::shared_ptr<XdmfItem> XdmfCoreReader::read(const std::string & filePath) c
xmlNodePtr
currNode
;
document
=
xmlReadFile
(
filePath
.
c_str
(),
NULL
,
0
);
mImpl
->
mXPathContext
=
xmlXPtrNewContext
(
document
,
NULL
,
NULL
);
if
(
document
==
NULL
)
{
assert
(
false
);
...
...
@@ -87,6 +134,8 @@ boost::shared_ptr<XdmfItem> XdmfCoreReader::read(const std::string & filePath) c
std
::
vector
<
boost
::
shared_ptr
<
XdmfItem
>
>
toReturn
=
mImpl
->
read
(
currNode
->
children
);
mImpl
->
mXPathMap
.
clear
();
xmlXPathFreeContext
(
mImpl
->
mXPathContext
);
xmlFreeDoc
(
document
);
xmlCleanupParser
();
...
...
core/XdmfCoreReader.hpp
View file @
326d3866
...
...
@@ -47,7 +47,7 @@ private:
XdmfCoreReader
(
const
XdmfCoreReader
&
reader
);
// Not implemented.
void
operator
=
(
const
XdmfCoreReader
&
reader
);
// Not implemented.
const
XdmfCoreReaderImpl
*
const
mImpl
;
XdmfCoreReaderImpl
*
const
mImpl
;
};
#endif
/* XDMFCOREREADER_HPP_ */
core/XdmfWriter.cpp
View file @
326d3866
...
...
@@ -2,7 +2,6 @@
// Xdmf Smart Pointer Test
#include <libxml/tree.h>
#include <map>
#include <sstream>
#include "XdmfArray.hpp"
#include "XdmfItem.hpp"
...
...
tests/Cxx/TestXdmfXPath.cpp
View file @
326d3866
#include <fstream>
#include <sstream>
#include "XdmfDomain.hpp"
#include "XdmfReader.hpp"
#include "XdmfWriter.hpp"
#include "XdmfTestDataGenerator.hpp"
...
...
@@ -31,5 +32,11 @@ int main(int argc, char* argv[])
assert
(
fileContents
.
find
(
"xpointer=
\"
element(/1/1/1/2)
\"
"
)
!=
std
::
string
::
npos
);
assert
(
fileContents
.
find
(
"xpointer=
\"
element(/1/1/1/3)
\"
"
)
!=
std
::
string
::
npos
);
// Make sure when we read it in we get the same structure as when we wrote it out (multiple items holding the same shared pointers)
boost
::
shared_ptr
<
XdmfReader
>
reader
=
XdmfReader
::
New
();
boost
::
shared_ptr
<
XdmfDomain
>
domain2
=
boost
::
shared_dynamic_cast
<
XdmfDomain
>
(
reader
->
read
(
"xpath.xmf"
));
boost
::
shared_ptr
<
XdmfWriter
>
writer2
=
XdmfWriter
::
New
(
"xpath2.xmf"
);
domain2
->
accept
(
writer2
);
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment