BankAndCustomer
Alle Klassen Namensbereiche Dateien Funktionen Variablen Typdefinitionen 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#include "EuException.h"
50#include "memory"
51//-----------------------------------------------------------------------------
52namespace glo
53{
54 //---------------------------------------------------------------------------
68 //---------------------------------------------------------------------------
69 template <typename Base, typename Derived>
71 {
72 private:
73 //-----------------------------------------------------------------------
83 typedef char Yes;
84 //-----------------------------------------------------------------------
94 struct No { char dummy[2]; };
95 //-----------------------------------------------------------------------
108 static Yes Test( Base * );
109 //-----------------------------------------------------------------------
119 static No Test(...);
120 //-----------------------------------------------------------------------
130 template <typename T> struct IsClass
131 {
132 typedef char Yes[1];
133 typedef char No[2];
134
135 template <typename U> static Yes & Test( void( U::* )() );
136 template <typename U> static No & Test(...);
137
138 static const bool value = sizeof( Test<T>( 0 ) ) == sizeof( Yes );
139 };
140 //-----------------------------------------------------------------------
141
142 public:
143 //-----------------------------------------------------------------------
155 static const bool value = IsClass<Base>::value
157 && sizeof( Test( static_cast<Derived*>( 0 ) ) ) == sizeof(Yes);
158 };
159 //---------------------------------------------------------------------------
205 //---------------------------------------------------------------------------
206 #define SUPER Reference
207 //---------------------------------------------------------------------------
208 template < class T > class TOndemand : public Reference
209 {
210 public:
211 //============== Konstruktoren
212 //-----------------------------------------------------------------------
222 TOndemand();
223 //-----------------------------------------------------------------------
224
225 private:
226 //============== Konstruktoren
227 //-----------------------------------------------------------------------
241 TOndemand( const ObjID & rObjID );
242 //-----------------------------------------------------------------------
243
244 public:
245 //============== Konstruktoren
246 //-----------------------------------------------------------------------
248
259 TOndemand( const TOndemand & rT );
260 template <class T2> TOndemand( const TOndemand<T2> & rT );
262 //-----------------------------------------------------------------------
272 virtual ~TOndemand();
273 //-----------------------------------------------------------------------
274
275 public:
276 //============== static methods
277 //-----------------------------------------------------------------------
289 static unsigned long getStaticGloClassID(){ return T::getStaticGloClassID();};
290 //-----------------------------------------------------------------------
291
292 //============== Methoden
293 //-----------------------------------------------------------------------
295
308 int set( const T * rObj );
309 int set( const T & rObj );
310 int set( const std::shared_ptr<T> & rObj );
311 virtual int set( const ObjID & rObj ) override;
312 virtual int set( const BasePersistent * rObj ) override;
313 virtual int set( const BasePersistent & rObj ) override;
315 //-----------------------------------------------------------------------
346 int get( T *& prObj );
347 //-----------------------------------------------------------------------
367 int get( std::shared_ptr<T> & rRetVal );
368 //-----------------------------------------------------------------------
369
370 public:
371 //============== Operatoren
372 //-----------------------------------------------------------------------
374
385 TOndemand< T > & operator= ( const TOndemand & rT );
386 template <class T2> TOndemand<T> & operator= ( const TOndemand<T2> & rT );
387 /*
388 Notlösung ohne Fehlermeldung
389 TOndemand< T > & operator= ( const Reference & rT )
390 {
391 if ( this != & rT )
392 {
393 SUPER::operator=( rT );
394 }
395 return *this;
396 };
397 */
398 /*
399 Geht nur mit Visual Studio 2022
400 template <class T2, std::enable_if_t<std::_SP_pointer_compatible<T2, T>::value, int> = 0>
401 TOndemand& operator=(const TOndemand<T2>& rT)
402 {
403 SUPER::set( rT.getObjID() );
404 return *this;
405 };
406 */
407 /*
408 Von C++ Version 98 nicht unterstützt
409 template <class T2, typename = std::enable_if_t<std::is_base_of_v<T, T2>>>
410 TOndemand& operator=(const TOndemand<T2>& rT)
411 {
412 SUPER::set( rT.getObjID() );
413 return *this;
414 }
415 */
417 //-----------------------------------------------------------------------
419
430 bool operator== ( const TOndemand & rT ) const;
431 bool operator!= ( const TOndemand & rT ) const;
432 template <class T2> bool operator== ( const TOndemand<T2>& rT) const;
433 template <class T2> bool operator!= ( const TOndemand<T2>& rT) const;
434 /*
435 Notlösung ohne Fehlermeldung
436 bool operator== ( const Reference & rT ) const
437 {
438 return SUPER::operator==( rT );
439 };
440 bool operator!= ( const Reference & rT ) const
441 {
442 return SUPER::operator!=( rT );
443 };
444 */
445 /*
446 Geht nur mit Visual Studio 2022
447 template <class T2, std::enable_if_t<std::_SP_pointer_compatible<T2, T>::value, int> = 0>
448 bool operator==(const TOndemand<T2>& rT)
449 {
450 return SUPER::operator==( rT );
451 }
452 template <class T2, std::enable_if_t<std::_SP_pointer_compatible<T2, T>::value, int> = 0>
453 bool operator!=(const TOndemand<T2>& rT)
454 {
455 if ( *this == rT )
456 {
457 return false;
458 }
459 return true;
460 }
461 */
462 /*
463 Von C++ Version 98 nicht unterstützt
464 template <class T2, typename = std::enable_if_t<std::is_base_of_v<T, T2>>>
465 bool operator==(const TOndemand<T2>& rT)
466 {
467 return SUPER::operator==( rT );
468 }
469 template <class T2, typename = std::enable_if_t<std::is_base_of_v<T, T2>>>
470 bool operator!=(const TOndemand<T2>& rT)
471 {
472 return SUPER::operator!=( rT );
473 }
474 */
476 //-----------------------------------------------------------------------
477 };
478 //---------------------------------------------------------------------------
479 template < class T >
481 : SUPER()
482 {
483 #ifdef _DEBUG
484 m_strDebugInfo = "TOndemand";
485 #endif
486 }
487 //---------------------------------------------------------------------------
488 template < class T >
489 TOndemand< T >::TOndemand( const ObjID & /*rObjID*/ )
490 //: SUPER( rObjID )
491 {
492 #ifdef _DEBUG
493 m_strDebugInfo = "TOndemand";
494 #endif
495 throw eut::ErrorNException( "TOndemand ctor(const ObjID &, Base &)", ERR_NOT_IMPLEMENTED_YET, __FILE__, __LINE__ );
496 }
497 //---------------------------------------------------------------------------
498 template < class T >
500 : SUPER( rT )
501 {
502 #ifdef _DEBUG
503 m_strDebugInfo = "TOndemand";
504 #endif
505 }
506 //---------------------------------------------------------------------------
507 #if defined(__GNUC__)
508 // Warnung: unused variable 't_iDEBUG_XXX' [-Wunused-local-typedefs]
509 #pragma GCC diagnostic push
510 #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
511 #endif
512 //---------------------------------------------------------------------------
513 template < class T >
514 template <class T2>
516 : SUPER( rT )
517 {
518 /*
519 An error is generated here if the type to be compared is incompatible.
520 Check if the compiler output provides more information, such as the incorrect
521 call to the comparison operator.
522 */
523 typedef char TypeCheck[IsBaseClassOf<T, T2>::value ? 1 : -1]; // <- Error if not derived
524 #ifdef _DEBUG
525 m_strDebugInfo = "TOndemand";
526 #endif
527 }
528 //---------------------------------------------------------------------------
529 template < class T >
533 //---------------------------------------------------------------------------
534 template < class T >
535 int TOndemand< T >::set( const T * pObj )
536 {
537 if ( ! pObj
538 ||
539 ( pObj
540 &&
541 ( T::getStaticGloClassID() == pObj->getGloClassID()
542 ||
543 T::isStaticSubClassID( pObj->getGloClassID() )
544 )
545 )
546 )
547 {
548 return SUPER::set( pObj );
549 }
550 return ERR_WRONG_TYPE;
551 }
552 //---------------------------------------------------------------------------
553 template < class T >
554 int TOndemand< T >::set( const T & rObj )
555 {
556 if ( T::getStaticGloClassID() == rObj.getGloClassID()
557 ||
558 T::isStaticSubClassID( rObj.getGloClassID() )
559 )
560 {
561 return SUPER::set( rObj );
562 }
563 return ERR_WRONG_TYPE;
564 }
565 //---------------------------------------------------------------------------
566 template < class T >
567 int TOndemand< T >::set( const std::shared_ptr<T> & spObj )
568 {
569 return this->set( spObj.get() );
570 }
571 //---------------------------------------------------------------------------
572 template < class T >
573 int TOndemand< T >::set( const ObjID & rObjID )
574 {
575 if ( rObjID.isNULL()
576 ||
577 ( ! rObjID.isNULL()
578 &&
579 ( T::getStaticGloClassID() == rObjID.getClassID()
580 ||
581 T::isStaticSubClassID( rObjID.getClassID() )
582 )
583 )
584 )
585 {
586 return SUPER::set( rObjID );
587 }
588 return ERR_WRONG_TYPE;
589 }
590 //---------------------------------------------------------------------------
591 template < class T >
593 {
594 if ( pObj->getObjID().isNULL()
595 ||
596 ( ! pObj->getObjID().isNULL()
597 &&
598 ( T::getStaticGloClassID() == pObj->getObjID().getClassID()
599 ||
600 T::isStaticSubClassID( pObj->getObjID().getClassID() )
601 )
602 )
603 )
604 {
605 return SUPER::set( pObj->getObjID() );
606 }
607 return ERR_WRONG_TYPE;
608 }
609 //---------------------------------------------------------------------------
610 template < class T >
612 {
613 return this->set( & rObj );
614 }
615 //---------------------------------------------------------------------------
616 template < class T >
617 int TOndemand< T >::get( T *& prObj )
618 {
619 int t_iErr = 0;
620 BasePersistent * t_pGetObj = nullptr;
621
622 t_iErr = SUPER::getBasePersistent( t_pGetObj );
623 if ( ! t_iErr )
624 {
625 prObj = dynamic_cast<T*>( t_pGetObj );
626 if ( ! prObj )
627 {
628 t_pGetObj->forget();
629 t_iErr = ERR_WRONG_TYPE;
630 }
631 }
632 else
633 {
634 prObj = nullptr;
635 }
636 return t_iErr;
637 }
638 //---------------------------------------------------------------------------
639 template < class T >
640 int TOndemand< T >::get( std::shared_ptr<T> & rRetVal )
641 {
642 T * t_pPersObject = nullptr;
643 int t_iErr = this->get( t_pPersObject );
644
645 if ( t_pPersObject )
646 {
647 rRetVal.reset( t_pPersObject, Forgetter<T>() );
648 }
649 else
650 {
651 rRetVal.reset();
652 }
653 return t_iErr;
654 }
655 //---------------------------------------------------------------------------
656 template < class T >
658 {
659 if ( this != & rT )
660 {
661 SUPER::operator=( rT );
662 }
663 return *this;
664 }
665 //---------------------------------------------------------------------------
666 template < class T >
667 template < class T2 >
669 {
670 /*
671 An error is generated here if the type being assigned is incompatible.
672 Check if the compiler output provides more information, such as the incorrect
673 call to the assignment operator.
674 */
675 typedef char TypeCheck[IsBaseClassOf<T, T2>::value ? 1 : -1]; // <- Error if not derived
676 if ( (void*) this != & rT )
677 {
678 SUPER::operator=( rT );
679 }
680 return *this;
681 }
682 //---------------------------------------------------------------------------
683 template < class T >
684 bool TOndemand< T >::operator== ( const TOndemand & rT ) const
685 {
686 return SUPER::operator==( rT );
687 }
688 //---------------------------------------------------------------------------
689 template < class T >
690 bool TOndemand< T >::operator!= ( const TOndemand & rT ) const
691 {
692 return SUPER::operator!=( rT );
693 }
694 //---------------------------------------------------------------------------
695 template < class T >
696 template <class T2>
698 {
699 /*
700 An error is generated here if the type to be compared is incompatible.
701 Check if the compiler output provides more information, such as the incorrect
702 call to the comparison operator.
703 */
704 typedef char TypeCheck[IsBaseClassOf<T, T2>::value ? 1 : -1]; // <- Error if not derived
705 return SUPER::operator==( rT );
706 }
707 //---------------------------------------------------------------------------
708 template < class T >
709 template <class T2>
711 {
712 /*
713 An error is generated here if the type to be compared is incompatible.
714 Check if the compiler output provides more information, such as the incorrect
715 call to the comparison operator.
716 */
717 typedef char TypeCheck[IsBaseClassOf<T, T2>::value ? 1 : -1]; // <- Error if not derived
718 return SUPER::operator!=( rT );
719 }
720 //---------------------------------------------------------------------------
721 #if defined(__GNUC__) && ! defined(__clang__)
722 // Warnung: variable 't_bWorked' set but not used [-Wunused-local-typedefs]
723 #pragma GCC diagnostic pop
724 #endif
725 //---------------------------------------------------------------------------
726 #undef SUPER
727 //---------------------------------------------------------------------------
728} // namespace glo
729#endif
Header für BasePersistent
Header für ObjID
Header für Reference
#define SUPER
Referenz (als Attribut) eines persistenten Objekte auf ein anderes persistentes Objekt in der Datenba...
Definition GloTOndemand.h:206
Abstrakte Basisklasse für Persistent und die generische GenericPersistent.
Definition GloBasePersistent.h:124
virtual unsigned int forget()
virtual ObjID getObjID() const
std::string m_strDebugInfo
Definition GloCallBack.h:111
Prüft, ob Vorlagenparameter Klassen sind und ob die Klasse des zweiten Vorlagenparameter vom Typ der ...
Definition GloTOndemand.h:71
static No Test(...)
char Yes
Definition GloTOndemand.h:83
static const bool value
Definition GloTOndemand.h:155
static Yes Test(Base *)
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
Definition GloTOndemand.h:209
int set(const T *rObj)
Übernimmt die Objekt-ID des übergeben Objekt als Referenz.
Definition GloTOndemand.h:535
bool operator==(const TOndemand &rT) const
Vergleichsoperator.
Definition GloTOndemand.h:684
virtual ~TOndemand()
Definition GloTOndemand.h:530
TOndemand()
Definition GloTOndemand.h:480
bool operator!=(const TOndemand &rT) const
Vergleichsoperator.
Definition GloTOndemand.h:690
static unsigned long getStaticGloClassID()
Definition GloTOndemand.h:289
TOndemand< T > & operator=(const TOndemand &rT)
Zuweisungsoperator.
Definition GloTOndemand.h:657
int get(T *&prObj)
Definition GloTOndemand.h:617
Definition GloBasePersistent.h:60
Definition GloTOndemand.h:131
static const bool value
Definition GloTOndemand.h:138
char Yes[1]
Definition GloTOndemand.h:132
char No[2]
Definition GloTOndemand.h:133
static Yes & Test(void(U::*)())
Definition GloTOndemand.h:94
char dummy[2]
Definition GloTOndemand.h:94