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 227 of file STLContainerStreamer.cc.

229  :
230  m_objectType( objectType ),
231  m_mappingElement( mapping ),
232  m_schema( contSchema ),
233  m_recordId(),
234  m_localElement(),
236  m_offset(0 ),
237  m_query(),
238  m_arrayHandler(),
239  m_keyReader(),
240  m_dataReader(){
241 }
std::auto_ptr< IRelationalReader > m_keyReader
bool isTypeAssociativeContainer(const Reflex::Type &typ)
Definition: ClassUtils.cc:202
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 243 of file STLContainerStreamer.cc.

243  {
244 }

Member Function Documentation

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

Implements ora::IRelationalReader.

Definition at line 246 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().

246  {
248  m_recordId.clear();
249  // allocate for the index...
250  m_recordId.push_back(0);
251 
252  RelationalStreamerFactory streamerFactory( m_schema );
253 
254  // first open the insert on the extra table...
255  m_query.reset( new MultiRecordSelectOperation( m_mappingElement.tableName(), m_schema.storageSchema() ));
256 
257  m_query->addWhereId( m_mappingElement.pkColumn() );
258  std::vector<std::string> recIdCols = m_mappingElement.recordIdColumns();
259  for( size_t i=0; i<recIdCols.size(); i++ ){
260  m_query->addId( recIdCols[ i ] );
261  m_query->addOrderId( recIdCols[ i ] );
262  }
263 
264  m_offset = &offset;
265 
267 
268  Reflex::Type valueType;
269  if ( m_associative ){
270 
272  Reflex::Type keyResolvedType = ClassUtils::resolvedType(keyType);
273 
274  if ( ! keyType ||!keyResolvedType ) {
275  throwException( "Missing dictionary information for the key type of the container \"" +
276  m_objectType.Name(Reflex::SCOPED) + "\"",
277  "STLContainerReader::build" );
278  }
279 
280  std::string keyName = keyType.Name();
281  // Retrieve the relevant mapping element
283  if ( iMe == m_mappingElement.end() ) {
284  throwException( "Item for \"" + keyName + "\" not found in the mapping element",
285  "STLContainerReader::build" );
286  }
287 
288  m_keyReader.reset( streamerFactory.newReader( keyResolvedType, iMe->second ) );
289  m_keyReader->build( m_localElement, *m_query );
290 
292  } else {
294  }
295 
296  Reflex::Type valueResolvedType = ClassUtils::resolvedType(valueType);
297  // Check the component type
298  if ( ! valueType ||!valueResolvedType ) {
299  throwException( "Missing dictionary information for the content type of the container \"" +
300  m_objectType.Name(Reflex::SCOPED) + "\"",
301  "STLContainerReader::build" );
302  }
303 
304  std::string valueName = valueType.Name();
305  // Retrieve the relevant mapping element
307  if ( iMe == m_mappingElement.end() ) {
308  throwException( "Item for \"" + valueName + "\" not found in the mapping element",
309  "STLContainerReader::build" );
310  }
311 
312  m_dataReader.reset( streamerFactory.newReader( valueResolvedType, iMe->second ) );
313  m_dataReader->build( m_localElement, *m_query );
314  return true;
315 }
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:349
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:333
Reflex::Type containerValueType(const Reflex::Type &typ)
Definition: ClassUtils.cc:317
Reflex::Type resolvedType(const Reflex::Type &typ)
Definition: ClassUtils.cc:380
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 338 of file STLContainerStreamer.cc.

References i, and ora::throwException().

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

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

References ora::throwException().

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

317  {
318  if(!m_query.get()){
319  throwException("The streamer has not been built.",
320  "STLContainerReader::read");
321  }
322  coral::AttributeList& whereData = m_query->whereData();
323  whereData[ m_mappingElement.pkColumn() ].data<int>() = oid;
324  m_query->execute();
325  if(m_keyReader.get()) m_keyReader->select( oid );
326  m_dataReader->select( oid );
327 }
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 329 of file STLContainerStreamer.cc.

References i.

329  {
330  m_recordId.clear();
331  for(size_t i=0;i<identity.size();i++) {
332  m_recordId.push_back( identity[i] );
333  }
334  // allocate the element for the index...
335  m_recordId.push_back( 0 );
336 }
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.