Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow default constructed DataAccessors #1080

Merged
merged 1 commit into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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