Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Ben Boeckel
Xdmf
Commits
9eb1f0c2
Commit
9eb1f0c2
authored
Apr 26, 2010
by
Kenneth Leiter
Browse files
ENH: Add resize() method to XdmfArray.
parent
364fcbb3
Changes
3
Hide whitespace changes
Inline
Side-by-side
XdmfArray.hpp
View file @
9eb1f0c2
...
...
@@ -147,7 +147,7 @@ public:
virtual
std
::
string
printSelf
()
const
;
/**
* Release
s
all data held by this XdmfArray.
* Release all data held by this XdmfArray.
*/
void
releaseData
()
{
...
...
@@ -155,6 +155,16 @@ public:
releaseArrayPointer
();
}
/**
* Resizes the XdmfArray to contain numValues. If numValues is larger than the current size, append values to end equal
* to val. If numValues is less than the current size, values at indices larger than numValues are removed.
*
* @param numValues the number of values to resize this array to.
* @param val the number to initialized newly created values to, if needed.
*/
template
<
typename
T
>
void
resize
(
const
unsigned
int
numValues
,
const
T
&
val
);
/**
* Sets the values of this array to the values stored in the arrayPointer array. No copy is made. Modifications to the array are
* not permitted through the XdmfArray API. Any calls through the XdmfArray API to modify the array (i.e. any non-const function)
...
...
@@ -244,6 +254,10 @@ private:
class
InternalizeArrayPointer
;
class
NewArray
;
template
<
typename
T
>
class
Resize
;
struct
NullDeleter
;
/**
...
...
XdmfArray.tpp
View file @
9eb1f0c2
...
...
@@ -41,6 +41,28 @@ private:
const
int
mValuesStride
;
};
template
<
typename
T
>
class
XdmfArray
::
Resize
:
public
boost
::
static_visitor
<
void
>
{
public:
Resize
(
const
unsigned
int
numValues
,
const
T
&
val
)
:
mNumValues
(
numValues
),
mVal
(
val
)
{
}
template
<
typename
U
>
void
operator
()(
boost
::
shared_ptr
<
std
::
vector
<
U
>
>
&
array
)
const
{
array
->
resize
(
mNumValues
,
(
U
)
mVal
);
}
private:
const
unsigned
int
mNumValues
;
const
T
&
mVal
;
};
struct
XdmfArray
::
NullDeleter
{
void
operator
()(
void
const
*
)
const
...
...
@@ -108,6 +130,20 @@ boost::shared_ptr<std::vector<T> > XdmfArray::initialize()
return
newArray
;
}
template
<
typename
T
>
void
XdmfArray
::
resize
(
const
unsigned
int
numValues
,
const
T
&
val
)
{
if
(
mHaveArrayPointer
)
{
internalizeArrayPointer
();
}
if
(
!
mHaveArray
)
{
initialize
<
T
>
();
}
return
boost
::
apply_visitor
(
Resize
<
T
>
(
numValues
,
val
),
mArray
);
}
template
<
typename
T
>
void
XdmfArray
::
setValues
(
const
T
*
const
arrayPointer
,
const
int
numValues
,
const
bool
transferOwnership
)
{
...
...
@@ -176,10 +212,6 @@ bool XdmfArray::swap(std::vector<T> & array)
{
boost
::
shared_ptr
<
std
::
vector
<
T
>
>
currArray
=
boost
::
get
<
boost
::
shared_ptr
<
std
::
vector
<
T
>
>
>
(
mArray
);
currArray
->
swap
(
array
);
//if(currArray->size() == 0)
//{
// mHaveArray = false;
//}
return
true
;
}
catch
(
const
boost
::
bad_get
&
exception
)
...
...
tests/Cxx/TestXdmfArray.cpp
View file @
9eb1f0c2
...
...
@@ -222,5 +222,17 @@ int main(int argc, char* argv[])
assert
(
array5
->
getSize
()
==
0
);
assert
(
array7
->
getSize
()
==
3
);
//
// Various STL like functions
//
boost
::
shared_ptr
<
XdmfArray
>
array8
=
XdmfArray
::
New
();
array8
->
copyValues
(
0
,
&
values
[
0
],
4
,
1
,
1
);
array8
->
resize
(
5
,
0
);
assert
(
array8
->
getValuesString
().
compare
(
"1 2 3 4 0 "
)
==
0
);
array8
->
resize
(
3
,
0
);
assert
(
array8
->
getValuesString
().
compare
(
"1 2 3 "
)
==
0
);
array8
->
resize
(
8
,
1.1
);
assert
(
array8
->
getValuesString
().
compare
(
"1 2 3 1 1 1 1 1 "
)
==
0
);
return
0
;
}
Write
Preview
Supports
Markdown
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