The Node class is the primary object in conduit.
Think of it as a hierarchical variant object.
../../tests/docs/t_conduit_docs_tutorial_basics.cpp
t_conduit_docs_tutorial_basics_out.txt
The Node class supports hierarchical construction.
../../tests/docs/t_conduit_docs_tutorial_basics.cpp
t_conduit_docs_tutorial_basics_out.txt
Borrowing form JSON (and other similar notations), collections of named nodes are called Objects and collections of unnamed nodes are called Lists, all other types are leaves that represent concrete data.
../../tests/docs/t_conduit_docs_tutorial_basics.cpp
t_conduit_docs_tutorial_basics_out.txt
You can use a NodeIterator ( or a NodeConstIterator) to iterate through a Node's children.
../../tests/docs/t_conduit_docs_tutorial_basics.cpp
t_conduit_docs_tutorial_basics_out.txt
Behind the scenes, Node instances manage a collection of memory spaces.
../../tests/docs/t_conduit_docs_tutorial_basics.cpp
t_conduit_docs_tutorial_basics_out.txt
There is no absolute path construct, all paths are fetched relative to the current node (a leading /
is ignored when fetching). Empty paths names are also ignored, fetching a///b
is equalvalent to fetching a/b
.
When sharing data in scientific codes, knowing the precision of the underlining types is very important.
Conduit uses well defined bitwidth style types (inspired by NumPy) for leaf values.
../../tests/docs/t_conduit_docs_tutorial_basics.cpp
t_conduit_docs_tutorial_basics_out.txt
Standard C++ numeric types will be mapped by the compiler to bitwidth style types.
../../tests/docs/t_conduit_docs_tutorial_basics.cpp
t_conduit_docs_tutorial_basics_out.txt
- Supported Bitwidth Style Types:
- signed integers: int8,int16,int32,int64
- unsigned integers: uint8,uint16,uint32,uint64
- floating point numbers: float32,float64
- Conduit provides these types by constructing a mapping for the current platform the from the following types:
- char, short, int, long, long long, float, double, long double
When C++11 support is enabled, Conduit's bitwidth style types will match the C++11 standard bitwidth types defined in <cstdint>
.
When a set method is called on a leaf Node, if the data passed to the set is compatible with the Node's Schema the data is simply copied.
When passed a compatible Node, Node methods update
and update_compatible
allow you to copy data into Node or extend a Node with new data without changing existing allocations.
Schemas do not need to be identical to be compatible.
You can check if a Schema is compatible with another Schema using the Schema::compatible(Schema &test) method. Here is the criteria for checking if two Schemas are compatible:
- If the calling Schema describes an Object : The passed test Schema must describe an Object and the test Schema's children must be compatible with the calling Schema's children that have the same name.
- If the calling Schema describes a List: The passed test Schema must describe a List, the calling Schema must have at least as many children as the test Schema, and when compared in list order each of the test Schema's children must be compatible with the calling Schema's children.
- If the calling Schema describes a leaf data type: The calling Schema's and test Schema's dtype().id() and dtype().element_bytes() must match, and the calling Schema dtype().number_of_elements() must be greater than or equal than the test Schema's.
For most uses cases in C++, Node references are the best solution to build and manipulate trees. They allow you to avoid expensive copies and pass around sub-trees without worrying about valid pointers.
../../tests/docs/t_conduit_docs_tutorial_basics.cpp
t_conduit_docs_tutorial_basics_out.txt
In C++ the Node assignment operator that takes a Node input is really an alias to set. That is, if follows set (deep copy) semantics.
../../tests/docs/t_conduit_docs_tutorial_basics.cpp
t_conduit_docs_tutorial_basics_out.txt
If you aren't careful, the ability to easily create dynamic trees can also undermine your process to consume them. For example, asking for an expected but non-existent path will return a reference to an empty Node. Surprise!
Methods like fetch_existing allow you to be more explicit when asking for expected data. In C++, const Node
references are also common way to process trees in an read-only fashion. const
methods will not modify the tree structure, so if you ask for a non-existent path, you will receive an error instead of reference to an empty Node.
../../tests/docs/t_conduit_docs_tutorial_basics.cpp
../../tests/docs/t_conduit_docs_tutorial_basics.cpp
t_conduit_docs_tutorial_basics_out.txt