Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

ltkcpp_element.cpp

00001 
00002 /*
00003  ***************************************************************************
00004  *  Copyright 2007,2008 Impinj, Inc.
00005  *
00006  *  Licensed under the Apache License, Version 2.0 (the "License");
00007  *  you may not use this file except in compliance with the License.
00008  *  You may obtain a copy of the License at
00009  *
00010  *      http://www.apache.org/licenses/LICENSE-2.0
00011  *
00012  *  Unless required by applicable law or agreed to in writing, software
00013  *  distributed under the License is distributed on an "AS IS" BASIS,
00014  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  *  See the License for the specific language governing permissions and
00016  *  limitations under the License.
00017  *
00018  ***************************************************************************
00019  */
00020 
00021 
00022 #include "ltkcpp_platform.h"
00023 #include "ltkcpp_base.h"
00024 
00025 
00026 namespace LLRP
00027 {
00028 
00029 CElement::CElement(void)
00030 {
00031     m_pType = NULL;
00032     m_pParent = NULL;
00033 }
00034 
00035 CElement::~CElement (void)
00036 {
00037 
00038     for (
00039         tListOfParameters::iterator elem = m_listAllSubParameters.begin();
00040         elem != m_listAllSubParameters.end();
00041         elem++)
00042     {
00043         delete *elem;
00044     }
00045 }
00046 
00047 
00048 void
00049 CElement::addSubParameterToAllList (
00050   CParameter *                  pParameter)
00051 {
00052     if(NULL != pParameter)
00053     {
00054         m_listAllSubParameters.push_back(pParameter);
00055     }
00056 }
00057 
00058 
00059 void
00060 CElement::removeSubParameterFromAllList (
00061   CParameter *                  pParameter)
00062 {
00063     if(NULL != pParameter)
00064     {
00065         m_listAllSubParameters.remove(pParameter);
00066     }
00067 }
00068 
00069 void
00070 CElement::clearSubParameterList (
00071   tListOfParameters *           pParameterList)
00072 {
00073     for(
00074         tListOfParameters::iterator elem = pParameterList->begin();
00075         elem != pParameterList->end();
00076         elem++)
00077     {
00078         removeSubParameterFromAllList(*elem);
00079         delete *elem;
00080     }
00081 
00082     pParameterList->clear();
00083 }
00084 
00085 int
00086 CElement::walk (
00087   int                           (*pFunc)(
00088                                   const CElement *  pElement,
00089                                   void *            pArg),
00090   void *                        pArg,
00091   int                           iDepth,
00092   int                           nMaxDepth) const
00093 {
00094     int                         rc;
00095 
00096     rc = (*pFunc)(this, pArg);
00097     if(0 != rc)
00098     {
00099         return rc;
00100     }
00101 
00102     if(iDepth >= nMaxDepth)
00103     {
00104         return 0;
00105     }
00106 
00107     for (
00108         tListOfParameters::const_iterator elem =
00109                                     m_listAllSubParameters.begin();
00110         elem != m_listAllSubParameters.end();
00111         elem++)
00112     {
00113         (*elem)->walk(pFunc, pArg, iDepth+1, nMaxDepth);
00114     }
00115 
00116     return 0;
00117 }
00118 
00119 llrp_bool_t
00120 CParameter::isAllowedIn (
00121   const CTypeDescriptor *       pEnclosingTypeDescriptor) const
00122 {
00123     return FALSE;
00124 }
00125 
00126 llrp_bool_t
00127 CParameter::isAllowedExtension (
00128   const CTypeDescriptor *       pEnclosingTypeDescriptor)
00129 {
00130     /*
00131      * If it is a generic Custom parameter allow it.
00132      */
00133     if(!m_pType->m_bIsMessage && NULL == m_pType->m_pVendorDescriptor &&
00134        1023u == m_pType->m_TypeNum)
00135     {
00136         return TRUE;
00137     }
00138 
00139     /*
00140      * If it is some kind of custom parameter allow it.
00141      */
00142     if(!m_pType->m_bIsMessage && NULL != m_pType->m_pVendorDescriptor)
00143     {
00144         return TRUE;
00145     }
00146 
00147     /*
00148      * At this point checking specifically if it is allowed
00149      * is perfunctory.
00150      */
00151     return isAllowedIn(pEnclosingTypeDescriptor);
00152 }
00153 
00154 
00155 }; /* namespace LLRP */

Generated on Wed Nov 26 12:27:44 2008 for LTKCPP-- LLRP Toolkit C Plus Plus Library by  doxygen 1.3.9.1