7 #ifndef __datatool_RecordView_h__ 8 #define __datatool_RecordView_h__ 10 #define FE_RV_VERBOSE (FE_CODEGEN<=FE_DEBUG) 11 #define FE_RV_CHECK (FE_CODEGEN<=FE_DEBUG) 14 #define FE_RV_R_CHECK (FE_CODEGEN<=FE_DEBUG) 17 #define FE_RV_WR_CHECK (FE_CODEGEN<=FE_DEBUG) 118 m_pWeakRecord(NULL) {}
125 { m_pWeakRecord=&rWeakRecord; }
133 feX(
"RecordView::RecordHolder" 135 "m_pWeakRecord NULL");
138 return *m_pWeakRecord;
152 const T operator()(
void)
const;
153 T& operator()(
const Record& r)
155 const T operator()(
const Record& r)
const 158 { checkWeakRecord(r);
161 { checkWeakRecord(r);
168 BWORD check(
void)
const 170 FEASSERT(m_pWeakRecord);
175 BWORD check(
const Record& r)
const 186 if(weakRecord().isValid() &&
202 if(weakRecord().isValid() &&
223 if(spHandlerI.isValid())
227 spHandlerI->handle(record);
239 FEASSERT(spScope.isValid());
242 if(!spComponent.isValid())
244 feX(
"Functor<>::createAndSetComponent",
245 "\"%s\" failed to create \"%s\"\n",
247 componentName.
c_str());
249 spComponent->setName(componentName+
" "+
name());
250 operator()()=spComponent;
260 FEASSERT(m_pWeakRecord);
262 FEASSERT(spRecordGroup.isValid());
264 spRecordGroup->setName(
name());
266 operator()()=spRecordGroup;
272 void checkRecordExists(
void)
const 275 if(!weakRecord().isValid())
277 feX(
"RecordView::checkRecordExists",
278 "WeakRecord invalid");
283 void checkWeakRecord(
const WeakRecord& r)
const 297 deregisterRegion(fe_cast<Counted>(
this));
305 registerRegion(fe_cast<Counted>(
this),
310 const String verboseName(
void)
const 311 {
return "RecordView " +
name(); }
321 FEASSERT(rspScope.isValid());
323 if(!m_hpScope.isValid())
325 AccessorSet::bind(rspScope);
329 else if(m_hpScope!=rspScope)
331 feX(
"RecordView::bind(sp<Scope>&) \"%s\"",
332 "changed scope",
name().c_str());
342 if(!m_hpScope.isValid())
344 AccessorSet::bind(rhpScope);
348 else if(m_hpScope!=rhpScope)
350 feX(
"RecordView::bind(hp<Scope>&) \"%s\"",
351 "changed scope",
name().c_str());
380 m_weakRecord=m_record;
388 if(!m_hpScope.isValid())
391 bind(record.
layout()->scope());
405 m_weakRecord=weakRecord;
408 if(!m_hpScope.isValid())
413 bind(weakRecord.
layout()->scope());
430 m_weakRecord=weakRecord;
471 if(!m_hpScope.isValid())
473 feX(
"RecordView::createRecord",
474 "\"%s\" has invalid scope\n",
479 if(!m_hpLayout.isValid())
481 feX(
"RecordView::createRecord",
482 "\"%s\" failed to create layout\n",
487 feX(
"RecordView::createRecord",
488 "\"%s\" failed to create record\n",
506 if(!m_hpScope.isValid())
508 feLog(
"RecordView::layout \"%s\" invalid scope\n",
512 if(!m_hpLayout.isValid())
514 m_hpLayout=createLayout();
523 for(U32 m=0;m<number;m++)
525 FEASSERT((*
this)[m]);
528 feLog(
"%2d %-16s %-16s <invalid record>\n",m,
529 nameOf(*(*
this)[m]).c_str(),
530 typeOf(*(*
this)[m]).c_str());
536 feLog(
"%2d %-16s %-16s <not locked>\n",m,
537 nameOf(*(*
this)[m]).c_str(),
538 typeOf(*(*
this)[m]).c_str());
543 feLog(
"%2d %-16s %-16s %s\n",m,
544 nameOf(*(*
this)[m]).c_str(),
545 typeOf(*(*
this)[m]).c_str(),
546 printOf(*(*
this)[m]).c_str());
597 template <
typename T>
610 String filename,BWORD a_binary=FALSE)
612 std::ifstream inFile(filename.
c_str());
616 feLog(
"RecordView::loadRecordGroup" 617 " could not open\n \"%s\"\n",
625 new data::BinaryStream(spScope)):
627 new data::AsciiStream(spScope)));
631 return spRecordGroup;
639 String buffer,BWORD a_binary=FALSE)
641 std::istringstream inString(buffer.
c_str());
645 feLog(
"RecordView::loadRecordGroupFromBuffer" 646 " could not open string buffer\n");
653 new data::BinaryStream(spScope)):
655 new data::AsciiStream(spScope));
658 return spRecordGroup;
667 String filename,BWORD a_binary=FALSE)
669 std::ofstream outfile(filename.
c_str());
672 feLog(
"RecordView::saveRecordGroup" 673 " could not open test output file\n");
679 new data::BinaryStream(spScope)):
681 new data::AsciiStream(spScope));
682 spStream->output(outfile, rspRecordGroup);
695 rFunctor.
setup(m_hpScope,name);
697 AccessorSet::add(rFunctor,name);
701 pHolder->bind(m_weakRecord);
713 if(!m_hpScope.isValid())
715 feX(
"AccessorArray::createLayout",
716 "\"%s\" has invalid scope\n",
721 if(!spLayout.isValid())
723 feX(
"AccessorArray::createLayout",
724 "\"%s\" failed to create layout\n",
737 std::list<String> nameList;
738 m_hpScope->registry()->master()->typeMaster()
739 ->reverseLookup(baseTypeOf(accessor),nameList);
740 return nameList.front();
745 void* pVoid=
record().rawAttribute(accessor.index());
748 return spInfo->print(pVoid);
754 baseTypeOf(accessor)->getInfo();
755 FEASSERT(spInfo.isValid());
762 return spAttribute->type();
815 inline BWORD operator==(
const RecordView& rRecordView1,
A heterogenous collection of records.
Definition: RecordGroup.h:35
Set of accessors.
Definition: AccessorSet.h:18
void createAndSetRecordGroup(void)
Create a RecordGroup for the attribute.
Definition: RecordView.h:258
const FESTRING_I8 * c_str(void) const
Return the contents of the 8-bit buffer cast as signed bytes.
Definition: String.h:352
bool isValid(void) const
Return true if the Record points to a valid state block.
Definition: RecordSB.h:184
void add(BaseAccessor &rFunctor, const char *name)
Add an attribute Functor.
Definition: RecordView.h:693
void bind(sp< Scope > &rspScope)
Associate with a Scope.
Definition: RecordView.h:319
kernel
Definition: namespace.dox:3
Bound accessor in a RecordView.
Definition: RecordView.h:147
void demandSerialNumber(void) const
throw if the record doesn't have a serial number
Definition: WeakRecordSB.cc:14
const sp< LayoutSB > & layout(void) const
Return the Layout.
Definition: WeakRecordSB.h:251
RecordHolder & operator=(const RecordHolder &rRecordHolder)
NOP: RecordView will handle copying.
Definition: RecordView.h:121
hp< Registry > registry(void) const
Get the Registry that created this component.
Definition: Component.cc:219
The main data access class for the data system.
Definition: Accessor.h:128
static void registerFactory(sp< Scope > spScope)
Indicate a RecordFactoryI for a Scope.
Definition: RecordView.h:598
sp< Layout > layout(void) const
Return the Layout.
Definition: RecordSB.h:189
hp< Scope > & scope(void)
Return associated Scope.
Definition: RecordView.h:357
BWORD operator!=(const DualString &s1, const DualString &s2)
Compare two DualString's (reverse logic)
Definition: DualString.h:229
static sp< RecordGroup > loadRecordGroup(sp< Scope > spScope, String filename, BWORD a_binary=FALSE)
Load a RecordGroup from a file.
Definition: RecordView.h:609
Component to create and initialize a Record.
Definition: RecordFactoryI.h:18
void call(void)
Call the attribute as a method.
Definition: RecordView.h:220
Type inspecific Accessor.
Definition: Accessor.h:26
virtual void finalize(Record &rRecord)
Finalize a Record using all the attributes.
Definition: RecordView.h:456
sp< Component > create(const String &a_pattern, BWORD quiet=FALSE) const
Instantiate a Component of the given named implementation.
Definition: Registry.cc:628
Untyped Functor base.
Definition: RecordView.h:113
Safe handle for shared pointer.
Definition: Handled.h:61
void safeSet(T value)
Set the value, checking first.
Definition: RecordView.h:199
sp< Attribute > attribute(void) const
Return the attribute this accessor is for.
Definition: Accessor.cc:151
WeakRecord record(void) const
Access the record by weak (fast) reference.
Definition: RecordView.h:498
void dump(void)
Spew attributes and state for the bound Record.
Definition: RecordView.h:520
void unbind(void)
Disassociate with any Record.
Definition: RecordView.h:362
Automatically reference-counted string container.
Definition: String.h:128
void bind(hp< Scope > &rhpScope)
Associate with a Scope by Handle.
Definition: RecordView.h:338
bool check(const RecordSB &r) const
Return true if record has attribute.
Definition: Accessor.h:314
void createAndSetComponent(String componentName)
Create a named component for the attribute.
Definition: RecordView.h:236
virtual void addFunctors(void)=0
Called at instantiation to add functors.
Record createRecord(void)
Create a Record using all the attributes.
Definition: RecordView.h:469
Bindable collection of accessor Functors.
Definition: RecordView.h:106
void bind(const WeakRecord weakRecord, BWORD weak=FALSE)
Associate with a specific WeakRecord.
Definition: RecordView.h:402
Reference to an instance of a Layout.
Definition: RecordSB.h:35
U32 index(void)
Return the current index into the RecordArray.
Definition: RecordView_spRA.h:592
static void saveRecordGroup(sp< Scope > spScope, sp< RecordGroup > &rspRecordGroup, String filename, BWORD a_binary=FALSE)
Save a RecordGroup to a file.
Definition: RecordView.h:665
virtual void initializeRecord(void)
Called at instantiation to initialize attributes.
Definition: RecordView.h:571
void setWeakRecord(const WeakRecord weakRecord)
Associate with a specific WeakRecord.
Definition: RecordView.h:427
bool isValid(void) const
Return true if the record points to the original valid state block.
Definition: WeakRecordSB.h:181
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53
const String & name(void) const
Return the components chosen name.
Definition: Component.h:77
static sp< RecordGroup > loadRecordGroupFromBuffer(sp< Scope > spScope, String buffer, BWORD a_binary=FALSE)
Serialize a RecordGroup from a string.
Definition: RecordView.h:638
virtual void finalizeRecord(void)
Called right after instantiation to finalize complex attributes.
Definition: RecordView.h:583
T safeGet(void)
Get the value, checking first.
Definition: RecordView.h:183
virtual void produce(Record &rRecord)
Produce a Record using all the attributes.
Definition: RecordView.h:436
void setName(const String &name)
Rename the component to anything you want.
Definition: Component.h:84
BWORD isValid(void) const
Returns true if the pointer is set.
Definition: Handled.h:179
void bind(const Record record, BWORD weak=FALSE)
Associate with a specific Record.
Definition: RecordView.h:377
T & operator()(const RecordSB &r)
Return the attribute.
Definition: Accessor.h:489
void registerFactory(String name, sp< RecordFactoryI > spRecordFactoryI)
Specify who can produce a named layout.
Definition: Scope.cc:524
void setup(sp< Scope > spScope, const String &attribute)
setup functions setup the accessor and also setup the Scope.
Definition: Accessor.cc:113
sp< Layout > layout(void)
Access a Layout of all the attributes.
Definition: RecordView.h:504
Non-persistent reference to an instance of a Layout.
Definition: WeakRecordSB.h:17