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) 110 virtual public RecordFactoryI
120 m_pspRecordArray(NULL),
131 m_pspRecordArray=&rspRecordArray;
132 m_pWeakRecord=&rWeakRecord;
139 if(!m_pspRecordArray)
141 feX(
"RecordView::RecordHolder::array",
142 "m_pspRecordArray NULL");
145 return *m_pspRecordArray;
153 feX(
"RecordView::RecordHolder" 155 "m_pWeakRecord NULL");
158 return *m_pWeakRecord;
161 U32 arrayIndex(
void)
const {
return *m_pIndex; }
176 const T operator()(
void)
const;
177 T& operator()(
const Record& r)
179 const T operator()(
const Record& r)
const 182 { checkWeakRecord(r);
185 { checkWeakRecord(r);
192 BWORD check(
void)
const 194 FEASSERT(m_pspRecordArray);
195 FEASSERT(m_pWeakRecord);
196 FEASSERT((array()).isValid());
202 BWORD check(
const Record& r)
const 213 if(array().isValid() &&
215 array(),arrayIndex())))
219 if(weakRecord().isValid() &&
235 if(array().isValid() &&
237 array(),arrayIndex())))
241 if(weakRecord().isValid() &&
262 if(spHandlerI.isValid())
265 if(array().isValid())
267 record=array()->getRecord(
275 spHandlerI->handle(record);
287 FEASSERT(spScope.isValid());
290 if(!spComponent.isValid())
292 feX(
"Functor<>::createAndSetComponent",
293 "\"%s\" failed to create \"%s\"\n",
295 componentName.
c_str());
297 spComponent->setName(componentName+
" "+
name());
298 operator()()=spComponent;
308 FEASSERT(m_pspRecordArray);
309 FEASSERT(m_pWeakRecord);
312 FEASSERT(spRecordGroup.isValid());
314 spRecordGroup->setName(
name());
316 operator()()=spRecordGroup;
322 void checkRecordExists(
void)
const 325 if(weakRecord().isValid())
329 if(!array().isValid())
331 feX(
"RecordView::checkRecordExists",
332 "RecordArray invalid");
334 if(!array()->length())
336 feX(
"RecordView::checkRecordExists",
339 else if((
int)arrayIndex()>=array()->length())
341 feX(
"RecordView::checkRecordExists",
342 "looking for index %d in RA length %d",
343 arrayIndex(),array()->length());
348 void checkWeakRecord(
const WeakRecord& r)
const 365 deregisterRegion(fe_cast<Counted>(
this));
373 registerRegion(fe_cast<Counted>(
this),
378 const String verboseName(
void)
const 379 {
return "RecordView " +
name(); }
391 FEASSERT(rspScope.isValid());
393 if(!m_hpScope.isValid())
395 AccessorSet::bind(rspScope);
399 else if(m_hpScope!=rspScope)
401 feX(
"RecordView::bind(sp<Scope>&) \"%s\"",
402 "changed scope",
name().c_str());
412 if(!m_hpScope.isValid())
414 AccessorSet::bind(rhpScope);
418 else if(m_hpScope!=rhpScope)
420 feX(
"RecordView::bind(hp<Scope>&) \"%s\"",
421 "changed scope",
name().c_str());
439 if(m_spRecordArray==rspRecordArray)
442 m_spRecordArray=rspRecordArray;
444 if(!m_hpScope.isValid())
447 bind(rspRecordArray->layout()->scope());
456 m_spRecordArray=NULL;
476 if(m_tempArray && m_spRecordArray.isValid())
478 m_spRecordArray->clear();
482 m_spRecordArray=NULL;
487 if(m_tempArray && m_spRecordArray.isValid() &&
488 m_spRecordArray->layout()!=record.
layout())
491 feLog(
"RecordView::bind(Record) \"%s\" tempArray" 492 " switching type from \"%s\"" 495 m_spRecordArray->layout()->name().
c_str(),
496 record.
layout()->name().c_str());
501 m_spRecordArray=NULL;
504 m_spRecordArray->clear();
505 m_spRecordArray->setLayout(record.
layout());
506 m_spRecordArray->setWeak(weak);
509 else if(!m_tempArray || !m_spRecordArray.isValid())
512 feLog(
"RecordView::bind(Record)" 513 " \"%s\" new \"%s\"\n",
515 record.
layout()->name().c_str());
518 m_spRecordArray->
setWeak(weak);
522 m_spRecordArray->clear();
527 if(!m_spRecordArray.isValid() ||
528 !m_spRecordArray->add(record))
530 feX(
"RecordView::bind(Record)",
531 "failed to create and populate RA \"%s\"",
535 if(!m_hpScope.isValid())
538 bind(record.
layout()->scope());
542 void bind(
const WeakRecord weakRecord,BWORD weak=FALSE)
544 m_weakRecord=weakRecord;
548 m_spRecordArray=NULL;
552 if(!m_hpScope.isValid())
555 bind(weakRecord.
layout()->scope());
579 if(m_spRecordArray.isValid() &&
580 I32(m_nextIndex)<m_spRecordArray->length())
582 assignIndex(m_nextIndex);
584 return !m_spRecordArray->isWeak() ||
635 if(!m_hpScope.isValid())
637 feX(
"RecordView::createRecord",
638 "\"%s\" has invalid scope\n",
643 if(!m_hpLayout.isValid())
645 feX(
"RecordView::createRecord",
646 "\"%s\" failed to create layout\n",
651 feX(
"RecordView::createRecord",
652 "\"%s\" failed to create record\n",
664 if(m_spRecordArray.isValid())
665 return m_spRecordArray->getWeakRecord(m_index);
673 if(!m_hpScope.isValid())
675 feLog(
"RecordView::layout \"%s\" invalid scope\n",
679 if(!m_hpLayout.isValid())
683 m_hpLayout=createLayout();
692 for(U32 m=0;m<number;m++)
694 FEASSERT((*
this)[m]);
697 feLog(
"%2d %-16s %-16s <invalid record>\n",m,
698 nameOf(*(*
this)[m]).c_str(),
699 typeOf(*(*
this)[m]).c_str());
705 feLog(
"%2d %-16s %-16s <not locked>\n",m,
706 nameOf(*(*
this)[m]).c_str(),
707 typeOf(*(*
this)[m]).c_str());
712 feLog(
"%2d %-16s %-16s %s\n",m,
713 nameOf(*(*
this)[m]).c_str(),
714 typeOf(*(*
this)[m]).c_str(),
715 printOf(*(*
this)[m]).c_str());
766 template <
typename T>
779 String filename,BWORD a_binary=FALSE)
781 std::ifstream inFile(filename.
c_str());
785 feLog(
"RecordView::loadRecordGroup" 786 " could not open\n \"%s\"\n",
794 new data::BinaryStream(spScope)):
796 new data::AsciiStream(spScope)));
800 return spRecordGroup;
804 String buffer,BWORD a_binary=FALSE)
806 std::istringstream inString(buffer.
c_str());
810 feLog(
"RecordView::loadRecordGroupFromBuffer" 811 " could not open string buffer\n");
818 new data::BinaryStream(spScope)):
820 new data::AsciiStream(spScope));
823 return spRecordGroup;
832 String filename,BWORD a_binary=FALSE)
834 std::ofstream outfile(filename.
c_str());
837 feLog(
"RecordView::saveRecordGroup" 838 " could not open test output file\n");
844 new data::BinaryStream(spScope)):
846 new data::AsciiStream(spScope));
847 spStream->output(outfile, rspRecordGroup);
860 rFunctor.
setup(m_hpScope,name);
862 AccessorSet::add(rFunctor,name);
866 pHolder->bind(m_spRecordArray,m_weakRecord,m_index);
875 void assignIndex(U32
index)
878 if(!m_spRecordArray.isValid())
880 feLog(
"RecordView::assignIndex \"%s\"" 881 " no m_spRecordArray bound\n",
886 #if FE_RV_CHECK || 0//FE_PREFETCHING 887 const U32 length=m_spRecordArray->length();
890 if(U32(index) >= length)
892 feLog(
"RecordView::assignIndex \"%s\"" 893 " index out of bounds (%d/%d)\n",
894 name().c_str(),index,
895 m_spRecordArray->
length());
898 #if 0//FE_PREFETCHING 901 FEPREFETCH_READ(m_spRecordArray->data(index+2));
909 if(!m_hpScope.isValid())
911 feX(
"AccessorArray::createLayout",
912 "\"%s\" has invalid scope\n",
917 if(!spLayout.isValid())
919 feX(
"AccessorArray::createLayout",
920 "\"%s\" failed to create layout\n",
935 std::list<String> nameList;
936 m_hpScope->registry()->master()->typeMaster()
937 ->reverseLookup(baseTypeOf(accessor),nameList);
938 return nameList.front();
943 void* pVoid=
record().rawAttribute(accessor.index());
946 return spInfo->print(pVoid);
952 baseTypeOf(accessor)->getInfo();
953 FEASSERT(spInfo.isValid());
960 return spAttribute->type();
982 if(array().isValid())
999 if(array().isValid())
1014 checkRecordExists();
1017 if(array().isValid())
1039 checkRecordExists();
1042 if(array().isValid())
1056 inline BWORD operator==(
const RecordView& rRecordView1,
1059 return rRecordView1.record()==rRecordView2.record();
1065 return rRecordView1.record()!=rRecordView2.record();
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_spRA.h:306
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_spRA.h:858
void bind(sp< Scope > &rspScope)
Associate with a Scope.
Definition: RecordView_spRA.h:389
kernel
Definition: namespace.dox:3
Bound accessor in a RecordView.
Definition: RecordView.h:147
void bind(const sp< RecordArray > &rspRecordArray)
Associate with a specific RecordArray.
Definition: RecordView_spRA.h:433
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_spRA.h:125
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_spRA.h:767
sp< Layout > layout(void) const
Return the Layout.
Definition: RecordSB.h:189
hp< Scope > & scope(void)
Return associated Scope.
Definition: RecordView_spRA.h:427
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 the root RecordGroup from a file.
Definition: RecordView_spRA.h:778
void call(void)
Call the attribute as a method.
Definition: RecordView_spRA.h:259
Type inspecific Accessor.
Definition: Accessor.h:26
virtual void finalize(Record &rRecord)
Finalize a Record using all the attributes.
Definition: RecordView_spRA.h:620
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_spRA.h:232
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_spRA.h:689
void unbind(void)
Disassociate with any Record or RecordArray.
Definition: RecordView_spRA.h:454
Automatically reference-counted string container.
Definition: String.h:128
void bind(hp< Scope > &rhpScope)
Associate with a Scope by Handle.
Definition: RecordView_spRA.h:408
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_spRA.h:284
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
BWORD step(void)
Step through the records in the array.
Definition: RecordView_spRA.h:577
Bindable collection of accessor Functors.
Definition: RecordView.h:106
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 the root RecordGroup to a file.
Definition: RecordView_spRA.h:830
int count(void) const
Return the count of references.
Definition: Counted.h:156
void setIndex(U32 index)
Set the index into the bound RecordArray.
Definition: RecordView_spRA.h:563
virtual void initializeRecord(void)
Called at instantiation to initialize attributes.
Definition: RecordView.h:571
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_spRA.h:210
virtual void produce(Record &rRecord)
Produce a Record using all the attributes.
Definition: RecordView_spRA.h:600
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_spRA.h:468
T & operator()(const RecordSB &r)
Return the attribute.
Definition: Accessor.h:489
void setWeak(BWORD weak)
Choose weak referencing.
Definition: RecordArraySB.h:183
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
U32 length(void) const
Return the number of represented characters, but not necessarily the size of any buffer.
Definition: String.h:662
Homogeneous collection of Records.
Definition: RecordArraySB.h:40
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