kfbxquery.h

Go to the documentation of this file.
00001 
00004 #ifndef FBXFILESDK_FBXCORE_KFBXQUERY_H
00005 #define FBXFILESDK_FBXCORE_KFBXQUERY_H
00006 
00007 /**************************************************************************************
00008 
00009  Copyright (C) 2001 - 2010 Autodesk, Inc. and/or its licensors.
00010  All Rights Reserved.
00011 
00012  The coded instructions, statements, computer programs, and/or related material 
00013  (collectively the "Data") in these files contain unpublished information 
00014  proprietary to Autodesk, Inc. and/or its licensors, which is protected by 
00015  Canada and United States of America federal copyright law and by international 
00016  treaties. 
00017  
00018  The Data may not be disclosed or distributed to third parties, in whole or in
00019  part, without the prior written consent of Autodesk, Inc. ("Autodesk").
00020 
00021  THE DATA IS PROVIDED "AS IS" AND WITHOUT WARRANTY.
00022  ALL WARRANTIES ARE EXPRESSLY EXCLUDED AND DISCLAIMED. AUTODESK MAKES NO
00023  WARRANTY OF ANY KIND WITH RESPECT TO THE DATA, EXPRESS, IMPLIED OR ARISING
00024  BY CUSTOM OR TRADE USAGE, AND DISCLAIMS ANY IMPLIED WARRANTIES OF TITLE, 
00025  NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR USE. 
00026  WITHOUT LIMITING THE FOREGOING, AUTODESK DOES NOT WARRANT THAT THE OPERATION
00027  OF THE DATA WILL BE UNINTERRUPTED OR ERROR FREE. 
00028  
00029  IN NO EVENT SHALL AUTODESK, ITS AFFILIATES, PARENT COMPANIES, LICENSORS
00030  OR SUPPLIERS ("AUTODESK GROUP") BE LIABLE FOR ANY LOSSES, DAMAGES OR EXPENSES
00031  OF ANY KIND (INCLUDING WITHOUT LIMITATION PUNITIVE OR MULTIPLE DAMAGES OR OTHER
00032  SPECIAL, DIRECT, INDIRECT, EXEMPLARY, INCIDENTAL, LOSS OF PROFITS, REVENUE
00033  OR DATA, COST OF COVER OR CONSEQUENTIAL LOSSES OR DAMAGES OF ANY KIND),
00034  HOWEVER CAUSED, AND REGARDLESS OF THE THEORY OF LIABILITY, WHETHER DERIVED
00035  FROM CONTRACT, TORT (INCLUDING, BUT NOT LIMITED TO, NEGLIGENCE), OR OTHERWISE,
00036  ARISING OUT OF OR RELATING TO THE DATA OR ITS USE OR ANY OTHER PERFORMANCE,
00037  WHETHER OR NOT AUTODESK HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSS
00038  OR DAMAGE. 
00039 
00040 **************************************************************************************/
00041 #include <fbxfilesdk/fbxfilesdk_def.h>
00042 
00043 #include <fbxfilesdk/components/kbaselib/klib/kmap.h>
00044 #include <fbxfilesdk/fbxcore/kfbxpropertydef.h>
00045 #include <fbxfilesdk/kfbxplugins/kfbxproperty.h>
00046 
00047 #include <fbxfilesdk/fbxfilesdk_nsbegin.h>
00048 
00049     /***********************************************
00050       KFbxQuery
00051     ************************************************/
00052 
00058     class KFBX_DLL KFbxQuery {
00059         // Overridable Test functions
00060         public:
00061             KFBXNEW_DECLARE_FRIEND
00063             virtual kFbxFilterId                    GetUniqueId() const     { return 0x1452e230; }
00064             
00069             virtual bool IsValid(KFbxProperty const &pProperty) const;
00070 
00076             virtual bool IsValid(KFbxProperty const &pProperty,kFbxConnectionType pType) const;
00077 
00082             virtual bool IsEqual(KFbxQuery *pOtherQuery)    const;
00083 
00084         public:
00086             void                                    Ref();
00088             void                                    Unref();
00089         protected:
00090             KFbxQuery();
00091             virtual ~KFbxQuery();
00092         private:
00093             class KFbxInternalFilter : public KFbxConnectionPointFilter{
00094                 public:
00095                     KFbxInternalFilter(KFbxQuery *pQuery);
00096                     ~KFbxInternalFilter();
00097 
00098                 // internal functions
00099                 public:
00100                     KFbxConnectionPointFilter*      Ref();
00101                     void                            Unref();
00102                     kFbxFilterId                    GetUniqueId() const { return mQuery->GetUniqueId(); }
00103                     bool                            IsValid             (KFbxConnectionPoint*   pConnect) const;
00104                     bool                            IsValidConnection   (KFbxConnectionPoint*   pConnect,kFbxConnectionType pType) const;
00105                     bool                            IsEqual             (KFbxConnectionPointFilter* pConnectFilter) const;
00106                 public:
00107                     KFbxQuery*      mQuery;
00108 
00109             };
00110 
00111             KFbxInternalFilter  mFilter;
00112             int                 mRefCount;
00113 
00114             friend class KFbxProperty;
00115             friend class KFbxInternalFilter;
00116         };
00117 
00118     /***********************************************
00119       KFbxQueryOperator (binary operators)
00120     ************************************************/
00121     enum eFbxQueryOperator { eFbxAnd,eFbxOr } ;
00122 
00128     class KFBX_DLL KFbxQueryOperator : public KFbxQuery {
00129         //
00130         public:
00131             KFBXNEW_DECLARE_FRIEND
00137             static KFbxQueryOperator* Create(KFbxQuery* pA,eFbxQueryOperator pOperator,KFbxQuery* pB);
00138 
00139         protected:
00140             KFbxQueryOperator(KFbxQuery* pA,eFbxQueryOperator pOperator,KFbxQuery* pB);
00141             virtual ~KFbxQueryOperator();
00142 
00143         // Test functions
00144         public:
00145 
00147             virtual kFbxFilterId    GetUniqueId() const{ return 0x945874; }
00148 
00153             virtual bool IsValid(KFbxProperty const &pProperty) const;
00154 
00160             virtual bool IsValid(KFbxProperty const &pProperty,kFbxConnectionType pType) const;
00161             
00166             virtual bool IsEqual(KFbxQuery *pOtherQuery)    const;
00167         private:
00168             KFbxQuery           *mA,*mB;
00169             eFbxQueryOperator   mOperator;
00170     };
00171 
00172     /***********************************************
00173       KFbxUnaryQueryOperator
00174     ************************************************/
00175     enum eFbxUnaryQueryOperator { eFbxNot };
00176 
00182     class KFBX_DLL KFbxUnaryQueryOperator : public KFbxQuery {
00183         //
00184         public:
00185             KFBXNEW_DECLARE_FRIEND
00190             static KFbxUnaryQueryOperator* Create(KFbxQuery* pA,eFbxUnaryQueryOperator pOperator);
00191 
00192         protected:
00193             KFbxUnaryQueryOperator(KFbxQuery* pA,eFbxUnaryQueryOperator pOperator);
00194             virtual ~KFbxUnaryQueryOperator();
00195 
00196         // Test functions
00197         public:
00198 
00200             virtual kFbxFilterId    GetUniqueId() const{ return 0x945874BB; }
00201 
00206             virtual bool IsValid(KFbxProperty const &pProperty) const;
00207 
00213             virtual bool IsValid(KFbxProperty const &pProperty,kFbxConnectionType pType) const;
00214 
00219             virtual bool IsEqual(KFbxQuery *pOtherQuery)    const;
00220         private:
00221             KFbxQuery                *mA;
00222             eFbxUnaryQueryOperator   mOperator;
00223     };
00224 
00225     /***********************************************
00226       KFbxQueryClassId -- match anywhere in the hierarchy of an object.
00227     ************************************************/
00233     class KFBX_DLL KFbxQueryClassId : public KFbxQuery {
00234         //
00235         public:
00236             KFBXNEW_DECLARE_FRIEND
00240             static KFbxQueryClassId* Create(kFbxClassId pClassId);
00241 
00242         protected:
00243             KFbxQueryClassId(kFbxClassId pClassId);
00244 
00245         // Test functions
00246         public:
00247 
00249             virtual kFbxFilterId    GetUniqueId() const{ return 0x14572785; }
00250 
00255             virtual bool IsValid(KFbxProperty const &pProperty) const;
00256 
00262             virtual bool IsValid(KFbxProperty const &pProperty,kFbxConnectionType pType) const;
00263 
00268             virtual bool IsEqual(KFbxQuery *pOtherQuery)    const;
00269         private:
00270             kFbxClassId             mClassId;
00271     };
00272 
00273     /***********************************************
00274       KFbxQueryIsA -- Exact match.
00275     ************************************************/
00276 
00282     class KFBX_DLL KFbxQueryIsA : public KFbxQuery {
00283         //
00284         public:
00285             KFBXNEW_DECLARE_FRIEND
00289             static KFbxQueryIsA* Create(kFbxClassId pClassId);
00290 
00291         protected:
00292 
00296             KFbxQueryIsA(kFbxClassId pClassId);
00297 
00298         // Test functions
00299         public:
00300 
00302             virtual kFbxFilterId    GetUniqueId() const{ return 0x1457278F; }
00303 
00308             virtual bool IsValid(KFbxProperty const &pProperty) const;
00309 
00315             virtual bool IsValid(KFbxProperty const &pProperty,kFbxConnectionType pType) const;
00316 
00321             virtual bool IsEqual(KFbxQuery *pOtherQuery)    const;
00322         private:
00323             kFbxClassId             mClassId;
00324     };
00325 
00326     /***********************************************
00327       KFbxQueryProperty
00328     ************************************************/
00329 
00334     class KFBX_DLL KFbxQueryProperty : public KFbxQuery {
00335         //
00336         public:
00337             KFBXNEW_DECLARE_FRIEND
00339             static KFbxQueryProperty* Create();
00340 
00341         protected:
00342             KFbxQueryProperty();
00343 
00344         // Test functions
00345         public:
00346 
00348             virtual kFbxFilterId    GetUniqueId() const{ return 0x9348203; }
00349 
00354             virtual bool IsValid(KFbxProperty const &pProperty) const;
00355 
00361             virtual bool IsValid(KFbxProperty const &pProperty,kFbxConnectionType pType) const;
00362 
00366             virtual bool IsEqual(KFbxQuery *pOtherQuery)    const;
00367         private:
00368     };
00369 
00370     /***********************************************
00371       KFbxQueryConnectionType
00372     ************************************************/
00373 
00379     class KFBX_DLL KFbxQueryConnectionType : public KFbxQuery {
00380         //
00381         public:
00382             KFBXNEW_DECLARE_FRIEND
00383 
00387             static KFbxQueryConnectionType* Create(kFbxConnectionType pConnectionType);
00388 
00389         protected:
00390             KFbxQueryConnectionType(kFbxConnectionType pConnectionType);
00391 
00392         // Test functions
00393         public:
00394 
00396             virtual kFbxFilterId    GetUniqueId() const{ return 0x14587275; }
00397 
00402             virtual bool IsValid(KFbxProperty const &pProperty) const;
00403 
00409             virtual bool IsValid(KFbxProperty const &pProperty,kFbxConnectionType pType) const;
00410 
00415             virtual bool IsEqual(KFbxQuery *pOtherQuery)    const;
00416         private:
00417             kFbxConnectionType              mConnectionType;
00418     };
00419 
00420     /***********************************************
00421       KFbxCriteria
00422     ************************************************/
00423 
00448     class KFBX_DLL KFbxCriteria {
00449         public:
00453             static KFbxCriteria ConnectionType(kFbxConnectionType pConnectionType)
00454             {
00455                 return KFbxCriteria(KFbxQueryConnectionType::Create(pConnectionType));
00456             }
00457 
00462             static KFbxCriteria ObjectType(kFbxClassId pClassId)
00463             {
00464                 return KFbxCriteria(*sCache.GetObjectType(pClassId));
00465             }
00466 
00470             static KFbxCriteria ObjectIsA(kFbxClassId pClassId)
00471             {
00472                 return KFbxCriteria(KFbxQueryIsA::Create(pClassId));
00473             }
00474 
00476             static KFbxCriteria Property()
00477             {
00478                 return KFbxCriteria(KFbxQueryProperty::Create());
00479             }
00480 
00482             inline KFbxCriteria()
00483                 : mQuery(0)
00484             {
00485             }
00486 
00490             inline KFbxCriteria(KFbxCriteria const &pCriteria)
00491                 : mQuery(pCriteria.mQuery)
00492             {
00493                 if( mQuery )
00494                     mQuery->Ref();
00495             }
00496 
00498             inline ~KFbxCriteria()
00499             {
00500                 if( mQuery )
00501                     mQuery->Unref();
00502             }
00503 
00507             inline KFbxCriteria &operator=(KFbxCriteria const &pCriteria)
00508             {
00509                 if( this != &pCriteria )
00510                 {
00511                     KFbxQuery* lQuery = mQuery;
00512                     mQuery = pCriteria.mQuery;
00513 
00514                     if( mQuery )
00515                         mQuery->Ref();
00516 
00517                     if( lQuery )
00518                         lQuery->Unref();
00519                 }
00520 
00521                 return *this;
00522             }
00526             inline KFbxCriteria operator && (KFbxCriteria const &pCriteria) const
00527             {
00528                 return KFbxCriteria(KFbxQueryOperator::Create(GetQuery(),eFbxAnd,pCriteria.GetQuery()));
00529             }
00530 
00534             inline KFbxCriteria operator || (KFbxCriteria const &pCriteria) const
00535             {
00536                 return KFbxCriteria(KFbxQueryOperator::Create(GetQuery(),eFbxOr,pCriteria.GetQuery()));
00537             }
00538 
00540             inline KFbxCriteria operator !() const
00541             {
00542                 return KFbxCriteria(KFbxUnaryQueryOperator::Create(GetQuery(), eFbxNot));
00543             }
00547             inline KFbxQuery*   GetQuery() const { return mQuery; }
00548 
00550             //
00551             //  WARNING!
00552             //
00553             //  Anything beyond these lines may not be documented accurately and is
00554             //  subject to change without notice.
00555             //
00557 
00558 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00559 
00560         private:
00561             KFbxQuery*  mQuery;
00562             inline KFbxCriteria(KFbxQuery* pQuery)
00563                 : mQuery(pQuery)
00564             {
00565             }
00566 
00567             // KFbxCriteriaCache caches KFbxCriteria instances for reuse
00568             KFBXNEW_DECLARE_FRIEND
00569             class KFbxCriteriaClassIdCompare
00570             {
00571             public:
00572                 inline int operator() (kFbxClassId const& pKeyA, kFbxClassId const& pKeyB) const
00573                 {
00574                     const KFbxClassIdInfo* lKeyA = pKeyA.GetClassIdInfo();
00575                     const KFbxClassIdInfo* lKeyB = pKeyB.GetClassIdInfo();
00576                     return (lKeyA > lKeyB) ? 1 : (lKeyA < lKeyB) ? -1 : 0;
00577                 }
00578             };
00579 
00580             class KFbxCriteriaCache
00581             {
00582             public:
00583                 KFbxCriteriaCache();
00584                 ~KFbxCriteriaCache();
00585 
00586                 inline KFbxCriteria* GetObjectType(kFbxClassId pClassId)
00587                 {
00588                     KFbxCriteriaCacheMap::RecordType* lRecord = mObjectTypeCriteria.Find(pClassId);
00589                     if (lRecord == NULL)
00590                     {
00591                         KFbxCriteria* lCriteria = FbxSdkNew<KFbxCriteria>(KFbxQueryClassId::Create(pClassId));
00592                         mObjectTypeCriteria.Insert(pClassId, lCriteria);
00593                         return lCriteria;
00594                     }
00595                     return lRecord->GetValue();
00596                 }
00597 
00598             private:
00599                 typedef KMap<kFbxClassId, KFbxCriteria*, KFbxCriteriaClassIdCompare> KFbxCriteriaCacheMap;
00600                 KFbxCriteriaCacheMap mObjectTypeCriteria;
00601             };
00602             static KFbxCriteriaCache sCache;
00603 #endif
00604     };
00605 
00606 #include <fbxfilesdk/fbxfilesdk_nsend.h>
00607 
00608 #endif // FBXFILESDK_FBXCORE_KFBXQUERY_H
00609