Gromacs  2020.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Member Functions
gmx::KeyValueTreePath Class Reference

#include <gromacs/utility/keyvaluetree.h>

Description

Identifies an entry in a key-value tree.

This class is mainly an internal utility within the key-value tree implementation, but it is exposed on the API level where string-based specification of a location in the tree is necessary. Constructors are not explicit to allow passing a simple string in contexts where a KeyValueTreePath is expected.

The string specifying a location should start with a /, followed by the names of the properties separated by /. For example, /a/b/c specifies property c in an object that is the value of b in an object that is the value of a at the root of the tree. Currently, there is no support for specifying paths to values within arrays (since none of the places where this is used implement array handling, either).

Public Member Functions

 KeyValueTreePath ()=default
 Creates an empty path (corresponds to the root object).
 
 KeyValueTreePath (const char *path)
 Creates a path from given string representation.
 
 KeyValueTreePath (const std::string &path)
 Creates a path from given string representation.
 
void append (const std::string &key)
 Adds another element to the path, making it a child of the old path.
 
void append (const KeyValueTreePath &other)
 Adds elements from another path to the path.
 
void pop_back ()
 Removes the last element in the path, making it the parent path.
 
std::string pop_last ()
 Removes and returns the last element in the path.
 
bool empty () const
 Whether the path is empty (pointing to the root object).
 
size_t size () const
 Returns the number of elements (=nesting level) in the path.
 
const std::string & operator[] (int i) const
 Returns the i'th path element.
 
const std::vector< std::string > & elements () const
 Returns all the path elements.
 
std::string toString () const
 Formats the path as a string for display.
 

The documentation for this class was generated from the following files: