MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
cpptoml::array Class Reference

#include <cpptoml.h>

Inheritance diagram for cpptoml::array:
[legend]
Collaboration diagram for cpptoml::array:
[legend]

Public Types

using size_type = std::size_t
 
using iterator = std::vector< std::shared_ptr< base > >::iterator
 
using const_iterator = std::vector< std::shared_ptr< base > >::const_iterator
 

Public Member Functions

std::shared_ptr< baseclone () const override
 
MBool is_array () const override
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
std::vector< std::shared_ptr< base > > & get ()
 
const std::vector< std::shared_ptr< base > > & get () const
 
std::shared_ptr< baseat (size_t idx) const
 
template<class T >
std::vector< std::shared_ptr< value< T > > > array_of () const
 
template<class T >
array_of_trait< T >::return_type get_array_of () const
 
std::vector< std::shared_ptr< array > > nested_array () const
 
template<class T >
void push_back (const std::shared_ptr< value< T > > &val)
 
void push_back (const std::shared_ptr< array > &val)
 
template<class T >
void push_back (T &&val, typename value_traits< T >::type *=0)
 
template<class T >
iterator insert (iterator position, const std::shared_ptr< value< T > > &value)
 
iterator insert (iterator position, const std::shared_ptr< array > &value)
 
template<class T >
iterator insert (iterator position, T &&val, typename value_traits< T >::type *=0)
 
iterator erase (iterator position)
 
void clear ()
 
void reserve (size_type n)
 
 array (const array &obj)=delete
 
arrayoperator= (const array &obj)=delete
 
template<>
array_of_trait< array >::return_type get_array_of () const
 
- Public Member Functions inherited from cpptoml::base
virtual ~base ()=default
 
virtual std::shared_ptr< baseclone () const =0
 
virtual MBool is_value () const
 
virtual MBool is_table () const
 
std::shared_ptr< tableas_table ()
 
virtual MBool is_array () const
 
std::shared_ptr< arrayas_array ()
 
virtual MBool is_table_array () const
 
std::shared_ptr< table_arrayas_table_array ()
 
template<class T >
std::shared_ptr< value< T > > as ()
 
template<class T >
std::shared_ptr< const value< T > > as () const
 
template<class Visitor , class... Args>
void accept (Visitor &&visitor, Args &&... args) const
 
base_type type () const
 
template<>
std::shared_ptr< value< double > > as ()
 
template<>
std::shared_ptr< const value< double > > as () const
 

Private Member Functions

 array ()
 
 array ()=default
 
template<class InputIterator >
 array (InputIterator begin, InputIterator end)
 

Private Attributes

std::vector< std::shared_ptr< base > > values_
 

Friends

std::shared_ptr< arraymake_array ()
 

Additional Inherited Members

- Protected Member Functions inherited from cpptoml::base
 base (const base_type t)
 
 base ()
 

Detailed Description

Definition at line 673 of file cpptoml.h.

Member Typedef Documentation

◆ const_iterator

using cpptoml::array::const_iterator = std::vector<std::shared_ptr<base> >::const_iterator

arrays can be iterated over. Const version.

Definition at line 691 of file cpptoml.h.

◆ iterator

using cpptoml::array::iterator = std::vector<std::shared_ptr<base> >::iterator

arrays can be iterated over

Definition at line 686 of file cpptoml.h.

◆ size_type

using cpptoml::array::size_type = std::size_t

Definition at line 681 of file cpptoml.h.

Constructor & Destructor Documentation

◆ array() [1/4]

cpptoml::array::array ( )
inlineprivate

Definition at line 844 of file cpptoml.h.

845 // empty
846 }

◆ array() [2/4]

cpptoml::array::array ( )
privatedefault

◆ array() [3/4]

template<class InputIterator >
cpptoml::array::array ( InputIterator  begin,
InputIterator  end 
)
inlineprivate

Definition at line 852 of file cpptoml.h.

852 : values_{begin, end} {
853 // nothing
854 }
std::vector< std::shared_ptr< base > > values_
Definition: cpptoml.h:861
iterator end()
Definition: cpptoml.h:697
iterator begin()
Definition: cpptoml.h:693

◆ array() [4/4]

cpptoml::array::array ( const array obj)
delete

Member Function Documentation

◆ array_of()

template<class T >
std::vector< std::shared_ptr< value< T > > > cpptoml::array::array_of ( ) const
inline

Obtains an array of value<T>s. Note that elements may be nullptr if they cannot be converted to a value<T>.

Definition at line 718 of file cpptoml.h.

718 {
719 std::vector<std::shared_ptr<value<T>>> result(values_.size());
720
721 std::transform(values_.begin(), values_.end(), result.begin(),
722 [&](const std::shared_ptr<base>& v) { return v->as<T>(); });
723
724 return result;
725 }

◆ at()

std::shared_ptr< base > cpptoml::array::at ( size_t  idx) const
inline

Definition at line 711 of file cpptoml.h.

711{ return values_.at(idx); }

◆ begin() [1/2]

iterator cpptoml::array::begin ( )
inline

Definition at line 693 of file cpptoml.h.

693{ return values_.begin(); }

◆ begin() [2/2]

const_iterator cpptoml::array::begin ( ) const
inline

Definition at line 695 of file cpptoml.h.

695{ return values_.begin(); }

◆ clear()

void cpptoml::array::clear ( )
inline

Clear the array

Definition at line 833 of file cpptoml.h.

833{ values_.clear(); }

◆ clone()

std::shared_ptr< base > cpptoml::array::clone ( ) const
inlineoverridevirtual

Implements cpptoml::base.

Definition at line 1437 of file cpptoml.h.

1437 {
1438 auto result = make_array();
1439 result->reserve(values_.size());
1440 for(const auto& ptr : values_)
1441 result->values_.push_back(ptr->clone());
1442 return result;
1443}
friend std::shared_ptr< array > make_array()
Definition: cpptoml.h:873

◆ end() [1/2]

iterator cpptoml::array::end ( )
inline

Definition at line 697 of file cpptoml.h.

697{ return values_.end(); }

◆ end() [2/2]

const_iterator cpptoml::array::end ( ) const
inline

Definition at line 699 of file cpptoml.h.

699{ return values_.end(); }

◆ erase()

iterator cpptoml::array::erase ( iterator  position)
inline

Erase an element from the array

Definition at line 828 of file cpptoml.h.

828{ return values_.erase(position); }

◆ get() [1/2]

std::vector< std::shared_ptr< base > > & cpptoml::array::get ( )
inline

Obtains the array (vector) of base values.

Definition at line 704 of file cpptoml.h.

704{ return values_; }

◆ get() [2/2]

const std::vector< std::shared_ptr< base > > & cpptoml::array::get ( ) const
inline

Obtains the array (vector) of base values. Const version.

Definition at line 709 of file cpptoml.h.

709{ return values_; }

◆ get_array_of() [1/2]

template<class T >
array_of_trait< T >::return_type cpptoml::array::get_array_of ( ) const
inline

Obtains a option<vector<T>>. The option will be empty if the array contains values that are not of type T.

Definition at line 732 of file cpptoml.h.

732 {
733 std::vector<T> result;
734 result.reserve(values_.size());
735
736 for(const auto& val : values_) {
737 if(auto v = val->as<T>())
738 result.push_back(v->get());
739 else
740 return {};
741 }
742
743 return {std::move(result)};
744 }

◆ get_array_of() [2/2]

template<>
array_of_trait< array >::return_type cpptoml::array::get_array_of ( ) const
inline

Obtains a option<vector<T>>. The option will be empty if the array contains values that are not of type T.

Definition at line 895 of file cpptoml.h.

895 {
896 std::vector<std::shared_ptr<array>> result;
897 result.reserve(values_.size());
898
899 for(const auto& val : values_) {
900 if(auto v = val->as_array())
901 result.push_back(v);
902 else
903 return {};
904 }
905
906 return {std::move(result)};
907}

◆ insert() [1/3]

iterator cpptoml::array::insert ( iterator  position,
const std::shared_ptr< array > &  value 
)
inline

Insert an array into the array

Definition at line 809 of file cpptoml.h.

809 {
810 if(values_.empty() || values_[0]->is_array()) {
811 return values_.insert(position, value);
812 } else {
813 THROW_(array_exception, "Arrays must be homogenous.");
814 }
815 }

◆ insert() [2/3]

template<class T >
iterator cpptoml::array::insert ( iterator  position,
const std::shared_ptr< value< T > > &  value 
)
inline

Insert a value into the array

Definition at line 798 of file cpptoml.h.

798 {
799 if(values_.empty() || values_[0]->as<T>()) {
800 return values_.insert(position, value);
801 } else {
802 THROW_(array_exception, "Arrays must be homogenous.");
803 }
804 }

◆ insert() [3/3]

template<class T >
iterator cpptoml::array::insert ( iterator  position,
T &&  val,
typename value_traits< T >::type = 0 
)
inline

Convenience function for inserting a simple element in the array

Definition at line 821 of file cpptoml.h.

821 {
822 return insert(position, make_value(std::forward<T>(val)));
823 }
iterator insert(iterator position, const std::shared_ptr< value< T > > &value)
Definition: cpptoml.h:798
std::shared_ptr< typename value_traits< T >::type > make_value(T &&val)
Definition: cpptoml.h:588

◆ is_array()

MBool cpptoml::array::is_array ( ) const
inlineoverridevirtual

Determines if the TOML element is an array of "leaf" elements.

Reimplemented from cpptoml::base.

Definition at line 679 of file cpptoml.h.

679{ return true; }

◆ nested_array()

std::vector< std::shared_ptr< array > > cpptoml::array::nested_array ( ) const
inline

Obtains an array of arrays. Note that elements may be nullptr if they cannot be converted to a array.

Definition at line 750 of file cpptoml.h.

750 {
751 std::vector<std::shared_ptr<array>> result(values_.size());
752
753 std::transform(values_.begin(), values_.end(), result.begin(),
754 [&](const std::shared_ptr<base>& v) -> std::shared_ptr<array> {
755 if(v->is_array()) return std::static_pointer_cast<array>(v);
756 return std::shared_ptr<array>{};
757 });
758
759 return result;
760 }

◆ operator=()

array & cpptoml::array::operator= ( const array obj)
delete

◆ push_back() [1/3]

void cpptoml::array::push_back ( const std::shared_ptr< array > &  val)
inline

Add an array to the end of the array

Definition at line 777 of file cpptoml.h.

777 {
778 if(values_.empty() || values_[0]->is_array()) {
779 values_.push_back(val);
780 } else {
781 THROW_(array_exception, "Arrays must be homogenous.");
782 }
783 }

◆ push_back() [2/3]

template<class T >
void cpptoml::array::push_back ( const std::shared_ptr< value< T > > &  val)
inline

Add a value to the end of the array

Definition at line 766 of file cpptoml.h.

766 {
767 if(values_.empty() || values_[0]->as<T>()) {
768 values_.push_back(val);
769 } else {
770 THROW_(array_exception, "Arrays must be homogenous.");
771 }
772 }

◆ push_back() [3/3]

template<class T >
void cpptoml::array::push_back ( T &&  val,
typename value_traits< T >::type = 0 
)
inline

Convenience function for adding a simple element to the end of the array.

Definition at line 790 of file cpptoml.h.

790 {
791 push_back(make_value(std::forward<T>(val)));
792 }
void push_back(const std::shared_ptr< value< T > > &val)
Definition: cpptoml.h:766

◆ reserve()

void cpptoml::array::reserve ( size_type  n)
inline

Reserve space for n values.

Definition at line 838 of file cpptoml.h.

838{ values_.reserve(n); }

Friends And Related Function Documentation

◆ make_array

std::shared_ptr< array > make_array ( )
friend

Definition at line 873 of file cpptoml.h.

873 {
874#if not defined(MAIA_INTEL_COMPILER)
875 struct make_shared_enabler : public array {
876 make_shared_enabler() = default;
877 };
878
879 return std::make_shared<make_shared_enabler>();
880#else
881 return std::make_shared<ARRAY_::make_shared_enabler>();
882#endif
883}

Member Data Documentation

◆ values_

std::vector<std::shared_ptr<base> > cpptoml::array::values_
private

Definition at line 861 of file cpptoml.h.


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