PolyReference.h
Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 //  (c) 2008 by Basler Vision Technologies
00003 //  Section: Vision Components
00004 //  Project: GenApi
00005 //  Author:  Fritz Dierks
00006 //  $Header$
00007 //
00008 //  License: This file is published under the license of the EMVA GenICam  Standard Group.
00009 //  A text file describing the legal terms is included in  your installation as 'GenICam_license.pdf'.
00010 //  If for some reason you are missing  this file please contact the EMVA or visit the website
00011 //  (http://www.genicam.org) for a full copy.
00012 //
00013 //  THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
00014 //  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00015 //  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00016 //  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD  GROUP
00017 //  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,  SPECIAL,
00018 //  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT  LIMITED TO,
00019 //  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  DATA, OR PROFITS;
00020 //  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  THEORY OF LIABILITY,
00021 //  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)
00022 //  ARISING IN ANY WAY OUT OF THE USE  OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00023 //  POSSIBILITY OF SUCH DAMAGE.
00024 //-----------------------------------------------------------------------------
00031 #ifndef GENAPI_POLYREFERENCE_H
00032 #define GENAPI_POLYREFERENCE_H
00033 
00034 #include "Base/GCBase.h"
00035 #include "GenApi/IBase.h"
00036 #include "GenApi/IValue.h"
00037 #include "GenApi/IFloat.h"
00038 #include "GenApi/IInteger.h"
00039 #include "GenApi/IEnumeration.h"
00040 #include "GenApi/IBoolean.h"
00041 #include "GenApi/IString.h"
00042 #include "GenApi/impl/INodePrivate.h"
00043 #include "GenApi/Pointer.h"
00044 #include <limits>
00045 
00046 #undef min
00047 #undef max
00048 
00049 namespace GENAPI_NAMESPACE
00050 {
00051     inline int64_t round(double x)
00052     {
00053         return (int64_t)(x > 0.0 ? x + 0.5 : x - 0.5);
00054     }
00055 
00056     //inline int64_t abs(int64_t x)
00057     //{
00058     //    return (x >= 0 ? x : -x);
00059     //}
00060 
00061     inline double abs(double  x)
00062     {
00063         return (x >= 0.0 ? x : -x);
00064     }
00065 
00068     class CIntegerPolyRef
00069     {
00070     public:
00072         CIntegerPolyRef() :
00073           m_Type(typeUninitialized)
00074           {
00075               m_Value.Value = 0;
00076           }
00077 
00079           void operator=(int64_t Value)
00080           {
00081               m_Type = typeValue;
00082               m_Value.Value = Value;
00083           }
00084 
00086                   void operator=(INode *pValue)
00087                   {
00088                           operator=( dynamic_cast<IBase*>(pValue) );
00089                   }
00090 
00092           void operator=(IBase *pValue)
00093           {
00094               m_Value.pInteger = dynamic_cast<IInteger*>(pValue);
00095               if( m_Value.pInteger )
00096                   m_Type = typeIInteger;
00097               else
00098               {
00099                   m_Value.pEnumeration = dynamic_cast<IEnumeration*>(pValue);
00100                   if( m_Value.pEnumeration )
00101                       m_Type = typeIEnumeration;
00102                   else
00103                   {
00104                       m_Value.pBoolean = dynamic_cast<IBoolean*>(pValue);
00105                       if( m_Value.pBoolean )
00106                           m_Type = typeIBoolean;
00107                       else
00108                       {
00109                           m_Value.pFloat = dynamic_cast<IFloat*>(pValue);
00110                           if( m_Value.pFloat )
00111                               m_Type = typeIFloat;
00112                           else
00113                               throw RUNTIME_EXCEPTION("CIntegerPolyRef::operator(IBase*) : pointer is neither IInteger*, nor IEnumeration*, nor IBoolean*, nor IFloat*");
00114                       }
00115                   }
00116               }
00117           }
00118 
00120           inline bool IsPointer() const
00121           {
00122               return (m_Type != typeValue) && (m_Type != typeUninitialized);
00123           }
00124 
00126                   inline bool IsValue() const
00127                   {
00128                           return (m_Type == typeValue) && (m_Type != typeUninitialized);
00129                   }
00130 
00132           inline bool IsInitialized() const
00133           {
00134               return (m_Type != typeUninitialized);
00135           }
00136 
00138           inline INodePrivate *GetPointer() const
00139           {
00140               switch(m_Type)
00141               {
00142               case typeIInteger:
00143                   return dynamic_cast<INodePrivate*>(m_Value.pInteger);
00144               case typeIEnumeration:
00145                   return dynamic_cast<INodePrivate*>(m_Value.pEnumeration);
00146               case typeIBoolean:
00147                   return dynamic_cast<INodePrivate*>(m_Value.pBoolean);
00148               case typeIFloat:
00149                   return dynamic_cast<INodePrivate*>(m_Value.pFloat);
00150               case typeValue:
00151                   return NULL;
00152 #           pragma BullseyeCoverage off
00153               case typeUninitialized:
00154               default:
00155                   return NULL;
00156 #           pragma BullseyeCoverage on
00157               }
00158           }
00159 
00161           inline operator INode*(void) const
00162           {
00163               return GetPointer();
00164           }
00165 
00167           inline int64_t GetValue( bool Verify = false, bool IgnoreCache = false) const
00168           {
00169               switch(m_Type)
00170               {
00171               case typeValue:
00172                   return m_Value.Value;
00173               case typeIInteger:
00174                   return m_Value.pInteger->GetValue(Verify, IgnoreCache);
00175               case typeIEnumeration:
00176                   {
00177                       CEnumEntryPtr ptrEnumEntry = m_Value.pEnumeration->GetCurrentEntry(Verify, IgnoreCache);
00178                       return round(ptrEnumEntry->GetNumericValue());
00179                   }
00180               case typeIBoolean:
00181                   return m_Value.pBoolean->GetValue(Verify, IgnoreCache) ? 1 : 0;
00182               case typeIFloat:
00183                   {
00184                         double Result = m_Value.pFloat->GetValue(Verify, IgnoreCache);
00185                         if (Result > (int64_t)GC_INT64_MAX || Result < (int64_t)GC_INT64_MIN)
00186                             throw RUNTIME_EXCEPTION("CIntegerPolyRef::GetValue(): Float value %f out of integer range", Result);
00187                         return round(Result);
00188                   }
00189               case typeUninitialized:
00190 #pragma BullseyeCoverage off
00191               default:
00192                   throw RUNTIME_EXCEPTION("CIntegerPolyRef::GetValue(): uninitialized pointer");
00193 #pragma BullseyeCoverage on
00194               }
00195           }
00196 
00198           inline void SetValue( int64_t Value, bool Verify = true)
00199           {
00200               switch(m_Type)
00201               {
00202               case typeValue:
00203                   m_Value.Value = Value;
00204                   break;
00205               case typeIInteger:
00206                   m_Value.pInteger->SetValue(Value, Verify);
00207                   break;
00208               case typeIEnumeration:
00209                   {
00210                       CEnumEntryPtr ptrOldEnumEntry;
00211                       double OldDistance = -1;
00212                       NodeList_t EnumEntries;
00213                       m_Value.pEnumeration->GetEntries(EnumEntries);
00214                       for( NodeList_t::iterator it=EnumEntries.begin(); it!=EnumEntries.end(); ++it )
00215                       {
00216                           if( IsAvailable(*it) )
00217                           {
00218                               if( !ptrOldEnumEntry.IsValid() )
00219                               {
00220                                   ptrOldEnumEntry = *it;
00221                                   OldDistance = abs( (double)Value - ptrOldEnumEntry->GetNumericValue() );
00222                               }
00223                               else
00224                               {
00225                                   CEnumEntryPtr ptrNewEnumEntry( *it );
00226                                   double  NewDistance = abs( (double)Value - ptrNewEnumEntry->GetNumericValue() ) ;
00227                                   if(NewDistance < OldDistance)
00228                                   {
00229                                       ptrOldEnumEntry = *it;
00230                                       OldDistance = NewDistance;
00231                                   }
00232                               }
00233                           }
00234                       }
00235                       if( ptrOldEnumEntry.IsValid() )
00236                           m_Value.pEnumeration->SetIntValue(ptrOldEnumEntry->GetValue(), Verify);
00237                       else
00238                           throw ACCESS_EXCEPTION("Failed to write enumeration. None of the entries is writable");
00239                   }
00240                   break;
00241               case typeIBoolean:
00242                   return m_Value.pBoolean->SetValue( (Value != 0), Verify);
00243                   break;
00244               case typeIFloat:
00245                   return m_Value.pFloat->SetValue( (double)Value, Verify);
00246                   break;
00247               case typeUninitialized:
00248 #pragma BullseyeCoverage off
00249               default:
00250                   throw RUNTIME_EXCEPTION("CIntegerPolyRef::SetValue(): uninitialized pointer");
00251 #pragma BullseyeCoverage on
00252               }
00253           }
00254 
00256           inline int64_t GetMin() const
00257           {
00258               switch(m_Type)
00259               {
00260               case typeIInteger:
00261                   return m_Value.pInteger->GetMin();
00262               case typeIEnumeration:
00263               case typeIBoolean:
00264               case typeValue:
00265                   return GC_INT64_MIN;
00266               case typeIFloat:
00267                   {
00268                       double Min = m_Value.pFloat->GetMin();
00269                       if(Min > (int64_t)GC_INT64_MAX || Min < (int64_t)GC_INT64_MIN)
00270                           throw RUNTIME_EXCEPTION("CIntegerPolyRef::GetMin(): Float value %f out of integer range", Min);
00271                       return round(Min);
00272                   }
00273               case typeUninitialized:
00274 #pragma BullseyeCoverage off
00275               default:
00276                   throw RUNTIME_EXCEPTION("CIntegerPolyRef::GetMin(): uninitialized pointer");
00277 #pragma BullseyeCoverage on
00278               }
00279           }
00280 
00282           inline int64_t GetMax() const
00283           {
00284               switch(m_Type)
00285               {
00286               case typeIInteger:
00287                   return m_Value.pInteger->GetMax();
00288               case typeIEnumeration:
00289               case typeIBoolean:
00290               case typeValue:
00291                   return GC_INT64_MAX;
00292               case typeIFloat:
00293                   {
00294                       double Max = m_Value.pFloat->GetMax();
00295                       if(Max > (int64_t)GC_INT64_MAX || Max < (int64_t)GC_INT64_MIN)
00296                           throw RUNTIME_EXCEPTION("CIntegerPolyRef::GetMin(): Float value %f out of integer range", Max);
00297                       return round(Max);
00298                   }
00299               case typeUninitialized:
00300 #pragma BullseyeCoverage off
00301               default:
00302                   throw RUNTIME_EXCEPTION("CIntegerPolyRef::GetMax(): uninitialized pointer");
00303 #pragma BullseyeCoverage on
00304               }
00305           }
00306 
00308           inline int64_t GetInc() const
00309           {
00310               switch(m_Type)
00311               {
00312               case typeIInteger:
00313                   return m_Value.pInteger->GetInc();
00314               case typeIEnumeration:
00315               case typeIBoolean:
00316               case typeValue:
00317                   return 1;
00318               case typeIFloat:
00319                   if( m_Value.pFloat->HasInc() )
00320                       return round(m_Value.pFloat->GetInc());
00321                   else
00322                       return 1;
00323               case typeUninitialized:
00324 #pragma BullseyeCoverage off
00325               default:
00326                   throw RUNTIME_EXCEPTION("CIntegerPolyRef::GetInc(): uninitialized pointer");
00327 #pragma BullseyeCoverage on
00328               }
00329           }
00330 
00332           inline ERepresentation GetRepresentation() const
00333           {
00334               switch(m_Type)
00335               {
00336               case typeIInteger:
00337                   return m_Value.pInteger->GetRepresentation();
00338               case typeValue:
00339               case typeIEnumeration:
00340               case typeIBoolean:
00341               case typeIFloat:
00342                   return PureNumber;
00343               case typeUninitialized:
00344 #pragma BullseyeCoverage off
00345               default:
00346                   throw RUNTIME_EXCEPTION("CIntegerPolyRef::GetRepresentation(): uninitialized pointer");
00347 #pragma BullseyeCoverage on
00348               }
00349           }
00350 
00352           GENICAM_NAMESPACE::gcstring GetUnit() const
00353           {
00354               switch(m_Type)
00355               {
00356               case typeIInteger:
00357                   return m_Value.pInteger->GetUnit();
00358               case typeIFloat:
00359                   return m_Value.pFloat->GetUnit();
00360               case typeValue:
00361               case typeIEnumeration:
00362               case typeIBoolean:
00363                   return GENICAM_NAMESPACE::gcstring();
00364               case typeUninitialized:
00365 #pragma BullseyeCoverage off
00366               default:
00367                   throw RUNTIME_EXCEPTION("CIntegerPolyRef::GetUnit(): uninitialized pointer");
00368               }
00369 #pragma BullseyeCoverage on
00370           }
00371 
00373           bool IsValueCacheValid() const
00374           {
00375               switch(m_Type)
00376               {
00377               case typeIInteger:
00378                   return m_Value.pInteger->IsValueCacheValid();
00379               case typeIEnumeration:
00380                   return m_Value.pEnumeration->IsValueCacheValid();
00381               case typeIBoolean:
00382                   return m_Value.pBoolean->IsValueCacheValid();
00383               case typeIFloat:
00384                   return m_Value.pFloat->IsValueCacheValid();
00385               case typeValue:
00386                   return true;
00387               case typeUninitialized:
00388 #             pragma BullseyeCoverage off
00389               default:
00390                   throw RUNTIME_EXCEPTION("CIntegerPolyRef::IsValueCacheValid(): uninitialized pointer");
00391               }
00392 #             pragma BullseyeCoverage on
00393           }
00394 
00395         inline ECachingMode GetCachingMode() const
00396         {
00397             switch(m_Type)
00398             {
00399             case typeIInteger:
00400                 return m_Value.pInteger->GetNode()->GetCachingMode();
00401             case typeIEnumeration:
00402                 return m_Value.pEnumeration->GetNode()->GetCachingMode();
00403             case typeIBoolean:
00404                 return m_Value.pBoolean->GetNode()->GetCachingMode();
00405             case typeIFloat:
00406                 return m_Value.pFloat->GetNode()->GetCachingMode();
00407             case typeValue:
00408                 return WriteThrough;
00409             case typeUninitialized:
00410             #pragma BullseyeCoverage off
00411             default:
00412                 throw RUNTIME_EXCEPTION("CIntegerPolyRef::GetCachingMode(): uninitialized pointer");
00413             #pragma BullseyeCoverage on
00414             }
00415         }
00416 
00417     protected:
00419         typedef enum _EType
00420         {
00421             typeUninitialized,
00422             typeValue,
00423             typeIInteger,
00424             typeIEnumeration,
00425             typeIBoolean,
00426             typeIFloat
00427         } EType;
00428 
00430         EType m_Type;
00431 
00433         union
00434         {
00435             int64_t Value;                
00436             IInteger *pInteger;           
00437             IEnumeration *pEnumeration;   
00438             IBoolean *pBoolean;           
00439             IFloat *pFloat;               
00440         } m_Value;
00441     };
00442 
00443 
00446     class CBooleanPolyRef
00447     {
00448     public:
00450         CBooleanPolyRef() :
00451           m_Type(typeUninitialized)
00452           {
00453               m_Value.Value = false;
00454           }
00455 
00456           #pragma BullseyeCoverage off
00457           GENICAM_NAMESPACE::gcstring GetName()  const
00458           {
00459               CNodePtr ptrNode = GetPointer();
00460               if( ptrNode.IsValid() )
00461                   return ptrNode->GetName();
00462               else
00463                   return GENICAM_NAMESPACE::gcstring(".Value.");
00464           }
00465           #pragma BullseyeCoverage on
00466 
00468           void operator=(bool Value)
00469           {
00470               m_Type = typeValue;
00471               m_Value.Value = Value;
00472           }
00473 
00475           void operator=(IBase *pValue)
00476           {
00477               m_Value.pInteger = dynamic_cast<IInteger*>(pValue);
00478               if( m_Value.pInteger )
00479                   m_Type = typeIInteger;
00480               else
00481               {
00482                   m_Value.pEnumeration = dynamic_cast<IEnumeration*>(pValue);
00483                   if( m_Value.pEnumeration )
00484                       m_Type = typeIEnumeration;
00485                   else
00486                   {
00487                       m_Value.pBoolean = dynamic_cast<IBoolean*>(pValue);
00488                       if( m_Value.pBoolean )
00489                           m_Type = typeIBoolean;
00490                       else
00491                           throw RUNTIME_EXCEPTION("CIntegerPolyRef::operator(IBase*) : pointer is neither IInteger*, IEnumeration*, nor IBoolean*");
00492                   }
00493               }
00494           }
00495 
00497           inline bool IsPointer() const
00498           {
00499               return (m_Type != typeValue) && (m_Type != typeUninitialized);
00500           }
00501 
00503           inline bool IsInitialized() const
00504           {
00505               return (m_Type != typeUninitialized);
00506           }
00507 
00509           inline INodePrivate *GetPointer() const
00510           {
00511               switch(m_Type)
00512               {
00513               case typeIInteger:
00514                   return dynamic_cast<INodePrivate*>(m_Value.pInteger);
00515               case typeIEnumeration:
00516                   return dynamic_cast<INodePrivate*>(m_Value.pEnumeration);
00517               case typeIBoolean:
00518                   return dynamic_cast<INodePrivate*>(m_Value.pBoolean);
00519               case typeValue:
00520                   return NULL;
00521 #pragma BullseyeCoverage off
00522               case typeUninitialized:
00523               default:
00524                   assert(false);
00525                   return NULL;
00526 #pragma BullseyeCoverage on
00527               }
00528           }
00529 
00531           inline operator INode*(void) const
00532           {
00533               return GetPointer();
00534           }
00535 
00537           inline bool GetValue( bool Verify = false, bool IgnoreCache = false) const
00538           {
00539               switch(m_Type)
00540               {
00541               case typeValue:
00542                   return m_Value.Value;
00543               case typeIInteger:
00544                   return m_Value.pInteger->GetValue(Verify, IgnoreCache) != 0;
00545               case typeIEnumeration:
00546                   return m_Value.pEnumeration->GetIntValue(Verify, IgnoreCache) != 0;
00547               case typeIBoolean:
00548                   return m_Value.pBoolean->GetValue(Verify, IgnoreCache);
00549               case typeUninitialized:
00550 #pragma BullseyeCoverage off
00551               default:
00552                   throw RUNTIME_EXCEPTION("CIntegerPolyRef::GetValue(): uninitialized pointer");
00553 #pragma BullseyeCoverage on
00554               }
00555           }
00556 
00558           inline void SetValue( bool Value, bool Verify = true)
00559           {
00560               switch(m_Type)
00561               {
00562               case typeValue:
00563                   m_Value.Value = Value;
00564                   break;
00565               case typeIInteger:
00566                   m_Value.pInteger->SetValue(Value ? 1 : 0, Verify);
00567                   break;
00568               case typeIEnumeration:
00569                   return m_Value.pEnumeration->SetIntValue(Value, Verify);
00570                   break;
00571               case typeIBoolean:
00572                   return m_Value.pBoolean->SetValue(Value, Verify);
00573                   break;
00574               case typeUninitialized:
00575 #pragma BullseyeCoverage off
00576               default:
00577                   throw RUNTIME_EXCEPTION("CIntegerPolyRef::SetValue(): uninitialized pointer");
00578 #pragma BullseyeCoverage on
00579               }
00580           }
00581 
00582           inline ECachingMode GetCachingMode() const
00583           {
00584               switch(m_Type)
00585               {
00586               case typeIInteger:
00587                   return m_Value.pInteger->GetNode()->GetCachingMode();
00588               case typeIEnumeration:
00589                   return m_Value.pEnumeration->GetNode()->GetCachingMode();
00590               case typeIBoolean:
00591                   return m_Value.pBoolean->GetNode()->GetCachingMode();
00592               case typeValue:
00593                   return WriteThrough;
00594               case typeUninitialized:
00595               #pragma BullseyeCoverage off
00596               default:
00597                   throw RUNTIME_EXCEPTION("CBooleanPolyRef::GetCachingMode(): uninitialized pointer");
00598               #pragma BullseyeCoverage on
00599               }
00600           }
00601     protected:
00603         typedef enum _EType
00604         {
00605             typeUninitialized,
00606             typeValue,
00607             typeIInteger,
00608             typeIEnumeration,
00609             typeIBoolean
00610         } EType;
00611 
00613         EType m_Type;
00614 
00616         union
00617         {
00618             bool Value;                   
00619             IInteger *pInteger;           
00620             IEnumeration *pEnumeration;   
00621             IBoolean *pBoolean;           
00622         } m_Value;
00623 
00624     };
00625 
00628     class CFloatPolyRef
00629     {
00630     public:
00632         CFloatPolyRef() :
00633           m_Type(typeUninitialized)
00634           {
00635               m_Value.Value = 0.0;
00636           }
00637 
00639           void operator=(double Value)
00640           {
00641               m_Type = typeValue;
00642               m_Value.Value = Value;
00643           }
00644                   
00646                   void operator=(INode *pValue)
00647                   {
00648                           operator=( dynamic_cast<IBase*>(pValue) );
00649                   }
00650 
00652           void operator=(IBase *pValue)
00653           {
00654               m_Value.pFloat = dynamic_cast<IFloat*>(pValue);
00655               if( m_Value.pFloat)
00656                   m_Type = typeIFloat;
00657               else
00658               {
00659                   m_Value.pEnumeration = dynamic_cast<IEnumeration*>(pValue);
00660                   if( m_Value.pEnumeration )
00661                       m_Type = typeIEnumeration;
00662                   else
00663                   {
00664                       m_Value.pInteger= dynamic_cast<IInteger*>(pValue);
00665                       if( m_Value.pInteger)
00666                           m_Type = typeIInteger;
00667                       else
00668                           throw RUNTIME_EXCEPTION("CFloatPolyRef::operator(IBase*) : pointer is neither IFloat*, IInteger*, nor IEnumeration*");
00669                   }
00670               }
00671           }
00672 
00674                   inline bool IsValue() const
00675                   {
00676                           return (m_Type == typeValue) && (m_Type != typeUninitialized);
00677                   }
00678 
00680           inline bool IsPointer() const
00681           {
00682               return (m_Type != typeValue) && (m_Type != typeUninitialized);
00683           }
00684 
00686           inline bool IsInitialized() const
00687           {
00688               return (m_Type != typeUninitialized);
00689           }
00690 
00692           inline INodePrivate *GetPointer() const
00693           {
00694               switch(m_Type)
00695               {
00696               case typeIFloat:
00697                   return dynamic_cast<INodePrivate*>(m_Value.pFloat);
00698               case typeIInteger:
00699                   return dynamic_cast<INodePrivate*>(m_Value.pInteger);
00700               case typeIEnumeration:
00701                   return dynamic_cast<INodePrivate*>(m_Value.pEnumeration);
00702               case typeValue:
00703                   return NULL;
00704           #pragma BullseyeCoverage off
00705               case typeUninitialized:
00706               default:
00707                   assert(false);
00708                   return NULL;
00709           #pragma BullseyeCoverage on
00710               }
00711           }
00712 
00714           inline operator INode*(void) const
00715           {
00716               return GetPointer();
00717           }
00718 
00720           inline double GetValue( bool Verify = false, bool IgnoreCache = false) const
00721           {
00722               switch(m_Type)
00723               {
00724               case typeValue:
00725                   return m_Value.Value;
00726               case typeIFloat:
00727                   return m_Value.pFloat->GetValue(Verify, IgnoreCache);
00728               case typeIInteger:
00729                   return (double)m_Value.pInteger->GetValue(Verify, IgnoreCache);
00730               case typeIEnumeration:
00731                   {
00732                       CEnumEntryPtr ptrEnumEntry = m_Value.pEnumeration->GetCurrentEntry(Verify, IgnoreCache);
00733                       return ptrEnumEntry->GetNumericValue();
00734                   }
00735               case typeUninitialized:
00736               #pragma BullseyeCoverage off
00737               default:
00738                   throw RUNTIME_EXCEPTION("CFloatPolyRef::GetValue(): uninitialized pointer");
00739               #pragma BullseyeCoverage on
00740               }
00741           }
00742 
00744           inline void SetValue( double Value, bool Verify = true)
00745           {
00746               switch(m_Type)
00747               {
00748               case typeValue:
00749                   m_Value.Value = Value;
00750                   break;
00751               case typeIFloat:
00752                   m_Value.pFloat->SetValue(Value, Verify);
00753                   break;
00754               case typeIInteger:
00755                   {
00756                       if( Value > (int64_t)GC_INT64_MAX || Value < (int64_t)GC_INT64_MIN  )
00757                           throw OUT_OF_RANGE_EXCEPTION("CIntegerPolyRef::SetValue(): double value outside int64 range");
00758 
00759                       int64_t TargetValue = round(Value);
00760                       int64_t Residuum = (TargetValue - m_Value.pInteger->GetMin()) % m_Value.pInteger->GetInc();
00761                       TargetValue -= Residuum;
00762                       if( 2 * Residuum > m_Value.pInteger->GetInc())
00763                           TargetValue += m_Value.pInteger->GetInc();
00764                       m_Value.pInteger->SetValue(TargetValue, Verify);
00765                   }
00766                   break;
00767               case typeIEnumeration:
00768                   {
00769                       CEnumEntryPtr ptrOldEnumEntry;
00770                       double OldDistance = -1;
00771                       NodeList_t EnumEntries;
00772                       m_Value.pEnumeration->GetEntries(EnumEntries);
00773                       for( NodeList_t::iterator it=EnumEntries.begin(); it!=EnumEntries.end(); ++it )
00774                       {
00775                           if( IsAvailable(*it) )
00776                           {
00777                               if( !ptrOldEnumEntry.IsValid() )
00778                               {
00779                                   ptrOldEnumEntry = *it;
00780                                   OldDistance = abs( Value - ptrOldEnumEntry->GetNumericValue() );
00781                               }
00782                               else
00783                               {
00784                                   CEnumEntryPtr ptrNewEnumEntry( *it );
00785                                   double  NewDistance = abs( Value - ptrNewEnumEntry->GetNumericValue() ) ;
00786                                   if(NewDistance < OldDistance)
00787                                   {
00788                                       ptrOldEnumEntry = *it;
00789                                       OldDistance = NewDistance;
00790                                   }
00791                               }
00792                           }
00793                       }
00794                       if( ptrOldEnumEntry.IsValid() )
00795                           m_Value.pEnumeration->SetIntValue(ptrOldEnumEntry->GetValue(), Verify);
00796                       else
00797                           throw ACCESS_EXCEPTION("Failed to write enumeration. None of the entries is writable");
00798                   }
00799                   break;
00800               case typeUninitialized:
00801               #pragma BullseyeCoverage off
00802               default:
00803                   throw RUNTIME_EXCEPTION("CIntegerPolyRef::SetValue(): uninitialized pointer");
00804               #pragma BullseyeCoverage on
00805               }
00806           }
00807 
00809           inline double GetMin() const
00810           {
00811               switch(m_Type)
00812               {
00813               case typeIFloat:
00814                   return m_Value.pFloat->GetMin();
00815               case typeIInteger:
00816                   return (double) m_Value.pInteger->GetMin();
00817               case typeIEnumeration:
00818               case typeValue:
00819                   return -std::numeric_limits<double>::max();
00820               case typeUninitialized:
00821               #pragma BullseyeCoverage off
00822               default:
00823                   throw RUNTIME_EXCEPTION("CFloatPolyRef::GetMin(): uninitialized pointer");
00824               #pragma BullseyeCoverage on
00825               }
00826           }
00827 
00829           inline double GetMax() const
00830           {
00831               switch(m_Type)
00832               {
00833               case typeIFloat:
00834                   return m_Value.pFloat->GetMax();
00835               case typeIInteger:
00836                   return (double) m_Value.pInteger->GetMax();
00837               case typeIEnumeration:
00838               case typeValue:
00839                   return std::numeric_limits<double>::max();
00840               case typeUninitialized:
00841               #pragma BullseyeCoverage off
00842               default:
00843                   throw RUNTIME_EXCEPTION("CFloatPolyRef::GetMax(): uninitialized pointer");
00844               #pragma BullseyeCoverage on
00845               }
00846           }
00847 
00849           inline bool HasInc()
00850           {
00851               switch(m_Type)
00852               {
00853               case typeIFloat:
00854                   return m_Value.pFloat->HasInc();
00855               case typeIInteger:
00856                   return true;
00857               case typeIEnumeration:
00858               case typeValue:
00859               case typeUninitialized:
00860               #pragma BullseyeCoverage off
00861               default:
00862                   return false;
00863               #pragma BullseyeCoverage on
00864               }
00865           }
00866 
00868           virtual double GetInc()
00869           {
00870               switch(m_Type)
00871               {
00872               case typeIFloat:
00873                   return m_Value.pFloat->GetInc();
00874               case typeIInteger:
00875                   return (double) m_Value.pInteger->GetInc();
00876               case typeIEnumeration:
00877               case typeValue:
00878               case typeUninitialized:
00879               #pragma BullseyeCoverage off
00880               default:
00881                   throw RUNTIME_EXCEPTION("CFloatPolyRef::GetInc(): uninitialized pointer");
00882               #pragma BullseyeCoverage on
00883               }
00884           }
00885 
00887           #pragma BullseyeCoverage off
00888           inline double GetInc() const
00889           {
00890               switch(m_Type)
00891               {
00892               case typeIInteger:
00893                   return (double) m_Value.pInteger->GetInc();
00894               case typeIFloat:
00895               case typeIEnumeration:
00896               case typeValue:
00897                   return 1.0;
00898               case typeUninitialized:
00899               #pragma BullseyeCoverage off
00900               default:
00901                   throw RUNTIME_EXCEPTION("CFloatPolyRef::GetMax(): uninitialized pointer");
00902               #pragma BullseyeCoverage on
00903               }
00904           }
00905           #pragma BullseyeCoverage on
00906 
00908           inline ERepresentation GetRepresentation() const
00909           {
00910               switch(m_Type)
00911               {
00912               case typeIFloat:
00913                   return m_Value.pFloat->GetRepresentation();
00914               case typeIInteger:
00915                   return m_Value.pInteger->GetRepresentation();
00916               case typeValue:
00917               case typeIEnumeration:
00918                   return PureNumber;
00919               case typeUninitialized:
00920               #pragma BullseyeCoverage off
00921               default:
00922                   throw RUNTIME_EXCEPTION("CFloatPolyRef::GetRepresentation(): uninitialized pointer");
00923               #pragma BullseyeCoverage on
00924               }
00925           }
00926 
00928           GENICAM_NAMESPACE::gcstring GetUnit() const
00929           {
00930               switch(m_Type)
00931               {
00932               case typeIFloat:
00933                   return m_Value.pFloat->GetUnit();
00934               case typeIInteger:
00935                   return m_Value.pInteger->GetUnit();
00936               case typeValue:
00937               case typeIEnumeration:
00938                   return GENICAM_NAMESPACE::gcstring();
00939               case typeUninitialized:
00940               #pragma BullseyeCoverage off
00941               default:
00942                   throw RUNTIME_EXCEPTION("CFloatPolyRef::GetUnit(): uninitialized pointer");
00943               #pragma BullseyeCoverage on
00944               }
00945           }
00946 
00947 // this is currently not needed but may be in future so we keep the code
00948 #if 0
00949 
00950           bool IsValueCacheValid() const
00951           {
00952               switch(m_Type)
00953               {
00954               case typeIFloat:
00955                   return m_Value.pFloat->IsValueCacheValid();
00956               case typeIInteger:
00957                   return m_Value.pInteger->IsValueCacheValid();
00958               case typeIEnumeration:
00959                   return m_Value.pEnumeration->IsValueCacheValid();
00960               case typeValue:
00961                   return true;
00962               case typeUninitialized:
00963               #pragma BullseyeCoverage off
00964               default:
00965                   throw RUNTIME_EXCEPTION("CFloatPolyRef::IsValueCacheValid(): uninitialized pointer");
00966               #pragma BullseyeCoverage on
00967               }
00968           }
00969 #endif
00970 
00972           EDisplayNotation GetDisplayNotation() const
00973           {
00974               switch(m_Type)
00975               {
00976               case typeIFloat:
00977                   return m_Value.pFloat->GetDisplayNotation();
00978               case typeIInteger:
00979               case typeIEnumeration:
00980               case typeValue:
00981                   return fnAutomatic;
00982               case typeUninitialized:
00983               #pragma BullseyeCoverage off
00984               default:
00985                   throw RUNTIME_EXCEPTION("CFloatPolyRef::GetDisplayNotation(): uninitialized pointer");
00986               #pragma BullseyeCoverage on
00987               }
00988           }
00989 
00991           int64_t GetDisplayPrecision() const
00992           {
00993               switch(m_Type)
00994               {
00995               case typeIFloat:
00996                   return m_Value.pFloat->GetDisplayPrecision();
00997               case typeIInteger:
00998               case typeIEnumeration:
00999               case typeValue:
01000                   return -1;
01001               case typeUninitialized:
01002               #pragma BullseyeCoverage off
01003               default:
01004                   throw RUNTIME_EXCEPTION("CFloatPolyRef::GetDisplayPrecision(): uninitialized pointer");
01005               #pragma BullseyeCoverage on
01006               }
01007           }
01008 
01010           typedef enum _EType
01011           {
01012               typeUninitialized,
01013               typeValue,
01014               typeIFloat,
01015               typeIInteger,
01016               typeIEnumeration
01017           } EType;
01018 
01019           inline ECachingMode GetCachingMode() const
01020           {
01021               switch(m_Type)
01022               {
01023               case typeIInteger:
01024                   return m_Value.pInteger->GetNode()->GetCachingMode();
01025               case typeIEnumeration:
01026                   return m_Value.pEnumeration->GetNode()->GetCachingMode();
01027               case typeIFloat:
01028                   return m_Value.pFloat->GetNode()->GetCachingMode();
01029               case typeValue:
01030                   return WriteThrough;
01031               case typeUninitialized:
01032               #pragma BullseyeCoverage off
01033               default:
01034                   throw RUNTIME_EXCEPTION("CFloatPolyRef::GetCachingMode(): uninitialized pointer");
01035               #pragma BullseyeCoverage on
01036               }
01037           }
01038     protected:
01040         EType m_Type;
01041 
01043         union
01044         {
01045             double Value;                   
01046             IFloat *pFloat;                 
01047             IInteger *pInteger;             
01048             IEnumeration *pEnumeration;     
01049         } m_Value;
01050 
01051     };
01052 
01053 
01056     class CStringPolyRef
01057     {
01058     public:
01060         CStringPolyRef() :
01061           m_Type(typeUninitialized)
01062           {
01063               m_Value.pString = NULL;
01064           }
01065 
01066           #pragma BullseyeCoverage off
01067           GENICAM_NAMESPACE::gcstring GetName() const
01068           {
01069               CNodePtr ptrNode = GetPointer();
01070               if( ptrNode.IsValid() )
01071                   return ptrNode->GetName();
01072               else
01073                   return GENICAM_NAMESPACE::gcstring(".Value.");
01074           }
01075           #pragma BullseyeCoverage on
01076 
01078           void operator=(const GENICAM_NAMESPACE::gcstring &Value)
01079           {
01080               m_Type = typeValue;
01081               m_Value.Value = Value;
01082           }
01083 
01085           void operator=(IBase *pValue)
01086           {
01087               m_Value.pString = dynamic_cast<IString*>(pValue);
01088               if( m_Value.pString )
01089                   m_Type = typeIString;
01090               else
01091                   throw RUNTIME_EXCEPTION("CStringPolyRef::operator(IBase*) : pointer is not IString*");
01092           }
01093 
01095                   inline bool IsValue() const
01096                   {
01097                           return (m_Type == typeValue);
01098                   }
01099 
01100 
01102           inline bool IsPointer() const
01103           {
01104               return (m_Type != typeValue) && (m_Type != typeUninitialized);
01105           }
01106 
01108           inline bool IsInitialized() const
01109           {
01110               return (m_Type != typeUninitialized);
01111           }
01112 
01114           inline INodePrivate *GetPointer() const
01115           {
01116               switch(m_Type)
01117               {
01118               case typeIString:
01119                   return dynamic_cast<INodePrivate*>(m_Value.pString);
01120               case typeValue:
01121                   return NULL;
01122 #           pragma BullseyeCoverage off
01123               case typeUninitialized:
01124               default:
01125                   assert(false);
01126                   return NULL;
01127 #           pragma BullseyeCoverage on
01128               }
01129           }
01130 
01132           inline operator INode*(void) const
01133           {
01134               return GetPointer();
01135           }
01136 
01138           inline GENICAM_NAMESPACE::gcstring GetValue( bool Verify = false, bool IgnoreCache = false) const
01139           {
01140               switch(m_Type)
01141               {
01142               case typeValue:
01143                   return m_Value.Value;
01144               case typeIString:
01145                   return m_Value.pString->GetValue(Verify, IgnoreCache);
01146               case typeUninitialized:
01147 #pragma BullseyeCoverage off
01148               default:
01149                   throw RUNTIME_EXCEPTION("CStringPolyRef::GetValue(): uninitialized pointer");
01150 #pragma BullseyeCoverage on
01151               }
01152           }
01153 
01155           inline void SetValue( const GENICAM_NAMESPACE::gcstring& Value, bool Verify = true)
01156           {
01157               switch(m_Type)
01158               {
01159               case typeValue:
01160                   m_Value.Value = Value;
01161                   break;
01162               case typeIString:
01163                   m_Value.pString->SetValue(Value, Verify);
01164                   break;
01165               case typeUninitialized:
01166 #pragma BullseyeCoverage off
01167               default:
01168                   throw RUNTIME_EXCEPTION("CStringPolyRef::SetValue(): uninitialized pointer");
01169 #pragma BullseyeCoverage on
01170               }
01171           }
01172 
01174           inline int64_t GetMaxLength( )
01175           {
01176               switch(m_Type)
01177               {
01178               case typeValue:
01179                   return m_Value.Value.max_size();
01180                   break;
01181               case typeIString:
01182                   return m_Value.pString->GetMaxLength();
01183                   break;
01184               case typeUninitialized:
01185 #pragma BullseyeCoverage off
01186               default:
01187                   throw RUNTIME_EXCEPTION("CStringPolyRef::GetMaxLength(): uninitialized pointer");
01188 #pragma BullseyeCoverage on
01189               }
01190           }
01191 
01192 
01194           bool IsValueCacheValid() const
01195           {
01196               switch(m_Type)
01197               {
01198               case typeIString:
01199                   return m_Value.pString->IsValueCacheValid();
01200               case typeValue:
01201                   return true;
01202               case typeUninitialized:
01203 #             pragma BullseyeCoverage off
01204               default:
01205                   throw RUNTIME_EXCEPTION("CStringPolyRef::IsValueCacheValid(): uninitialized pointer");
01206               }
01207 #             pragma BullseyeCoverage on
01208           }
01209 
01210 
01211     protected:
01213         typedef enum _EType
01214         {
01215             typeUninitialized,
01216             typeValue,
01217             typeIString
01218         } EType;
01219 
01221         EType m_Type;
01222 
01224         struct
01225         {
01226             GENICAM_NAMESPACE::gcstring Value;      
01227             IString *pString;             
01228         } m_Value;
01229     };
01230 
01231         class CIntegerOffsetPolyRef
01232         {
01233         public:
01234                 CIntegerOffsetPolyRef() 
01235                 {
01236                 };
01237                 CIntegerOffsetPolyRef( INode *_pIndex, int64_t _Offset ) 
01238                 {
01239                         pIndex = _pIndex;
01240                         Offset = _Offset;
01241                 };
01242 
01243                 CIntegerOffsetPolyRef( INode *_pIndex, INode *_pOffset ) 
01244                 {
01245                         pIndex = _pIndex;
01246                         Offset = _pOffset;
01247                 };
01248 
01249                 CIntegerOffsetPolyRef( const CIntegerOffsetPolyRef &Copy ) 
01250                 {
01251                         pIndex = Copy.pIndex;
01252                         Offset = Copy.Offset;
01253                 };
01254 
01255                 CIntegerPolyRef pIndex;
01256                 CIntegerPolyRef Offset;
01257         }; 
01258 
01259 
01260 }
01261 
01262 #endif // ifndef GENAPI_POLYREFERENCE_H


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:06