GlobalObjects
Alle Klassen Namensbereiche Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Freundbeziehungen Makrodefinitionen Seiten
GloTOndemand.h
gehe zur Dokumentation dieser Datei
1#ifndef INC_GLOTONDEMAND_H
2#define INC_GLOTONDEMAND_H
3//-----------------------------------------------------------------------------
43//-----------------------------------------------------------------------------
44#include "GloTypes.h"
45#include "GloReference.h"
46#include "GloBase.h"
47#include "GloObjID.h"
48#include "GloBasePersistent.h"
49//-----------------------------------------------------------------------------
50namespace glo
51{
52 //---------------------------------------------------------------------------
101 template < class T > class TOndemand : public Reference
102 {
103 public:
104 //============== Konstruktoren
105 //-----------------------------------------------------------------------
115 TOndemand();
116 //-----------------------------------------------------------------------
130 TOndemand( const ObjID & rObjID );
131 //-----------------------------------------------------------------------
145 TOndemand( Base & rBase );
146 //-----------------------------------------------------------------------
160 TOndemand( unsigned long ulDatabaseID );
161 //-----------------------------------------------------------------------
177 TOndemand( const ObjID & rObjID, Base & rBase );
178 //-----------------------------------------------------------------------
195 TOndemand( const ObjID & rObjID, unsigned long ulDatabaseID );
196 //-----------------------------------------------------------------------
208 TOndemand( const TOndemand & rT );
209 //-----------------------------------------------------------------------
219 virtual ~TOndemand();
220 //-----------------------------------------------------------------------
221
222 public:
223 //============== static methods
224 //-----------------------------------------------------------------------
236 static unsigned long getStaticGloClassID(){ return T::getStaticGloClassID();};
237 //-----------------------------------------------------------------------
238
239 //============== Methoden
240 //-----------------------------------------------------------------------
242
259 int set( const T * rObj );
260 int set( const T & rObj );
261 int set( const std::shared_ptr<T> & rObj );
263 //-----------------------------------------------------------------------
294 int get( T *& prObj );
295 //-----------------------------------------------------------------------
315 int get( std::shared_ptr<T> & rRetVal );
316 //-----------------------------------------------------------------------
332 virtual int setReference( const ObjID & rObjID ) override;
333 //-----------------------------------------------------------------------
334
335 public:
336 //============== Operatoren
337 //-----------------------------------------------------------------------
339
350 TOndemand< T > & operator= ( const TOndemand & rT );
351 //TOndemand< T > & operator= ( const Reference & rT );
353 //-----------------------------------------------------------------------
355
366 bool operator== ( const TOndemand & rT ) const;
367 bool operator!= ( const TOndemand & rT ) const;
369 //-----------------------------------------------------------------------
370 };
371 //---------------------------------------------------------------------------
372 #define SUPER Reference
373 //---------------------------------------------------------------------------
374 template < class T >
376 : SUPER()
377 {
378 #ifdef _DEBUG
379 m_strDebugInfo = "TOndemand";
380 #endif
381 }
382 //---------------------------------------------------------------------------
383 template < class T >
385 : SUPER( rObjID )
386 {
387 #ifdef _DEBUG
388 m_strDebugInfo = "TOndemand";
389 #endif
390 }
391 //---------------------------------------------------------------------------
392 template < class T >
394 : SUPER( rBase )
395 {
396 #ifdef _DEBUG
397 m_strDebugInfo = "TOndemand";
398 #endif
399 }
400 //---------------------------------------------------------------------------
401 template < class T >
402 TOndemand< T >::TOndemand( unsigned long ulDatabaseID )
403 : SUPER( ulDatabaseID )
404 {
405 #ifdef _DEBUG
406 m_strDebugInfo = "TOndemand";
407 #endif
408 }
409 //---------------------------------------------------------------------------
410 template < class T >
411 TOndemand< T >::TOndemand( const ObjID & rObjID, Base & rBase )
412 : SUPER( rObjID, rBase )
413 {
414 #ifdef _DEBUG
415 m_strDebugInfo = "TOndemand";
416 #endif
417 }
418 //---------------------------------------------------------------------------
419 template < class T >
420 TOndemand< T >::TOndemand( const ObjID & rObjID, unsigned long ulDatabaseID )
421 : SUPER( rObjID, ulDatabaseID )
422 {
423 #ifdef _DEBUG
424 m_strDebugInfo = "TOndemand";
425 #endif
426 }
427 //---------------------------------------------------------------------------
428 template < class T >
430 : SUPER( rT )
431 {
432 #ifdef _DEBUG
433 m_strDebugInfo = "TOndemand";
434 #endif
435 }
436 //---------------------------------------------------------------------------
437 template < class T >
441 //---------------------------------------------------------------------------
442 template < class T >
443 int TOndemand< T >::set( const T * pObj )
444 {
445 if ( ! pObj
446 ||
447 ( pObj
448 &&
449 ( T::getStaticGloClassID() == pObj->getGloClassID()
450 ||
451 T::isStaticSubClassID( pObj->getGloClassID() )
452 )
453 )
454 )
455 {
456 return SUPER::setReference( pObj );
457 }
458 return ERR_WRONG_TYPE;
459 }
460 //---------------------------------------------------------------------------
461 template < class T >
462 int TOndemand< T >::set( const T & rObj )
463 {
464 if ( T::getStaticGloClassID() == rObj.getGloClassID()
465 ||
466 T::isStaticSubClassID( rObj.getGloClassID() )
467 )
468 {
469 return SUPER::setReference( rObj );
470 }
471 return ERR_WRONG_TYPE;
472 }
473 //---------------------------------------------------------------------------
474 template < class T >
475 int TOndemand< T >::set( const std::shared_ptr<T> & spObj )
476 {
477 return this->set( spObj.get() );
478 }
479 //---------------------------------------------------------------------------
480 template < class T >
481 int TOndemand< T >::get( T *& prObj )
482 {
483 int t_iErr = 0;
484 BasePersistent * t_pGetObj = nullptr;
485
486 t_iErr = SUPER::getReference( t_pGetObj );
487 if ( ! t_iErr )
488 {
489 prObj = dynamic_cast<T*>( t_pGetObj );
490 if ( ! prObj )
491 {
492 t_pGetObj->forget();
493 t_iErr = ERR_WRONG_TYPE;
494 }
495 }
496 else
497 {
498 prObj = nullptr;
499 }
500 return t_iErr;
501 }
502 //---------------------------------------------------------------------------
503 template < class T >
504 int TOndemand< T >::get( std::shared_ptr<T> & rRetVal )
505 {
506 T * t_pPersObject = nullptr;
507 int t_iErr = this->get( t_pPersObject );
508
509 if ( t_pPersObject )
510 {
511 rRetVal.reset( t_pPersObject, Forgetter<T>() );
512 }
513 else
514 {
515 rRetVal.reset();
516 }
517 return t_iErr;
518 }
519 //---------------------------------------------------------------------------
520 template < class T >
522 {
523 if ( rObjID.isNULL()
524 ||
525 ( ! rObjID.isNULL()
526 &&
527 ( T::getStaticGloClassID() == rObjID.getClassID()
528 ||
529 T::isStaticSubClassID( rObjID.getClassID() )
530 )
531 )
532 )
533 {
534 return SUPER::setReference( rObjID );
535 }
536 return ERR_WRONG_TYPE;
537 }
538 //---------------------------------------------------------------------------
539 template < class T >
541 {
542 if ( this != & rT )
543 {
544 SUPER::operator=( rT );
545 }
546 return *this;
547 }
548 //---------------------------------------------------------------------------
549 //template < class T >
550 //TOndemand< T > & TOndemand< T >::operator= ( const Reference & rT )
551 //{
552 // if ( this != & rT )
553 // {
554 // SUPER::operator=( rT );
555 // }
556 // return *this;
557 //}
558 //---------------------------------------------------------------------------
559 template < class T >
560 bool TOndemand< T >::operator== ( const TOndemand & rT ) const
561 {
562 return SUPER::operator==( rT );
563 }
564 //---------------------------------------------------------------------------
565 template < class T >
566 bool TOndemand< T >::operator!= ( const TOndemand & rT ) const
567 {
568 if ( *this == rT )
569 {
570 return false;
571 }
572 return true;
573 }
574 //---------------------------------------------------------------------------
575 #undef SUPER
576 //---------------------------------------------------------------------------
577} // namespace glo
578#endif
Header für Base
Header für BasePersistent
Header für ObjID
Header für Reference
#define SUPER
Definition GloTAllSet.h:1300
Für jede Bibliothek, hier 'GlobalObjects' gibt es eine Typen-Datei.
Abstrakte Basisklasse für Persistent und die generische GenericPersistent.
Definition GloBasePersistent.h:124
virtual unsigned int forget()
std::string m_strDebugInfo
Definition GloCallBack.h:111
Speziel für GenericPersistent oder abgeleitete Klassen von Persistent die Forget-Methode für std::sha...
Definition GloTypes.h:1253
Ein Objekt-ID besteht aus der Klassen-ID, einer Datenbank-ID und der eigentlichen eindeutigen ObjektZ...
Definition GloObjID.h:84
unsigned long getClassID() const
bool isNULL() const
friend class Base
Definition GloReference.h:82
Referenz (als Attribut) eines persistenten Objekte auf ein anderes persistentes Objekt in der Datenba...
Definition GloTOndemand.h:102
int set(const T *rObj)
Übernimmt die Objekt-ID des übergeben Objekt als Referenz.
Definition GloTOndemand.h:443
bool operator==(const TOndemand &rT) const
Vergleichsoperator.
Definition GloTOndemand.h:560
virtual int setReference(const ObjID &rObjID) override
Definition GloTOndemand.h:521
virtual ~TOndemand()
Definition GloTOndemand.h:438
TOndemand()
Definition GloTOndemand.h:375
bool operator!=(const TOndemand &rT) const
Vergleichsoperator.
Definition GloTOndemand.h:566
static unsigned long getStaticGloClassID()
Definition GloTOndemand.h:236
TOndemand< T > & operator=(const TOndemand &rT)
Zuweisungsoperator.
Definition GloTOndemand.h:540
int get(T *&prObj)
Definition GloTOndemand.h:481
Definition GloAbstractBaseLot.h:49
@ ERR_WRONG_TYPE
Definition GloErrors.h:551