7 #ifndef __datatool_Relay_h__ 8 #define __datatool_Relay_h__ 10 #define FE_RELAY_ASSERT TRUE //* for unmatched gets and sets 11 #define FE_RELAY_SAFE (FE_CODEGEN<=FE_DEBUG) //* query records safely 13 #define FE_RELAY_STORE_DEBUG TRUE 14 #define FE_RELAY_DEBUG (FE_RELAY_STORE_DEBUG && FE_CODEGEN<FE_DEBUG) 37 const char* typeAt(U32 index) {
return NULL; }
39 const char* nameAt(U32 index) {
return NULL; }
41 void initializeRecursively(
Record&) {}
51 virtual Record createRecord(
void) =0;
52 virtual Record createRecordAndBind(
void) =0;
64 m_name(
"CountedRelay"),
70 CoreRelay* relay(
void) {
return m_pRelay; }
73 const String& name(
void)
const {
return m_name; }
125 template<
int SIZE,
typename TYPE,
typename BASE=NoRelay>
131 e_totalSize=BASE::e_size+SIZE
134 Relay(
void) { FEASSERT(TYPE::e_size==BASE::e_size+SIZE); }
135 virtual ~
Relay(
void) {}
147 BWORD check(U32 index)
const;
151 BWORD checkType(U32 index)
const;
155 T& access(U32 index)
const;
163 T safeGet(U32 index)
const;
171 T
get(U32 index)
const;
175 void safeSet(U32 index,T value);
179 void set(U32 index,T value);
183 String print(U32 index)
const;
186 void dump(
void)
const;
192 virtual Record createRecord(
void);
213 const char* typeAt(U32 index);
217 const char* nameAt(U32 index);
219 void initializeRecursively(
Record& rRecord);
227 void createAndSetComponent(U32 index,
String componentName);
231 void createAndSetRecordGroup(U32 index);
241 virtual void initialize(
void) {}
248 #if FE_RELAY_STORE_DEBUG 250 String m_debugCache[e_totalSize];
254 template<
int SIZE,
typename TYPE,
typename BASE>
262 if(m_hpScope!=spScope && spScope.isValid())
264 if(m_hpScope.isValid())
265 feLog(
"Relay::bind Record changed scope\n");
271 if(!m_hpScope.isValid())
273 m_hpScope=record.
layout()->scope();
280 template<
int SIZE,
typename TYPE,
typename BASE>
287 template<
int SIZE,
typename TYPE,
typename BASE>
290 return m_pAccessorArray[index].check(m_record);
293 template<
int SIZE,
typename TYPE,
typename BASE>
297 sp<Attribute> spAttribute=m_hpScope->findAttribute(nameAt(index));
299 if(spBaseType->typeinfo().ref() !=
typeid(T))
301 feLog(
"Relay<>::checkType %s is %s not %s\n",
303 spBaseType->typeinfo().ref().name(),
313 template<
int SIZE,
typename TYPE,
typename BASE>
320 ->m_debugCache[index]=print(index);
324 ->queryAttribute(m_record));
327 (&m_pAccessorArray[index]))(m_record);
331 template<
int SIZE,
typename TYPE,
typename BASE>
335 #if FE_RELAY_SAFE && FE_RELAY_DEBUG 339 if(m_record.isValid() &&
341 (&m_pAccessorArray[index]))->queryAttribute(m_record)))
356 template<
int SIZE,
typename TYPE,
typename BASE>
364 feLog(
"Relay<>::get(%s) failed\n",nameAt(index));
369 return safeGet<T>(index);
372 (&m_pAccessorArray[index]))(m_record);
376 template<
int SIZE,
typename TYPE,
typename BASE>
380 #if FE_RELAY_SAFE && FE_RELAY_DEBUG 384 if(m_record.isValid() && (pValue=
reinterpret_cast<T*
> 385 (m_pAccessorArray[index].queryAttribute(m_record))))
389 m_debugCache[index]=print(index);
397 template<
int SIZE,
typename TYPE,
typename BASE>
405 feLog(
"Relay<>::set(%s) failed\n",nameAt(index));
409 safeSet(index,value);
412 (&m_pAccessorArray[index]))(m_record)=value;
416 template<
int SIZE,
typename TYPE,
typename BASE>
419 if(!m_hpScope.isValid())
425 sp<Attribute> spAttribute=m_hpScope->findAttribute(nameAt(index));
428 return spInfo->print(pVoid);
431 template<
int SIZE,
typename TYPE,
typename BASE>
434 for(U32 index=0;index<e_totalSize;index++)
435 feLog(
"%2d %-16s %-16s %s\n",index,typeAt(index),
436 nameAt(index),print(index).c_str());
439 template<
int SIZE,
typename TYPE,
typename BASE>
442 if(!m_hpScope.isValid())
443 feX(
"Relay::createRecord",
"no scope bound (%s)\n",TYPE::layoutName());
444 Record record=m_hpScope->createRecord(layout());
447 relay.initializeRecursively(record);
451 template<
int SIZE,
typename TYPE,
typename BASE>
454 if(!m_hpScope.isValid())
456 if(!m_hpLayout.isValid())
457 m_hpLayout=createLayout();
461 template<
int SIZE,
typename TYPE,
typename BASE>
464 if(index<BASE::e_size)
465 return BASE::typeAt(index);
467 return TYPE::attributes()[(index-BASE::e_size)*2];
470 template<
int SIZE,
typename TYPE,
typename BASE>
473 if(index<BASE::e_size)
474 return BASE::nameAt(index);
476 return TYPE::attributes()[(index-BASE::e_size)*2+1];
479 template<
int SIZE,
typename TYPE,
typename BASE>
483 base.initializeRecursively(rRecord);
488 template<
int SIZE,
typename TYPE,
typename BASE>
494 FEASSERT(rspComponent.isValid());
495 rspComponent->setName(nameAt(index));
498 template<
int SIZE,
typename TYPE,
typename BASE>
503 FEASSERT(rspRecordGroup.isValid());
507 template<
int SIZE,
typename TYPE,
typename BASE>
510 if(!m_hpScope.isValid())
512 for(U32 index=0;index<e_totalSize;index++)
513 m_pAccessorArray[index].initialize(m_hpScope,nameAt(index));
516 template<
int SIZE,
typename TYPE,
typename BASE>
519 if(!rspLayout.isValid())
520 feLog(
"Relay::populate layout not valid\n");
523 for(U32 index=0;index<e_totalSize;index++)
526 spScope->
support(nameAt(index),typeAt(index));
530 for(U32 index=0;index<e_totalSize;index++)
531 rspLayout->populate(nameAt(index));
534 template<
int SIZE,
typename TYPE,
typename BASE>
537 if(!m_hpScope.isValid())
538 feLog(
"Relay::createLayout scope not valid\n");
540 sp<Layout> spLayout=m_hpScope->declare(TYPE::layoutName());
A heterogenous collection of records.
Definition: RecordGroup.h:35
Counted wrapper for a CoreRelay.
Definition: Relay.h:59
void set(U32 index, T value)
Set the value of an entry, bypassing checks.
Definition: Relay.h:399
Heap-based support for classes participating in fe::ptr <>
Definition: Counted.h:35
sp< Attribute > support(const String &mayHave, const String &ofType)
Add a support for a Attribute with name and type of name ofType.
Definition: Scope.cc:818
kernel
Definition: namespace.dox:3
Generic interface to the Relay template.
Definition: Relay.h:47
bool queryAttribute(const RecordSB &r, T *&data)
Return true if the attribute exists in record.
Definition: Accessor.h:574
const sp< LayoutSB > & layout(void) const
Return the Layout.
Definition: WeakRecordSB.h:251
hp< Registry > registry(void) const
Get the Registry that created this component.
Definition: Component.cc:219
BWORD check(U32 index) const
Check if the bound Record supports the attribute.
Definition: Relay.h:288
void createAndSetComponent(U32 index, String componentName)
Construct and insert a Component into the given slot.
Definition: Relay.h:489
WeakRecord bind(WeakRecord record)
Bind all accessors to a given record.
Definition: Relay.h:255
static const char * nameAt(U32 index)
Returns the attribute's name.
Definition: Relay.h:471
BWORD checkType(U32 index) const
Verify that the attribute is the given type.
Definition: Relay.h:295
static void populate(sp< Layout > &rspLayout)
Populate the given Layout with this Relay's attributes.
Definition: Relay.h:517
void safeSet(U32 index, T value)
Set the value of an entry, if supported.
Definition: Relay.h:378
sp< Component > create(const String &a_pattern, BWORD quiet=FALSE) const
Instantiate a Component of the given named implementation.
Definition: Registry.cc:628
T safeGet(U32 index) const
Return the value of an entry, if supported.
Definition: Relay.h:333
void dump(void) const
Logs all entries with state.
Definition: Relay.h:432
Safe handle for shared pointer.
Definition: Handled.h:61
virtual Record createRecord(void)
Create a new Record.
Definition: Relay.h:440
Automatically reference-counted string container.
Definition: String.h:128
sp< Layout > layout(void)
Returns a Layout with the attributes of this relay.
Definition: Relay.h:452
Reference to an instance of a Layout.
Definition: RecordSB.h:35
sp< Scope > scope(void)
Returns the currently bound scope.
Definition: Relay.h:198
static const char * typeAt(U32 index)
Returns the attribute's type.
Definition: Relay.h:462
bool isValid(void) const
Return true if the record points to the original valid state block.
Definition: WeakRecordSB.h:181
T get(U32 index) const
Return the value of an entry, bypassing checks.
Definition: Relay.h:358
String print(U32 index) const
Returns a string representation of the entry's state.
Definition: Relay.h:417
WeakRecord & record(void)
Returns the currently bound record.
Definition: Relay.h:205
Default for BASE Relay template argument.
Definition: Relay.h:28
T & access(U32 index) const
Return a reference to the entry without checking.
Definition: Relay.h:315
Collection of accessors for a Record.
Definition: Relay.h:126
sp< Layout > createLayout(void)
Create or extend a layout.
Definition: Relay.h:535
virtual Record createRecordAndBind(void)
(convenience) Create and bind a new Record
Definition: Relay.h:195
void createAndSetRecordGroup(U32 index)
Construct and insert a RecordGroup Component into the given slot.
Definition: Relay.h:499
Non-persistent reference to an instance of a Layout.
Definition: WeakRecordSB.h:17