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
f53c300e
Commit
f53c300e
authored
Aug 24, 2010
by
Ken Renard
Committed by
Kenneth Leiter
Sep 23, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes for "transparent root" and "compare"
parent
8c4b7ddd
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
129 additions
and
44 deletions
+129
-44
core/XdmfCore.i
core/XdmfCore.i
+16
-0
core/XdmfCoreReader.cpp
core/XdmfCoreReader.cpp
+10
-2
core/XdmfCoreReader.hpp
core/XdmfCoreReader.hpp
+8
-0
core/XdmfItem.cpp
core/XdmfItem.cpp
+7
-0
core/XdmfItem.hpp
core/XdmfItem.hpp
+7
-0
core/XdmfWriter.cpp
core/XdmfWriter.cpp
+67
-42
core/XdmfWriter.hpp
core/XdmfWriter.hpp
+14
-0
No files found.
core/XdmfCore.i
View file @
f53c300e
...
...
@@ -64,6 +64,22 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
%
}
#
endif
/* SWIGJAVA */
#
ifdef
SWIGPYTHON
%
extend
XdmfItem
{
bool
__eq__
(
boost
::
shared_ptr
<
XdmfItem
>
item
)
{
return
(
self-
>
IsEqual
(
item
))
;
}
}
;
#
endif
#
ifdef
SWIGJAVA
%
extend
XdmfItem
{
bool
equals
(
boost
::
shared_ptr
<
XdmfItem
>
item
)
{
return
(
self-
>
IsEqual
(
item
))
;
}
}
;
#
endif
%
include
XdmfItem
.
hpp
%
include
XdmfItemProperty
.
hpp
%
include
XdmfVisitor
.
hpp
...
...
core/XdmfCoreReader.cpp
View file @
f53c300e
...
...
@@ -171,13 +171,21 @@ XdmfCoreReader::~XdmfCoreReader()
delete
mImpl
;
}
boost
::
shared_ptr
<
XdmfItem
>
XdmfCoreReader
::
read
(
const
std
::
string
&
filePath
)
const
std
::
vector
<
boost
::
shared_ptr
<
XdmfItem
>
>
XdmfCoreReader
::
read
Items
(
const
std
::
string
&
filePath
)
const
{
mImpl
->
openFile
(
filePath
);
const
xmlNodePtr
currNode
=
xmlDocGetRootElement
(
mImpl
->
mDocument
);
const
std
::
vector
<
boost
::
shared_ptr
<
XdmfItem
>
>
toReturn
=
mImpl
->
read
(
currNode
->
children
);
mImpl
->
closeFile
();
return
toReturn
[
0
];
return
toReturn
;
}
boost
::
shared_ptr
<
XdmfItem
>
XdmfCoreReader
::
read
(
const
std
::
string
&
filePath
)
const
{
const
std
::
vector
<
boost
::
shared_ptr
<
XdmfItem
>
>
toReturn
=
readItems
(
filePath
);
if
(
toReturn
.
size
()
==
0
)
return
(
boost
::
shared_ptr
<
XdmfItem
>
());
return
(
toReturn
[
0
]);
}
std
::
vector
<
boost
::
shared_ptr
<
XdmfItem
>
>
XdmfCoreReader
::
read
(
const
std
::
string
&
filePath
,
const
std
::
string
&
xPath
)
const
...
...
core/XdmfCoreReader.hpp
View file @
f53c300e
...
...
@@ -30,6 +30,14 @@ public:
*/
virtual
boost
::
shared_ptr
<
XdmfItem
>
read
(
const
std
::
string
&
filePath
)
const
;
/**
* Read an Xdmf file from disk into memory.
*
* @param filePath the path of the Xdmf file to read in from disk.
* @return a vector of XdmfItems at the root of the Xdmf tree.
*/
virtual
std
::
vector
<
boost
::
shared_ptr
<
XdmfItem
>
>
readItems
(
const
std
::
string
&
filePath
)
const
;
/**
* Read part of an Xdmf file from disk into memory.
*
...
...
core/XdmfItem.cpp
View file @
f53c300e
...
...
@@ -22,6 +22,13 @@ void XdmfItem::populateItem(const std::map<std::string, std::string> &, std::vec
}
}
bool
XdmfItem
::
IsEqual
(
boost
::
shared_ptr
<
XdmfItem
>
item
)
{
if
(
item
==
NULL
)
return
false
;
if
(
this
==
item
.
get
())
return
(
true
);
return
(
false
);
}
void
XdmfItem
::
traverse
(
const
boost
::
shared_ptr
<
XdmfBaseVisitor
>
visitor
)
{
for
(
std
::
vector
<
boost
::
shared_ptr
<
XdmfInformation
>
>::
const_iterator
iter
=
mInformations
.
begin
();
iter
!=
mInformations
.
end
();
++
iter
)
...
...
core/XdmfItem.hpp
View file @
f53c300e
...
...
@@ -147,6 +147,13 @@ public:
*/
virtual
void
traverse
(
const
boost
::
shared_ptr
<
XdmfBaseVisitor
>
visitor
);
/**
* Test for equality of underlying item.
*
* @param an XdmfItem to test for equality
*/
bool
IsEqual
(
boost
::
shared_ptr
<
XdmfItem
>
item
);
protected:
XdmfItem
();
...
...
core/XdmfWriter.cpp
View file @
f53c300e
...
...
@@ -27,7 +27,10 @@ public:
mXMLDocument
(
NULL
),
mXMLFilePath
(
XdmfSystemUtils
::
getRealPath
(
xmlFilePath
)),
mXPathCount
(
0
),
mXPathString
(
""
)
mXPathString
(
""
),
mDocumentTitle
(
"Xdmf"
),
mVersionString
(
"2.0"
),
mDepth
(
0
)
{
};
...
...
@@ -46,9 +49,9 @@ public:
void
openFile
()
{
mXMLDocument
=
xmlNewDoc
((
xmlChar
*
)
"1.0"
);
mXMLCurrentNode
=
xmlNewNode
(
NULL
,
(
xmlChar
*
)
"Xdmf"
);
mXMLCurrentNode
=
xmlNewNode
(
NULL
,
(
xmlChar
*
)
mDocumentTitle
.
c_str
()
);
xmlNewProp
(
mXMLCurrentNode
,
(
xmlChar
*
)
"xmlns:xi"
,
(
xmlChar
*
)
"http://www.w3.org/2001/XInclude"
);
xmlNewProp
(
mXMLCurrentNode
,
(
xmlChar
*
)
"Version"
,
(
xmlChar
*
)
"2.0"
);
xmlNewProp
(
mXMLCurrentNode
,
(
xmlChar
*
)
"Version"
,
(
xmlChar
*
)
mVersionString
.
c_str
()
);
xmlDocSetRootElement
(
mXMLDocument
,
mXMLCurrentNode
);
}
...
...
@@ -63,6 +66,9 @@ public:
std
::
map
<
const
XdmfItem
*
const
,
std
::
string
>
mXPath
;
unsigned
int
mXPathCount
;
std
::
string
mXPathString
;
std
::
string
mDocumentTitle
;
std
::
string
mVersionString
;
int
mDepth
;
};
boost
::
shared_ptr
<
XdmfWriter
>
XdmfWriter
::
New
(
const
std
::
string
&
xmlFilePath
)
...
...
@@ -148,6 +154,16 @@ void XdmfWriter::setWriteXPaths(const bool writeXPaths)
mImpl
->
mWriteXPaths
=
writeXPaths
;
}
void
XdmfWriter
::
setDocumentTitle
(
const
std
::
string
title
)
{
mImpl
->
mDocumentTitle
=
title
;
}
void
XdmfWriter
::
setVersionString
(
const
std
::
string
version
)
{
mImpl
->
mVersionString
=
version
;
}
void
XdmfWriter
::
visit
(
XdmfArray
&
array
,
const
boost
::
shared_ptr
<
XdmfBaseVisitor
>
visitor
)
{
bool
isSubclassed
=
array
.
getItemTag
().
compare
(
XdmfArray
::
ItemTag
)
!=
0
;
...
...
@@ -217,65 +233,74 @@ void XdmfWriter::visit(XdmfArray & array, const boost::shared_ptr<XdmfBaseVisito
void
XdmfWriter
::
visit
(
XdmfItem
&
item
,
const
boost
::
shared_ptr
<
XdmfBaseVisitor
>
visitor
)
{
if
(
mImpl
->
mXPathString
.
compare
(
""
)
==
0
)
{
mImpl
->
openFile
();
if
(
mImpl
->
mDepth
==
0
)
{
mImpl
->
openFile
();
}
mImpl
->
mDepth
++
;
if
(
mImpl
->
mWriteXPaths
)
std
::
string
tag
=
item
.
getItemTag
();
if
(
tag
.
length
()
==
0
)
{
mImpl
->
mXPathCount
++
;
item
.
traverse
(
visitor
);
}
else
{
if
(
mImpl
->
mWriteXPaths
)
{
mImpl
->
mXPathCount
++
;
std
::
string
parentXPathString
=
mImpl
->
mXPathString
;
std
::
string
parentXPathString
=
mImpl
->
mXPathString
;
std
::
stringstream
newXPathString
;
newXPathString
<<
mImpl
->
mXPathString
<<
"/"
<<
mImpl
->
mXPathCount
;
mImpl
->
mXPathString
=
newXPathString
.
str
();
std
::
stringstream
newXPathString
;
newXPathString
<<
mImpl
->
mXPathString
<<
"/"
<<
mImpl
->
mXPathCount
;
mImpl
->
mXPathString
=
newXPathString
.
str
();
std
::
map
<
const
XdmfItem
*
const
,
std
::
string
>::
const_iterator
iter
=
mImpl
->
mXPath
.
find
(
&
item
);
if
(
iter
!=
mImpl
->
mXPath
.
end
())
{
// Inserted before --- just xpath location of previously written node
mImpl
->
mXMLCurrentNode
=
xmlNewChild
(
mImpl
->
mXMLCurrentNode
,
NULL
,
(
xmlChar
*
)
"xi:include"
,
NULL
);
xmlNewProp
(
mImpl
->
mXMLCurrentNode
,
(
xmlChar
*
)
"xpointer"
,
(
xmlChar
*
)
iter
->
second
.
c_str
());
mImpl
->
mLastXPathed
=
true
;
std
::
map
<
const
XdmfItem
*
const
,
std
::
string
>::
const_iterator
iter
=
mImpl
->
mXPath
.
find
(
&
item
);
if
(
iter
!=
mImpl
->
mXPath
.
end
())
{
// Inserted before --- just xpath location of previously written node
mImpl
->
mXMLCurrentNode
=
xmlNewChild
(
mImpl
->
mXMLCurrentNode
,
NULL
,
(
xmlChar
*
)
"xi:include"
,
NULL
);
xmlNewProp
(
mImpl
->
mXMLCurrentNode
,
(
xmlChar
*
)
"xpointer"
,
(
xmlChar
*
)
iter
->
second
.
c_str
());
mImpl
->
mLastXPathed
=
true
;
}
else
{
// Not inserted before --- need to write all data and traverse.
mImpl
->
mXMLCurrentNode
=
xmlNewChild
(
mImpl
->
mXMLCurrentNode
,
NULL
,
(
xmlChar
*
)
tag
.
c_str
(),
NULL
);
std
::
stringstream
xPathProp
;
xPathProp
<<
"element(/1"
<<
mImpl
->
mXPathString
<<
")"
;
mImpl
->
mXPath
[
&
item
]
=
xPathProp
.
str
();
const
std
::
map
<
std
::
string
,
std
::
string
>
itemProperties
=
item
.
getItemProperties
();
for
(
std
::
map
<
std
::
string
,
std
::
string
>::
const_iterator
iter
=
itemProperties
.
begin
();
iter
!=
itemProperties
.
end
();
++
iter
)
{
xmlNewProp
(
mImpl
->
mXMLCurrentNode
,
(
xmlChar
*
)
iter
->
first
.
c_str
(),
(
xmlChar
*
)
iter
->
second
.
c_str
());
}
unsigned
int
parentCount
=
mImpl
->
mXPathCount
;
mImpl
->
mXPathCount
=
0
;
item
.
traverse
(
visitor
);
mImpl
->
mXPathCount
=
parentCount
;
mImpl
->
mLastXPathed
=
false
;
}
mImpl
->
mXPathString
=
parentXPathString
;
}
else
{
// Not inserted before --- need to write all data and traverse.
mImpl
->
mXMLCurrentNode
=
xmlNewChild
(
mImpl
->
mXMLCurrentNode
,
NULL
,
(
xmlChar
*
)
item
.
getItemTag
().
c_str
(),
NULL
);
std
::
stringstream
xPathProp
;
xPathProp
<<
"element(/1"
<<
mImpl
->
mXPathString
<<
")"
;
mImpl
->
mXPath
[
&
item
]
=
xPathProp
.
str
();
mImpl
->
mXMLCurrentNode
=
xmlNewChild
(
mImpl
->
mXMLCurrentNode
,
NULL
,
(
xmlChar
*
)
tag
.
c_str
(),
NULL
);
const
std
::
map
<
std
::
string
,
std
::
string
>
itemProperties
=
item
.
getItemProperties
();
for
(
std
::
map
<
std
::
string
,
std
::
string
>::
const_iterator
iter
=
itemProperties
.
begin
();
iter
!=
itemProperties
.
end
();
++
iter
)
{
xmlNewProp
(
mImpl
->
mXMLCurrentNode
,
(
xmlChar
*
)
iter
->
first
.
c_str
(),
(
xmlChar
*
)
iter
->
second
.
c_str
());
}
unsigned
int
parentCount
=
mImpl
->
mXPathCount
;
mImpl
->
mXPathCount
=
0
;
item
.
traverse
(
visitor
);
mImpl
->
mXPathCount
=
parentCount
;
mImpl
->
mLastXPathed
=
false
;
}
mImpl
->
mX
PathString
=
parentXPathString
;
mImpl
->
mX
MLCurrentNode
=
mImpl
->
mXMLCurrentNode
->
parent
;
}
else
{
// Not inserted before --- need to write all data and traverse.
mImpl
->
mXMLCurrentNode
=
xmlNewChild
(
mImpl
->
mXMLCurrentNode
,
NULL
,
(
xmlChar
*
)
item
.
getItemTag
().
c_str
(),
NULL
);
const
std
::
map
<
std
::
string
,
std
::
string
>
itemProperties
=
item
.
getItemProperties
();
for
(
std
::
map
<
std
::
string
,
std
::
string
>::
const_iterator
iter
=
itemProperties
.
begin
();
iter
!=
itemProperties
.
end
();
++
iter
)
{
xmlNewProp
(
mImpl
->
mXMLCurrentNode
,
(
xmlChar
*
)
iter
->
first
.
c_str
(),
(
xmlChar
*
)
iter
->
second
.
c_str
());
}
item
.
traverse
(
visitor
);
}
mImpl
->
mXMLCurrentNode
=
mImpl
->
mXMLCurrentNode
->
parent
;
if
(
mImpl
->
mXPathString
.
compare
(
""
)
==
0
)
mImpl
->
mDepth
--
;
if
(
mImpl
->
mDepth
<=
0
)
{
mImpl
->
closeFile
();
}
...
...
core/XdmfWriter.hpp
View file @
f53c300e
...
...
@@ -108,6 +108,20 @@ public:
*/
void
setMode
(
const
Mode
mode
);
/**
* Set XML document title
*
* @param title, title to use for this XML document
*/
void
setDocumentTitle
(
const
std
::
string
title
);
/**
* Set version String
*
* @param version, string to use as version attribute in document title
*/
void
setVersionString
(
const
std
::
string
version
);
/**
* Set whether to write xpaths for this writer.
*
...
...
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