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
CrayzeeWulf
Xdmf
Commits
f8cd6652
Commit
f8cd6652
authored
May 14, 2010
by
Kenneth Leiter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ENH: Use PIMPL idiom to hide hdf5 and libxml2 includes from header files for writers.
parent
048eabaf
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
95 additions
and
50 deletions
+95
-50
XdmfHDF5Writer.cpp
XdmfHDF5Writer.cpp
+36
-15
XdmfHDF5Writer.hpp
XdmfHDF5Writer.hpp
+7
-5
XdmfWriter.cpp
XdmfWriter.cpp
+46
-22
XdmfWriter.hpp
XdmfWriter.hpp
+6
-8
No files found.
XdmfHDF5Writer.cpp
View file @
f8cd6652
// Kenneth Leiter
// Xdmf Smart Pointer Test
#include <hdf5.h>
#include <sstream>
#include "XdmfArray.hpp"
#include "XdmfItem.hpp"
#include "XdmfHDF5Writer.hpp"
/**
* PIMPL
*/
class
XdmfHDF5Writer
::
XdmfHDF5WriterImpl
{
public:
XdmfHDF5WriterImpl
()
:
mHDF5Handle
(
H5Fcreate
(
"output.h5"
,
H5F_ACC_TRUNC
,
H5P_DEFAULT
,
H5P_DEFAULT
)),
mHeavyFileName
(
"output.h5"
)
{
};
~
XdmfHDF5WriterImpl
()
{
herr_t
status
=
H5Fclose
(
mHDF5Handle
);
};
std
::
vector
<
std
::
string
>
mDataHierarchy
;
hid_t
mHDF5Handle
;
std
::
string
mHeavyFileName
;
};
XdmfHDF5Writer
::
XdmfHDF5Writer
()
:
mHeavyFileName
(
"output.h5"
),
mHDF5Handle
(
H5Fcreate
(
"output.h5"
,
H5F_ACC_TRUNC
,
H5P_DEFAULT
,
H5P_DEFAULT
))
mImpl
(
new
XdmfHDF5WriterImpl
())
{
std
::
cout
<<
"Created XdmfHDF5Writer "
<<
this
<<
std
::
endl
;
}
XdmfHDF5Writer
::~
XdmfHDF5Writer
()
{
herr_t
status
=
H5Fclose
(
mHDF5Handle
)
;
delete
mImpl
;
std
::
cout
<<
"Deleted XdmfHDF5Writer "
<<
this
<<
std
::
endl
;
}
std
::
string
XdmfHDF5Writer
::
createHDF5Group
(
std
::
stringstream
&
groupPath
,
int
index
)
{
groupPath
<<
"/"
<<
mDataHierarchy
[
index
];
hid_t
handle
=
H5Gopen
(
mHDF5Handle
,
groupPath
.
str
().
c_str
(),
H5P_DEFAULT
);
groupPath
<<
"/"
<<
mImpl
->
mDataHierarchy
[
index
];
hid_t
handle
=
H5Gopen
(
mImpl
->
mHDF5Handle
,
groupPath
.
str
().
c_str
(),
H5P_DEFAULT
);
if
(
handle
<
0
)
{
// Open failed, create a new group
handle
=
H5Gcreate
(
mHDF5Handle
,
groupPath
.
str
().
c_str
(),
H5P_DEFAULT
,
H5P_DEFAULT
,
H5P_DEFAULT
);
handle
=
H5Gcreate
(
mImpl
->
mHDF5Handle
,
groupPath
.
str
().
c_str
(),
H5P_DEFAULT
,
H5P_DEFAULT
,
H5P_DEFAULT
);
}
H5Gclose
(
handle
);
// + 2 because the last value in mDataHierarchy == dataset name
if
(
index
+
2
<
mDataHierarchy
.
size
())
if
(
index
+
2
<
mImpl
->
mDataHierarchy
.
size
())
{
return
createHDF5Group
(
groupPath
,
index
+
1
);
}
...
...
@@ -40,7 +61,7 @@ std::string XdmfHDF5Writer::createHDF5Group(std::stringstream & groupPath, int i
std
::
string
XdmfHDF5Writer
::
getHDF5GroupHandle
()
{
if
(
mDataHierarchy
.
size
()
>
1
)
if
(
mImpl
->
mDataHierarchy
.
size
()
>
1
)
{
// Save old error handler and turn off error handling for now
H5E_auto_t
old_func
;
...
...
@@ -61,7 +82,7 @@ std::string XdmfHDF5Writer::getHDF5GroupHandle()
void
XdmfHDF5Writer
::
popDataHierarchy
()
{
mDataHierarchy
.
pop_back
();
mImpl
->
mDataHierarchy
.
pop_back
();
}
void
XdmfHDF5Writer
::
pushDataHierarchy
(
const
XdmfItem
&
item
)
...
...
@@ -70,11 +91,11 @@ void XdmfHDF5Writer::pushDataHierarchy(const XdmfItem & item)
std
::
map
<
std
::
string
,
std
::
string
>::
const_iterator
name
=
itemProperties
.
find
(
"Name"
);
if
(
name
==
itemProperties
.
end
())
{
mDataHierarchy
.
push_back
(
item
.
getItemTag
());
mImpl
->
mDataHierarchy
.
push_back
(
item
.
getItemTag
());
}
else
{
mDataHierarchy
.
push_back
(
name
->
second
);
mImpl
->
mDataHierarchy
.
push_back
(
name
->
second
);
}
}
...
...
@@ -83,13 +104,13 @@ std::string XdmfHDF5Writer::visit(XdmfArray & array, boost::shared_ptr<Loki::Bas
herr_t
status
;
hsize_t
size
=
array
.
getSize
();
hid_t
dataspace
=
H5Screate_simple
(
1
,
&
size
,
NULL
);
hid_t
handle
=
mHDF5Handle
;
hid_t
handle
=
mImpl
->
mHDF5Handle
;
std
::
string
groupName
=
getHDF5GroupHandle
();
if
(
groupName
.
compare
(
""
)
!=
0
)
{
handle
=
H5Gopen
(
mHDF5Handle
,
groupName
.
c_str
(),
H5P_DEFAULT
);
handle
=
H5Gopen
(
mImpl
->
mHDF5Handle
,
groupName
.
c_str
(),
H5P_DEFAULT
);
}
hid_t
dataset
=
H5Dcreate
(
handle
,
mDataHierarchy
.
back
().
c_str
(),
array
.
getHDF5Type
(),
dataspace
,
H5P_DEFAULT
,
H5P_DEFAULT
,
H5P_DEFAULT
);
hid_t
dataset
=
H5Dcreate
(
handle
,
mImpl
->
mDataHierarchy
.
back
().
c_str
(),
array
.
getHDF5Type
(),
dataspace
,
H5P_DEFAULT
,
H5P_DEFAULT
,
H5P_DEFAULT
);
status
=
H5Dwrite
(
dataset
,
array
.
getHDF5Type
(),
H5S_ALL
,
H5S_ALL
,
H5P_DEFAULT
,
array
.
getValuesPointer
());
if
(
groupName
.
compare
(
""
)
!=
0
)
{
...
...
@@ -99,7 +120,7 @@ std::string XdmfHDF5Writer::visit(XdmfArray & array, boost::shared_ptr<Loki::Bas
status
=
H5Sclose
(
dataspace
);
std
::
stringstream
dataSetName
;
dataSetName
<<
mHeavyFileName
<<
":"
<<
groupName
<<
"/"
<<
mDataHierarchy
.
back
();
dataSetName
<<
mImpl
->
mHeavyFileName
<<
":"
<<
groupName
<<
"/"
<<
mImpl
->
mDataHierarchy
.
back
();
return
dataSetName
.
str
();
}
...
...
XdmfHDF5Writer.hpp
View file @
f8cd6652
...
...
@@ -5,7 +5,6 @@
class
XdmfArray
;
// Includes
#include <hdf5.h>
#include "XdmfVisitor.hpp"
/**
...
...
@@ -64,6 +63,11 @@ protected:
private:
/**
* PIMPL
*/
class
XdmfHDF5WriterImpl
;
XdmfHDF5Writer
(
const
XdmfHDF5Writer
&
hdf5Writer
);
// Not implemented.
void
operator
=
(
const
XdmfHDF5Writer
&
hdf5Writer
);
// Not implemented.
...
...
@@ -86,9 +90,7 @@ private:
*/
std
::
string
getHDF5GroupHandle
();
std
::
vector
<
std
::
string
>
mDataHierarchy
;
hid_t
mHDF5Handle
;
std
::
string
mHeavyFileName
;
XdmfHDF5WriterImpl
*
mImpl
;
};
#endif
/* XDMFWRITER_HPP_ */
#endif
/* XDMF
HDF5
WRITER_HPP_ */
XdmfWriter.cpp
View file @
f8cd6652
// Kenneth Leiter
// Xdmf Smart Pointer Test
#include <libxml/tree.h>
#include <sstream>
#include "XdmfArray.hpp"
#include "XdmfItem.hpp"
#include "XdmfHDF5Writer.hpp"
#include "XdmfWriter.hpp"
/**
* PIMPL
*/
class
XdmfWriter
::
XdmfWriterImpl
{
public:
XdmfWriterImpl
()
:
mHDF5Writer
(
XdmfHDF5Writer
::
New
()),
mLightDataLimit
(
100
),
mXMLDocument
(
xmlNewDoc
((
xmlChar
*
)
"1.0"
)),
mXMLCurrentNode
(
xmlNewNode
(
NULL
,
(
xmlChar
*
)
"Xdmf"
))
{
xmlDocSetRootElement
(
mXMLDocument
,
mXMLCurrentNode
);
};
~
XdmfWriterImpl
()
{
xmlSaveFormatFile
(
"output.xmf"
,
mXMLDocument
,
1
);
xmlFreeDoc
(
mXMLDocument
);
xmlCleanupParser
();
};
boost
::
shared_ptr
<
XdmfHDF5Writer
>
mHDF5Writer
;
std
::
string
mHeavyFileName
;
unsigned
int
mLightDataLimit
;
xmlDocPtr
mXMLDocument
;
xmlNodePtr
mXMLCurrentNode
;
};
XdmfWriter
::
XdmfWriter
()
:
mHDF5Writer
(
XdmfHDF5Writer
::
New
()),
mLightDataLimit
(
100
),
mXMLDocument
(
xmlNewDoc
((
xmlChar
*
)
"1.0"
)),
mXMLCurrentNode
(
xmlNewNode
(
NULL
,
(
xmlChar
*
)
"Xdmf"
))
mImpl
(
new
XdmfWriterImpl
())
{
xmlDocSetRootElement
(
mXMLDocument
,
mXMLCurrentNode
);
std
::
cout
<<
"Created XdmfWriter "
<<
this
<<
std
::
endl
;
}
XdmfWriter
::~
XdmfWriter
()
{
xmlSaveFormatFile
(
"output.xmf"
,
mXMLDocument
,
1
);
xmlFreeDoc
(
mXMLDocument
);
xmlCleanupParser
();
delete
mImpl
;
std
::
cout
<<
"Deleted XdmfWriter "
<<
this
<<
std
::
endl
;
}
unsigned
int
XdmfWriter
::
getLightDataLimit
()
const
{
return
mLightDataLimit
;
return
mImpl
->
mLightDataLimit
;
}
void
XdmfWriter
::
setLightDataLimit
(
unsigned
int
numValues
)
{
mLightDataLimit
=
numValues
;
mImpl
->
mLightDataLimit
=
numValues
;
}
void
XdmfWriter
::
visit
(
XdmfArray
&
array
,
boost
::
shared_ptr
<
Loki
::
BaseVisitor
>
visitor
)
{
this
->
visit
(
dynamic_cast
<
XdmfItem
&>
(
array
),
visitor
);
xmlNodePtr
parentNode
=
mXMLCurrentNode
;
mXMLCurrentNode
=
mXMLCurrentNode
->
children
;
xmlNodePtr
parentNode
=
mImpl
->
mXMLCurrentNode
;
mImpl
->
mXMLCurrentNode
=
mImpl
->
mXMLCurrentNode
->
children
;
std
::
stringstream
xmlTextValues
;
if
(
array
.
getSize
()
>
mLightDataLimit
)
if
(
array
.
getSize
()
>
mImpl
->
mLightDataLimit
)
{
xmlTextValues
<<
mHDF5Writer
->
visit
(
array
,
mHDF5Writer
);
xmlTextValues
<<
mImpl
->
mHDF5Writer
->
visit
(
array
,
mImpl
->
mHDF5Writer
);
}
else
{
xmlTextValues
<<
array
.
getValuesString
();
}
xmlAddChild
(
mXMLCurrentNode
,
xmlNewText
((
xmlChar
*
)
xmlTextValues
.
str
().
c_str
()));
mXMLCurrentNode
=
parentNode
;
xmlAddChild
(
mImpl
->
mXMLCurrentNode
,
xmlNewText
((
xmlChar
*
)
xmlTextValues
.
str
().
c_str
()));
mImpl
->
mXMLCurrentNode
=
parentNode
;
}
void
XdmfWriter
::
visit
(
XdmfItem
&
item
,
boost
::
shared_ptr
<
Loki
::
BaseVisitor
>
visitor
)
{
xmlNodePtr
parentNode
=
mXMLCurrentNode
;
mXMLCurrentNode
=
xmlNewChild
(
mXMLCurrentNode
,
NULL
,
(
xmlChar
*
)
item
.
getItemTag
().
c_str
(),
NULL
);
xmlNodePtr
parentNode
=
mImpl
->
mXMLCurrentNode
;
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
(
mXMLCurrentNode
,
(
xmlChar
*
)
iter
->
first
.
c_str
(),
(
xmlChar
*
)
iter
->
second
.
c_str
());
xmlNewProp
(
mImpl
->
mXMLCurrentNode
,
(
xmlChar
*
)
iter
->
first
.
c_str
(),
(
xmlChar
*
)
iter
->
second
.
c_str
());
}
mHDF5Writer
->
pushDataHierarchy
(
item
);
mImpl
->
mHDF5Writer
->
pushDataHierarchy
(
item
);
item
.
traverse
(
visitor
);
mHDF5Writer
->
popDataHierarchy
();
mXMLCurrentNode
=
parentNode
;
mImpl
->
mHDF5Writer
->
popDataHierarchy
();
mImpl
->
mXMLCurrentNode
=
parentNode
;
}
XdmfWriter.hpp
View file @
f8cd6652
...
...
@@ -3,11 +3,8 @@
// Forward Declarations
class
XdmfArray
;
class
XdmfHDF5Writer
;
// Includes
#include <libxml/tree.h>
#include <vector>
#include "XdmfVisitor.hpp"
/**
...
...
@@ -62,14 +59,15 @@ protected:
private:
/**
* PIMPL
*/
class
XdmfWriterImpl
;
XdmfWriter
(
const
XdmfWriter
&
writer
);
// Not implemented.
void
operator
=
(
const
XdmfWriter
&
writer
);
// Not implemented.
boost
::
shared_ptr
<
XdmfHDF5Writer
>
mHDF5Writer
;
std
::
string
mHeavyFileName
;
unsigned
int
mLightDataLimit
;
xmlDocPtr
mXMLDocument
;
xmlNodePtr
mXMLCurrentNode
;
XdmfWriterImpl
*
mImpl
;
};
#endif
/* XDMFWRITER_HPP_ */
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