HiveMind
BittyBuzzClosureRegister.h
Go to the documentation of this file.
1 #ifndef __BITTYBUZZCLOSUREREGISTER_H_
2 #define __BITTYBUZZCLOSUREREGISTER_H_
3 
5 #include "bittybuzz/BittyBuzzSettings.h"
6 #include <bbzvm.h>
7 #include <cpp-common/HashMapStack.h>
8 #include <cstdint>
9 #include <functional>
10 #include <string_view>
11 #include <tuple>
12 
14  public:
15  ~BittyBuzzClosureRegister() = default;
16 
17  bool registerClosure(const char* functionName,
18  bbzheap_idx_t closureHeapIdx,
19  bbzheap_idx_t selfHeapIdx,
20  const BittyBuzzFunctionDescription& description) override;
21 
22  void clearClosures() override;
23 
24  std::optional<std::reference_wrapper<const BittyBuzzRegisteredClosure>> getRegisteredClosure(
25  const char* functionName) const override;
26 
27  std::optional<std::reference_wrapper<const BittyBuzzRegisteredClosure>> getRegisteredClosure(
28  uint16_t idx) const override;
29 
30  uint16_t getRegisteredClosureLength() const override;
31 
32  constexpr static uint16_t m_maxSize = BBZ_CLOSURE_REGISTER_LENGTH;
33 
34  private:
35  HashMapStack<uint16_t, const char*, m_maxSize> m_closureNameRegisters;
36  HashMapStack<std::string_view, BittyBuzzRegisteredClosure, m_maxSize> m_closureRegisterMap;
37 };
38 
39 #endif // __BITTYBUZZCLOSUREREGISTER_H_
BittyBuzzClosureRegister::m_closureRegisterMap
HashMapStack< std::string_view, BittyBuzzRegisteredClosure, m_maxSize > m_closureRegisterMap
Definition: BittyBuzzClosureRegister.h:36
BittyBuzzClosureRegister
Definition: BittyBuzzClosureRegister.h:13
IBittyBuzzClosureRegister
A class to register buzz function/closures id and associate them with a string.
Definition: IBittyBuzzClosureRegister.h:24
BittyBuzzClosureRegister::getRegisteredClosure
std::optional< std::reference_wrapper< const BittyBuzzRegisteredClosure > > getRegisteredClosure(const char *functionName) const override
get the id of a stored function by it's associated name
Definition: BittyBuzzClosureRegister.cpp:55
BittyBuzzClosureRegister::clearClosures
void clearClosures() override
Clears all the registered closures.
Definition: BittyBuzzClosureRegister.cpp:49
BittyBuzzClosureRegister::m_closureNameRegisters
HashMapStack< uint16_t, const char *, m_maxSize > m_closureNameRegisters
Definition: BittyBuzzClosureRegister.h:35
BittyBuzzClosureRegister::registerClosure
bool registerClosure(const char *functionName, bbzheap_idx_t closureHeapIdx, bbzheap_idx_t selfHeapIdx, const BittyBuzzFunctionDescription &description) override
register a closure to the list
Definition: BittyBuzzClosureRegister.cpp:16
BittyBuzzClosureRegister::getRegisteredClosureLength
uint16_t getRegisteredClosureLength() const override
get the length/number of the registered closures
Definition: BittyBuzzClosureRegister.cpp:68
IBittyBuzzClosureRegister.h
BittyBuzzFunctionDescription
Description for a function, used for the FunctionDescriptionRequest/Response.
Definition: BittyBuzzFunctionDescription.h:11
BittyBuzzClosureRegister::m_maxSize
constexpr static uint16_t m_maxSize
Definition: BittyBuzzClosureRegister.h:32
BBZ_CLOSURE_REGISTER_LENGTH
#define BBZ_CLOSURE_REGISTER_LENGTH
Template file used by CMake to provide default or user-provided values for the settings of the BittyB...
Definition: BittyBuzzSettings.in.h:10
BittyBuzzClosureRegister::~BittyBuzzClosureRegister
~BittyBuzzClosureRegister()=default