# Poco::Dynamic

# template < typename K, typename M = std::map < K, Var >, typename S = std::set < K >>

# class Struct

Library: Foundation
Package: Dynamic
Header: Poco/Dynamic/Struct.h

## Description

Struct allows to define a named collection of Var objects.

## Member Summary

Member Functions: begin, clear, contains, empty, end, erase, find, getVar, insert, members, operator [], size, swap, toString

## Types Aliases

### ConstIterator

using ConstIterator = typename Data::const_iterator;

### Data

using Data = M;

### InsRetVal

using InsRetVal = typename std::pair < typename Struct < K, M, S >::Iterator, bool >;

### Iterator

using Iterator = typename Data::iterator;

### NameSet

using NameSet = S;

### Ptr

using Ptr = typename Poco::SharedPtr < Struct < K, M, S >>;

### SizeType

using SizeType = typename Struct < K >::Data::size_type;

### ValueType

using ValueType = typename Struct < K >::Data::value_type;

## Constructors

### Struct

Struct();

Creates an empty Struct

### Struct

Struct(
const Data & val
);

Creates the Struct from the given value.

### Struct

template < typename T > Struct(
const std::map < K, T > & val
);

### Struct

template < typename T > Struct(
const OrderedMap < K, T > & val
);

## Destructor

### ~Struct

virtual ~Struct() = default;

Destroys the Struct.

## Member Functions

### begin

inline Iterator begin();

Returns the begin iterator for the Struct

### begin

inline ConstIterator begin() const;

Returns the begin const iterator for the Struct

### clear

inline void clear();

Remove all elements from the struct

### contains

inline bool contains(
const K & name
) const;

Returns true if the Struct contains a member with the given name

### empty

inline bool empty() const;

Returns true if the Struct doesn't contain any members

### end

inline Iterator end();

Returns the end iterator for the Struct

### end

inline ConstIterator end() const;

Returns the end const iterator for the Struct

### erase

inline SizeType erase(
const K & key
);

Erases the element if found, returns number of elements deleted

### erase

inline void erase(
Iterator & it
);

Erases the element at the given position

### find

inline Iterator find(
const K & name
);

Returns an iterator, pointing to the <name,Var> pair containing the element, or it returns end() if the member was not found

### find

inline ConstIterator find(
const K & name
) const;

Returns a const iterator, pointing to the <name,Var> pair containing the element, or it returns end() if the member was not found

### getVar

inline Var getVar(
const K & key
) const;

Returns the var value of the element with the given name. Throws a NotFoundException if the key does not exist.

### getVar

template < typename DefT = Var > inline Var getVar(
const K & key,
const DefT & defaultValue
) const;

Returns the var value of the element with the given name. or defaultValue if none is found.

### insert

template < typename T > inline InsRetVal insert(
const K & key,
const T & value
);

Inserts a <name, Var> pair into the Struct, returns a pair containing the iterator and a boolean which indicates success or not (is true, when insert succeeded, false, when already another element was present, in this case Iterator points to that other element)

### insert

inline InsRetVal insert(
const ValueType & aPair
);

Inserts a <name, Var> pair into the Struct, returns a pair containing the iterator and a boolean which indicates success or not (is true, when insert succeeded, false, when already another element was present, in this case Iterator points to that other element)

### members

inline NameSet members() const;

Returns a sorted collection containing all member names

### operator []

inline Var & operator[] (
const K & name
);

Returns the Var with the given name, creates an entry if not found.

### operator []

const Var & operator[] (
const K & name
) const;

Returns the Var with the given name, throws a NotFoundException if the data member is not found.

### size

SizeType size() const;

Returns the number of members the Struct contains

### swap

inline void swap(
Struct & other
) noexcept;

Swap content of Struct with another Struct

### toString

std::string toString(
bool wrap = true
) const;

Returns the DynamicStruct as string.

To prevent unwanted string wrapping (eg. when a value is JSON string), wrap`should be false. Note, however, that wrap argument is of a limited utility because it applies to the entire Struct, so it should not be relied on when mixed content (ie. plain string, which should be wrapped, and JSON-as-string entries, which shouldn't) is held.`