12#ifndef LDNDC_STATE_SCRATCH_H_
13#define LDNDC_STATE_SCRATCH_H_
15#include "crabmeat-common.h"
17#include "nosql/cbm_kvstore.h"
18#include "string/cbm_string.h"
19#include "time/cbm_time.h"
23template <
typename _T >
24struct state_scratch_invalid_t
26 static _T
const value;
29struct CBM_API state_scratch_invalid_t< bool >
31 static bool const value;
36template <
typename _T >
37_T
const cbm::state_scratch_invalid_t< _T >::value =
38 ldndc::invalid_t< _T >::value;
42struct CBM_API state_scratch_t
44 typedef kvstore_t scratch_hashtable_t;
46 static void make_item_key(
48 char const * _format, ...)
51 va_start( args, _format);
52 *_key = cbm::string_t::format_t< 128 >::vmake( _format, args).str();
56 state_scratch_t() : T_expire( -1) {}
58 lerr_t initialize( cbm::sclock_t
const *);
59 lerr_t finalize( cbm::sclock_t
const *);
61 lerr_t run_garbage_collector( cbm::td_scalar_t );
89 template <
typename _T >
91 char const * , _T * )
const;
96 template <
typename _T >
99 _T * , _T
const & )
const;
107 template <
typename _T >
109 char const * , _T
const & ,
118 template <
typename _T >
120 char const * , _T
const & );
125 template <
typename _T >
127 char const * , _T * , _T
const & );
135 template <
typename _T >
136 lerr_t get_and_remove(
137 char const * , _T * );
142 template <
typename _T >
143 lerr_t get_and_remove(
155 scratch_hashtable_t ht;
156 cbm::td_scalar_t T_expire;
158 lerr_t expire_list_enqueue(
159 char const * , cbm::td_scalar_t );
160 lerr_t expire_list_remove(
166template <
typename _T >
168cbm::state_scratch_t::get(
169 char const * _key, _T * _reg)
172 return this->ht.fetch_pod< _T >( _reg, _key);
174template <
typename _T >
176cbm::state_scratch_t::get(
178 _T * _reg, _T
const & _default)
181 lerr_t rc_get = this->get< _T >( _key, _reg);
182 if ( rc_get == LDNDC_ERR_ATTRIBUTE_NOT_FOUND)
188 *_reg = state_scratch_invalid_t< _T >::value;
194template <
typename _T >
196cbm::state_scratch_t::set(
197 char const * _key, _T
const & _reg,
int _expire_time)
199 this->ht.store_pod< _T >( _key, _reg);
200 this->expire_list_enqueue( _key, _expire_time);
203template <
typename _T >
205cbm::state_scratch_t::addvalue(
206 char const * _key, _T
const & _add_value)
209 this->get( _key, &value, _T( 0));
210 this->set( _key, value + _add_value);
213template <
typename _T >
215cbm::state_scratch_t::get_and_set(
216 char const * _key, _T * _reg,
217 _T
const & _reset_value)
219 lerr_t
const rc_get = this->get( _key, _reg);
220 this->set( _key, _reset_value);
223template <
typename _T >
225cbm::state_scratch_t::get_and_remove(
226 char const * _key, _T * _reg)
228 return this->ht.fetch_and_remove_pod( _reg, _key);
230template <
typename _T >
232cbm::state_scratch_t::get_and_remove(
234 _T * _reg, _T
const & _default)
236 lerr_t rc_get = this->get_and_remove( _key, _reg);
237 if ( rc_get == LDNDC_ERR_ATTRIBUTE_NOT_FOUND)
243 *_reg = state_scratch_invalid_t< _T >::value;
The "Service Registry" holds information about available services (e.g., models, readers,...
Definition Lresources.h:51