Scroom 0.14-49-gb7ae7a6d
Loading...
Searching...
No Matches
Scroom::Utils::ParentContext Class Reference

#include <parent-context.hh>

Inheritance diagram for Scroom::Utils::ParentContext:
Inheritance graph
Collaboration diagram for Scroom::Utils::ParentContext:
Collaboration graph

Public Member Functions

 ParentContext (Context::Ptr first_)
 
void set (std::string name, std::any value) override
 
const std::any & get (std::string name) const override
 
std::any try_get (std::string name) const override
 
void add (const Context::ConstPtr &child) override
 
- Public Member Functions inherited from Interface
 Interface ()=default
 
 Interface (const Interface &)=delete
 
Interfaceoperator= (const Interface &)=delete
 
 Interface (Interface &&)=delete
 
Interfaceoperator= (Interface &&)=delete
 
virtual ~Interface ()=default
 

Private Attributes

Context::Ptr first
 
std::vector< Context::ConstPtrcontexts
 

Additional Inherited Members

- Public Types inherited from Scroom::Utils::RecursiveContext
using Ptr = std::shared_ptr< RecursiveContext >
 
- Public Types inherited from Scroom::Utils::Context
using Ptr = std::shared_ptr< Context >
 
using ConstPtr = std::shared_ptr< const Context >
 
- Static Public Member Functions inherited from Scroom::Utils::RecursiveContext
static Ptr create ()
 
- Static Public Member Functions inherited from Scroom::Utils::Context
static Ptr create ()
 

Constructor & Destructor Documentation

◆ ParentContext()

Scroom::Utils::ParentContext::ParentContext ( Context::Ptr  first_)
explicit
12 : first(std::move(first_))
13 {
14 require(this->first);
15 contexts.emplace_back(this->first);
16 }
#define require(expr)
Definition assertions.hh:30
Context::Ptr first
Definition parent-context.hh:28
std::vector< Context::ConstPtr > contexts
Definition parent-context.hh:29

Member Function Documentation

◆ add()

void Scroom::Utils::ParentContext::add ( const Context::ConstPtr child)
overridevirtual

Implements Scroom::Utils::RecursiveContext.

19 {
20 require(child);
21 contexts.emplace_back(std::move(child));
22 }

Referenced by ParentContextTests::ParentContextTests().

Here is the caller graph for this function:

◆ get()

const std::any & Scroom::Utils::ParentContext::get ( std::string  name) const
overridevirtual

Implements Scroom::Utils::Context.

27 {
28 for(const auto& context: contexts)
29 {
30 try
31 {
32 return context->get(name);
33 }
34 catch(name_not_found&)
35 {
36 // Try the next one
37 }
38 }
39
40 throw name_not_found();
41 }

◆ set()

void Scroom::Utils::ParentContext::set ( std::string  name,
std::any  value 
)
overridevirtual

Implements Scroom::Utils::Context.

24{ first->set(std::move(name), std::move(value)); }
const uint8_t value
Definition blob-tests.cc:114

◆ try_get()

std::any Scroom::Utils::ParentContext::try_get ( std::string  name) const
overridevirtual

Implements Scroom::Utils::Context.

44 {
45 std::any result;
46
47 for(const auto& context: contexts)
48 {
49 result = context->try_get(name);
50 if(result.has_value())
51 {
52 break;
53 }
54 }
55
56 return result;
57 }
SampleIterator< const uint8_t > result
Definition sampleiterator-tests.cc:94

Member Data Documentation

◆ contexts

std::vector<Context::ConstPtr> Scroom::Utils::ParentContext::contexts
private

Referenced by add(), get(), ParentContext(), and try_get().

◆ first

Context::Ptr Scroom::Utils::ParentContext::first
private

Referenced by ParentContext(), and set().


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