Skip to content

Commit

Permalink
allow default constructed DataAccessors (#1080)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrush committed Feb 17, 2023
1 parent 1255e71 commit ad0a255
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project aspires to adhere to [Semantic Versioning](https://semver.org/s
## Unreleased

### Added
- Added public default and copy constructor to DataAccessor. Enables more flexibility with initializing DataAccessors from Nodes.

#### General
- Added Node.name(), Node.path(), Schema.name(), and Schema.path() to Python API.
Expand Down
10 changes: 9 additions & 1 deletion src/libs/conduit/conduit_data_accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace conduit

//-----------------------------------------------------------------------------
//
// -- conduit::DataArray public methods --
// -- conduit::DataAccessor public methods --
//
//-----------------------------------------------------------------------------

Expand All @@ -34,6 +34,14 @@ DataAccessor<T>::DataAccessor()
m_dtype()
{}

//---------------------------------------------------------------------------//
template <typename T>
DataAccessor<T>::DataAccessor(const DataAccessor<T> &accessor)
: m_data(accessor.m_data),
m_dtype(accessor.m_dtype)
{}


//---------------------------------------------------------------------------//
template <typename T>
DataAccessor<T>::DataAccessor(void *data, const DataType &dtype)
Expand Down
5 changes: 4 additions & 1 deletion src/libs/conduit/conduit_data_accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class CONDUIT_API DataAccessor
//-----------------------------------------------------------------------------
// Construction and Destruction
//-----------------------------------------------------------------------------
/// Default constructor
DataAccessor();
/// Copy constructor
DataAccessor(const DataAccessor<T> &accessor);
/// Access a pointer to raw data according to dtype description.
DataAccessor(void *data, const DataType &dtype);
/// Access a const pointer to raw data according to dtype description.
Expand Down Expand Up @@ -92,7 +96,6 @@ class CONDUIT_API DataAccessor
// -- conduit::DataAccessor private data members --
//
//-----------------------------------------------------------------------------
DataAccessor();
/// holds data (always external, never allocated)
void *m_data;
/// holds data description
Expand Down
16 changes: 16 additions & 0 deletions src/tests/conduit/t_conduit_data_accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,22 @@ TEST(conduit_data_accessor, as_cstyle)

}

//-----------------------------------------------------------------------------
TEST(conduit_data_accessor, default_construct)
{
index_t_accessor n_acc;
Node n;
n.set({-1,2,-3,4,-5});

n_acc = n.value();
EXPECT_EQ(n_acc[0],(index_t)(-1));
EXPECT_EQ(n_acc[1],(index_t)( 2));
EXPECT_EQ(n_acc[2],(index_t)(-3));
EXPECT_EQ(n_acc[3],(index_t)( 4));
EXPECT_EQ(n_acc[4],(index_t)(-5));
}





Expand Down

0 comments on commit ad0a255

Please sign in to comment.