CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
ora::STLContainerReader Class Reference

#include <STLContainerStreamer.h>

Inheritance diagram for ora::STLContainerReader:
ora::IRelationalReader

Public Member Functions

bool build (DataElement &offset, IRelationalData &relationalData)
 
void clear ()
 
void read (void *address)
 Reads a data element. More...
 
void select (int oid)
 
void setRecordId (const std::vector< int > &identity)
 
 STLContainerReader (const Reflex::Type &objectType, MappingElement &mapping, ContainerSchema &contSchema)
 Constructor. More...
 
virtual ~STLContainerReader ()
 
- Public Member Functions inherited from ora::IRelationalReader
virtual ~IRelationalReader ()
 

Private Attributes

std::auto_ptr< IArrayHandlerm_arrayHandler
 
bool m_associative
 
std::auto_ptr< IRelationalReaderm_dataReader
 
std::auto_ptr< IRelationalReaderm_keyReader
 
DataElement m_localElement
 
MappingElementm_mappingElement
 
Reflex::Type m_objectType
 
DataElementm_offset
 
std::auto_ptr
< MultiRecordSelectOperation
m_query
 
std::vector< int > m_recordId
 
ContainerSchemam_schema
 

Detailed Description

Definition at line 79 of file STLContainerStreamer.h.

Constructor & Destructor Documentation

ora::STLContainerReader::STLContainerReader ( const Reflex::Type &  objectType,
MappingElement mapping,
ContainerSchema contSchema 
)

Constructor.

Definition at line 232 of file STLContainerStreamer.cc.

234  :
235  m_objectType( objectType ),
236  m_mappingElement( mapping ),
237  m_schema( contSchema ),
238  m_recordId(),
239  m_localElement(),
241  m_offset(0 ),
242  m_query(),
243  m_arrayHandler(),
244  m_keyReader(),
245  m_dataReader(){
246 }
std::auto_ptr< IRelationalReader > m_keyReader
bool isTypeAssociativeContainer(const Reflex::Type &typ)
Definition: ClassUtils.cc:211
MappingElement & m_mappingElement
std::auto_ptr< IArrayHandler > m_arrayHandler
std::auto_ptr< MultiRecordSelectOperation > m_query
std::auto_ptr< IRelationalReader > m_dataReader
std::vector< int > m_recordId
ora::STLContainerReader::~STLContainerReader ( )
virtual

Definition at line 248 of file STLContainerStreamer.cc.

248  {
249 }

Member Function Documentation

bool ora::STLContainerReader::build ( DataElement offset,
IRelationalData relationalData 
)
virtual

Implements ora::IRelationalReader.

Definition at line 251 of file STLContainerStreamer.cc.

References ora::ClassUtils::containerDataType(), ora::ClassUtils::containerKeyType(), ora::ClassUtils::containerValueType(), i, ora::ArrayHandlerFactory::newArrayHandler(), ora::RelationalStreamerFactory::newReader(), evf::evtn::offset(), ora::ClassUtils::resolvedType(), and ora::throwException().

251  {
253  m_recordId.clear();
254  // allocate for the index...
255  m_recordId.push_back(0);
256 
257  RelationalStreamerFactory streamerFactory( m_schema );
258 
259  // first open the insert on the extra table...
260  m_query.reset( new MultiRecordSelectOperation( m_mappingElement.tableName(), m_schema.storageSchema() ));
261 
262  m_query->addWhereId( m_mappingElement.pkColumn() );
263  std::vector<std::string> recIdCols = m_mappingElement.recordIdColumns();
264  for( size_t i=0; i<recIdCols.size(); i++ ){
265  m_query->addId( recIdCols[ i ] );
266  m_query->addOrderId( recIdCols[ i ] );
267  }
268 
269  m_offset = &offset;
270 
272 
273  Reflex::Type valueType;
274  if ( m_associative ){
275 
277  Reflex::Type keyResolvedType = ClassUtils::resolvedType(keyType);
278 
279  if ( ! keyType ||!keyResolvedType ) {
280  throwException( "Missing dictionary information for the key type of the container \"" +
281  m_objectType.Name(Reflex::SCOPED) + "\"",
282  "STLContainerReader::build" );
283  }
284 
285  std::string keyName = keyType.Name();
286  // Retrieve the relevant mapping element
288  if ( iMe == m_mappingElement.end() ) {
289  throwException( "Item for \"" + keyName + "\" not found in the mapping element",
290  "STLContainerReader::build" );
291  }
292 
293  m_keyReader.reset( streamerFactory.newReader( keyResolvedType, iMe->second ) );
294  m_keyReader->build( m_localElement, *m_query );
295 
297  } else {
299  }
300 
301  Reflex::Type valueResolvedType = ClassUtils::resolvedType(valueType);
302  // Check the component type
303  if ( ! valueType ||!valueResolvedType ) {
304  throwException( "Missing dictionary information for the content type of the container \"" +
305  m_objectType.Name(Reflex::SCOPED) + "\"",
306  "STLContainerReader::build" );
307  }
308 
309  std::string valueName = valueType.Name();
310  // Retrieve the relevant mapping element
312  if ( iMe == m_mappingElement.end() ) {
313  throwException( "Item for \"" + valueName + "\" not found in the mapping element",
314  "STLContainerReader::build" );
315  }
316 
317  m_dataReader.reset( streamerFactory.newReader( valueResolvedType, iMe->second ) );
318  m_dataReader->build( m_localElement, *m_query );
319  return true;
320 }
std::auto_ptr< IRelationalReader > m_keyReader
int i
Definition: DBlmapReader.cc:9
MappingElement & m_mappingElement
Reflex::Type containerDataType(const Reflex::Type &typ)
Definition: ClassUtils.cc:373
std::auto_ptr< IArrayHandler > m_arrayHandler
std::auto_ptr< MultiRecordSelectOperation > m_query
std::vector< std::string > recordIdColumns() const
static IArrayHandler * newArrayHandler(const Reflex::Type &arrayType)
std::auto_ptr< IRelationalReader > m_dataReader
std::vector< int > m_recordId
iterator find(const std::string &key)
Retrieves a sub-element.
unsigned int offset(bool)
std::string pkColumn() const
std::map< std::string, MappingElement >::iterator iterator
Iterator definition.
Reflex::Type containerKeyType(const Reflex::Type &typ)
Definition: ClassUtils.cc:357
Reflex::Type containerValueType(const Reflex::Type &typ)
Definition: ClassUtils.cc:341
Reflex::Type resolvedType(const Reflex::Type &typ)
Definition: ClassUtils.cc:404
coral::ISchema & storageSchema()
iterator end()
Returns an iterator in the end of the sequence.
const std::string & tableName() const
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
void ora::STLContainerReader::clear ( void  )
virtual
void ora::STLContainerReader::read ( void *  address)
virtual

Reads a data element.

Implements ora::IRelationalReader.

Definition at line 343 of file STLContainerStreamer.cc.

References i, and ora::throwException().

Referenced by Vispa.Plugins.EdmBrowser.EdmDataAccessor.EdmDataAccessor::goto(), and Vispa.Plugins.EdmBrowser.EdmDataAccessor.EdmDataAccessor::setFilterBranches().

343  {
344 
345  if(!m_offset){
346  throwException("The streamer has not been built.",
347  "STLContainerReader::read");
348  }
349 
350  void* address = m_offset->address( destinationData );
351 
352  const Reflex::Type& iteratorReturnType = m_arrayHandler->iteratorReturnType();
353  U_Primitives primitiveStub;
354 
355  Reflex::Type keyType;
356  Reflex::Member firstMember;
357  Reflex::Member secondMember;
358  if ( m_associative ) {
359  keyType = m_objectType.TemplateArgumentAt(0);
360  firstMember = iteratorReturnType.MemberByName( "first" );
361  if ( ! firstMember ) {
362  throwException("Could not retrieve the data member \"first\" of the class \"" +
363  iteratorReturnType.Name(Reflex::SCOPED) + "\"",
364  "STLContainerReader::read" );
365  }
366  secondMember = iteratorReturnType.MemberByName( "second" );
367  if ( ! secondMember ) {
368  throwException( "Could not retrieve the data member \"second\" of the class \"" +
369  iteratorReturnType.Name(Reflex::SCOPED) + "\"",
370  "STLContainerReader::read" );
371  }
372  }
373 
374  bool isElementFundamental = iteratorReturnType.IsFundamental();
375 
376  m_arrayHandler->clear( address );
377 
378  size_t cursorSize = m_query->selectionSize(m_recordId, m_recordId.size()-1);
379  unsigned int i=0;
380  while ( i< cursorSize ){
381 
382  m_recordId[m_recordId.size()-1] = (int)i;
383  m_query->selectRow( m_recordId );
384 
385  // Create a new element for the array
386  void* objectData = 0;
387  if(isElementFundamental){
388  objectData = &primitiveStub;
389  } else {
390  objectData = iteratorReturnType.Construct().Address();
391  }
392 
393  void* componentData = objectData;
394  void* keyData = 0;
395 
396  if ( keyType ) { // treat the key object first
397  keyData = static_cast< char* >( objectData ) + firstMember.Offset();
398  m_keyReader->setRecordId( m_recordId );
399  m_keyReader->read( keyData );
400 
401  componentData = static_cast< char* >( objectData ) + secondMember.Offset();
402  }
403  m_dataReader->setRecordId( m_recordId );
404  m_dataReader->read( componentData );
405 
406  size_t prevSize = m_arrayHandler->size( address );
407  m_arrayHandler->appendNewElement( address, objectData );
408  bool inserted = m_arrayHandler->size( address )>prevSize;
409  if ( ! ( iteratorReturnType.IsFundamental() ) ) {
410  iteratorReturnType.Destruct( objectData );
411  }
412  if ( !inserted ) {
413  throwException( "Could not insert a new element in the array type \"" +
414  m_objectType.Name(Reflex::SCOPED) + "\"",
415  "STLContainerReader::read" );
416  }
417  ++i;
418  }
419 
420  m_arrayHandler->finalize( address );
421 
422 }
std::auto_ptr< IRelationalReader > m_keyReader
int i
Definition: DBlmapReader.cc:9
char * address
Definition: mlp_lapack.h:14
void * address(const void *topLevelAddress) const
Definition: DataElement.cc:48
std::auto_ptr< IArrayHandler > m_arrayHandler
std::auto_ptr< MultiRecordSelectOperation > m_query
std::auto_ptr< IRelationalReader > m_dataReader
std::vector< int > m_recordId
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
void ora::STLContainerReader::select ( int  oid)
virtual

Implements ora::IRelationalReader.

Definition at line 322 of file STLContainerStreamer.cc.

References ora::throwException().

Referenced by Vispa.Views.LineDecayView.LineDecayContainer::createObject(), Vispa.Plugins.Browser.BrowserTabController.BrowserTabController::find(), Vispa.Views.LineDecayView.LineDecayContainer::mousePressEvent(), Vispa.Gui.PortConnection.PointToPointConnection::mousePressEvent(), Vispa.Gui.VispaWidget.VispaWidget::mousePressEvent(), and Vispa.Views.AbstractView.AbstractView::restoreSelection().

322  {
323  if(!m_query.get()){
324  throwException("The streamer has not been built.",
325  "STLContainerReader::read");
326  }
327  coral::AttributeList& whereData = m_query->whereData();
328  whereData[ m_mappingElement.pkColumn() ].data<int>() = oid;
329  m_query->execute();
330  if(m_keyReader.get()) m_keyReader->select( oid );
331  m_dataReader->select( oid );
332 }
std::auto_ptr< IRelationalReader > m_keyReader
MappingElement & m_mappingElement
std::auto_ptr< MultiRecordSelectOperation > m_query
std::auto_ptr< IRelationalReader > m_dataReader
std::string pkColumn() const
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
void ora::STLContainerReader::setRecordId ( const std::vector< int > &  identity)
virtual

Implements ora::IRelationalReader.

Definition at line 334 of file STLContainerStreamer.cc.

References i.

334  {
335  m_recordId.clear();
336  for(size_t i=0;i<identity.size();i++) {
337  m_recordId.push_back( identity[i] );
338  }
339  // allocate the element for the index...
340  m_recordId.push_back( 0 );
341 }
int i
Definition: DBlmapReader.cc:9
std::vector< int > m_recordId

Member Data Documentation

std::auto_ptr<IArrayHandler> ora::STLContainerReader::m_arrayHandler
private

Definition at line 110 of file STLContainerStreamer.h.

bool ora::STLContainerReader::m_associative
private

Definition at line 107 of file STLContainerStreamer.h.

std::auto_ptr<IRelationalReader> ora::STLContainerReader::m_dataReader
private

Definition at line 112 of file STLContainerStreamer.h.

std::auto_ptr<IRelationalReader> ora::STLContainerReader::m_keyReader
private

Definition at line 111 of file STLContainerStreamer.h.

DataElement ora::STLContainerReader::m_localElement
private

Definition at line 104 of file STLContainerStreamer.h.

MappingElement& ora::STLContainerReader::m_mappingElement
private

Definition at line 101 of file STLContainerStreamer.h.

Reflex::Type ora::STLContainerReader::m_objectType
private

Definition at line 100 of file STLContainerStreamer.h.

DataElement* ora::STLContainerReader::m_offset
private

Definition at line 108 of file STLContainerStreamer.h.

std::auto_ptr<MultiRecordSelectOperation> ora::STLContainerReader::m_query
private

Definition at line 109 of file STLContainerStreamer.h.

std::vector<int> ora::STLContainerReader::m_recordId
private

Definition at line 103 of file STLContainerStreamer.h.

ContainerSchema& ora::STLContainerReader::m_schema
private

Definition at line 102 of file STLContainerStreamer.h.