MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
cpptoml::base Class Referenceabstract

#include <cpptoml.h>

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

Public Member Functions

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
 

Protected Member Functions

 base (const base_type t)
 
 base ()
 

Private Attributes

const base_type type_ = base_type::NONE
 

Detailed Description

A generic base TOML value used for type erasure.

Definition at line 453 of file cpptoml.h.

Constructor & Destructor Documentation

◆ ~base()

virtual cpptoml::base::~base ( )
virtualdefault

◆ base() [1/2]

cpptoml::base::base ( const base_type  t)
inlineexplicitprotected

Definition at line 519 of file cpptoml.h.

519 : type_(t) {
520 // nothing
521 }
const base_type type_
Definition: cpptoml.h:524

◆ base() [2/2]

cpptoml::base::base ( )
inlineprotected

Definition at line 528 of file cpptoml.h.

528 {
529 // nothing
530 }

Member Function Documentation

◆ accept()

template<class Visitor , class... Args>
void cpptoml::base::accept ( Visitor &&  visitor,
Args &&...  args 
) const

base implementation of accept() that calls visitor.visit() on the concrete class.

Definition at line 2543 of file cpptoml.h.

2543 {
2544#if defined(MAIA_GCC_COMPILER)
2545#pragma GCC diagnostic push
2546#pragma GCC diagnostic ignored "-Wnull-dereference"
2547#endif
2548
2549 if(is_value()) {
2550 using value_acceptor =
2551 value_accept<std::string, int64_t, double, MBool, local_date, local_time, local_datetime, offset_datetime>;
2552 value_acceptor::accept(*this, std::forward<Visitor>(visitor), std::forward<Args>(args)...);
2553 } else if(is_table()) {
2554 visitor.visit(static_cast<const table&>(*this), std::forward<Args>(args)...);
2555 } else if(is_array()) {
2556 visitor.visit(static_cast<const array&>(*this), std::forward<Args>(args)...);
2557 } else if(is_table_array()) {
2558 visitor.visit(static_cast<const table_array&>(*this), std::forward<Args>(args)...);
2559 }
2560#if defined(MAIA_GCC_COMPILER)
2561#pragma GCC diagnostic pop
2562#endif
2563}
virtual MBool is_array() const
Definition: cpptoml.h:479
virtual MBool is_table_array() const
Definition: cpptoml.h:492
virtual MBool is_table() const
Definition: cpptoml.h:467
virtual MBool is_value() const
Definition: cpptoml.h:462

◆ as() [1/4]

template<class T >
std::shared_ptr< value< T > > cpptoml::base::as
inline

Attempts to coerce the TOML element into a concrete TOML value of type T.

Definition at line 595 of file cpptoml.h.

595 {
596#if defined(CPPTOML_NO_RTTI)
597 if(type() == base_type_traits<T>::type)
598 return std::static_pointer_cast<value<T>>(shared_from_this());
599 else
600 return nullptr;
601#else
602 return std::dynamic_pointer_cast<value<T>>(shared_from_this());
603#endif
604}
base_type type() const
Definition: cpptoml.h:516

◆ as() [2/4]

template<>
std::shared_ptr< value< double > > cpptoml::base::as ( )
inline

Definition at line 609 of file cpptoml.h.

609 {
610#if defined(CPPTOML_NO_RTTI)
611 if(type() == base_type::FLOAT) return std::static_pointer_cast<value<double>>(shared_from_this());
612
613 if(type() == base_type::INT) {
614 auto v = std::static_pointer_cast<value<int64_t>>(shared_from_this());
615 return make_value<double>(static_cast<double>(v->get()));
616 }
617#else
618 if(auto v = std::dynamic_pointer_cast<value<double>>(shared_from_this())) return v;
619
620 if(auto v = std::dynamic_pointer_cast<value<int64_t>>(shared_from_this()))
621 return make_value<double>(static_cast<double>(v->get()));
622#endif
623
624 return nullptr;
625}

◆ as() [3/4]

template<class T >
std::shared_ptr< const value< T > > cpptoml::base::as
inline

Definition at line 628 of file cpptoml.h.

628 {
629#if defined(CPPTOML_NO_RTTI)
630 if(type() == base_type_traits<T>::type)
631 return std::static_pointer_cast<const value<T>>(shared_from_this());
632 else
633 return nullptr;
634#else
635 return std::dynamic_pointer_cast<const value<T>>(shared_from_this());
636#endif
637}

◆ as() [4/4]

template<>
std::shared_ptr< const value< double > > cpptoml::base::as ( ) const
inline

Definition at line 642 of file cpptoml.h.

642 {
643#if defined(CPPTOML_NO_RTTI)
644 if(type() == base_type::FLOAT) return std::static_pointer_cast<const value<double>>(shared_from_this());
645
646 if(type() == base_type::INT) {
647 auto v = as<int64_t>();
648 // labels:IO the below has to be a non-const value<double> due to a bug in
649 // libc++: https://llvm.org/bugs/show_bug.cgi?id=18843
650 return make_value<double>(static_cast<double>(v->get()));
651 }
652#else
653 if(auto v = std::dynamic_pointer_cast<const value<double>>(shared_from_this())) return v;
654
655 if(auto v = as<int64_t>()) {
656 // labels:IO the below has to be a non-const value<double> due to a bug in
657 // libc++: https://llvm.org/bugs/show_bug.cgi?id=18843
658 return make_value<double>(static_cast<double>(v->get()));
659 }
660#endif
661
662 return nullptr;
663}

◆ as_array()

std::shared_ptr< array > cpptoml::base::as_array ( )
inline

Converts the TOML element to an array.

Definition at line 484 of file cpptoml.h.

484 {
485 if(is_array()) return std::static_pointer_cast<array>(shared_from_this());
486 return nullptr;
487 }

◆ as_table()

std::shared_ptr< table > cpptoml::base::as_table ( )
inline

Converts the TOML element into a table.

Definition at line 472 of file cpptoml.h.

472 {
473 if(is_table()) return std::static_pointer_cast<table>(shared_from_this());
474 return nullptr;
475 }

◆ as_table_array()

std::shared_ptr< table_array > cpptoml::base::as_table_array ( )
inline

Converts the TOML element into a table array.

Definition at line 497 of file cpptoml.h.

497 {
498 if(is_table_array()) return std::static_pointer_cast<table_array>(shared_from_this());
499 return nullptr;
500 }

◆ clone()

virtual std::shared_ptr< base > cpptoml::base::clone ( ) const
pure virtual

◆ is_array()

virtual MBool cpptoml::base::is_array ( ) const
inlinevirtual

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

Reimplemented in cpptoml::array.

Definition at line 479 of file cpptoml.h.

479{ return false; }

◆ is_table()

virtual MBool cpptoml::base::is_table ( ) const
inlinevirtual

Determines if the given TOML element is a table.

Reimplemented in cpptoml::table.

Definition at line 467 of file cpptoml.h.

467{ return false; }

◆ is_table_array()

virtual MBool cpptoml::base::is_table_array ( ) const
inlinevirtual

Determines if the given TOML element is an array of tables.

Reimplemented in cpptoml::table_array.

Definition at line 492 of file cpptoml.h.

492{ return false; }

◆ is_value()

virtual MBool cpptoml::base::is_value ( ) const
inlinevirtual

Determines if the given TOML element is a value.

Reimplemented in cpptoml::value< T >.

Definition at line 462 of file cpptoml.h.

462{ return false; }

◆ type()

base_type cpptoml::base::type ( ) const
inline

Definition at line 516 of file cpptoml.h.

516{ return type_; }

Member Data Documentation

◆ type_

const base_type cpptoml::base::type_ = base_type::NONE
private

Definition at line 524 of file cpptoml.h.


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