⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 valuenostl.cpp

📁 OSB-PIK-OpenVXI-3.0.0源代码 “中国XML论坛 - 专业的XML技术讨论区--XML在语音技术中的应用”
💻 CPP
📖 第 1 页 / 共 3 页
字号:
     m->size++;   }    return VXIvalue_RESULT_SUCCESS; }   /**  * Get a named property from an Map  *  * The property value is returned for read-only access and is  * invalidated if the Map is modified. The client must clone it if  * they wish to perform modifications or wish to retain the value even  * afer modifying this Map.  *  * @param   m     Map to access  * @param   key   NULL terminated property name  * @return        On success the value of the property for read-only   *                access (invalidated if the Map is modified), NULL  *                if the property was never set or was deleted   */ VXIVALUE_API const VXIValue *VXIMapGetProperty(const VXIMap    *m,  					       const VXIchar   *key) {   if (( m == NULL ) || ( m->GetType( ) != VALUE_MAP ) ||        ( key == NULL ) || ( key[0] == 0 ))     return NULL;    // Search for that element   int rc;   VXIElement *cur = m->head;   while (( cur ) && ( (rc = cur->GetKey( ).Compare (key)) < 0 ))     cur = cur->GetNext( );      // Return it if found   if (( cur ) && ( rc == 0 ))     return cur->GetValue( );    return NULL; }   /**  * Delete a named property from an Map  *  * This does a VXIValueDestroy( ) on the value for the named property  * (thus recursively deleting held values within it if it is an Map  * or Vector). However, for Ptr properties the user is responsible for  * freeing the held memory if appropriate.  *  * @param   m     Map to access  * @param   key   NULL terminated property name  * @return        VXIvalue_RESULT_SUCCESS on success   */ VXIVALUE_API VXIvalueResult VXIMapDeleteProperty(VXIMap         *m,  						 const VXIchar  *key) {   if (( m == NULL ) || ( m->GetType( ) != VALUE_MAP ) ||        ( key == NULL ) || ( key[0] == 0 ))     return VXIvalue_RESULT_INVALID_ARGUMENT;    // Search for that element   int rc;   VXIElement *cur = m->head, *prev = NULL;   while (( cur ) && ( (rc = cur->GetKey( ).Compare (key)) < 0 )) {     prev = cur;     cur = cur->GetNext( );   }      // Delete it if found   if (( ! cur ) || ( rc != 0 ))     return VXIvalue_RESULT_FAILURE;    if ( prev )     prev->SetNext (cur->GetNext( ));   else     m->head = cur->GetNext( );      cur->DestroyValue( );   delete cur;   m->size--;    return VXIvalue_RESULT_SUCCESS; }   /**  * Return the number of properties for an Map  *  * Note: this only returns the number of properties that are direct  * children of the Map, it does not include the number of properties  * held in Maps and Vectors stored within this map.  *  * @param   m   Map to access  * @return      Number of properties stored in the Map  */ VXIVALUE_API VXIunsigned VXIMapNumProperties(const VXIMap *m) {   if (( m == NULL ) || ( m->GetType( ) != VALUE_MAP ))     return 0;    return m->size; }   /**  * Get the first property of an Map and an iterator  *  * Note: this is used to traverse all the properties within an map,  * there is no guarantee on what order the properties will be  * returned. The iterator must be eventually freed with  * VXIMapIteratorDestroy( ), and is invalidated if the Map is  * modified in any way.  *  * @param   m      Map to access  * @param   key    Set to point at the property name for read-only   *                 access (must not be modified)                   * @param   value  Set to point at the property value for read-only   *                 access (must not be modified)  * @return         Pointer to an iterator that may be used to get  *                 additional properties via VXIMapGetNextProperty( ),  *                 or NULL on failure (typically no properties in the map)  */ VXIVALUE_API  VXIMapIterator *VXIMapGetFirstProperty(const VXIMap     *m, 				       const VXIchar   **key, 				       const VXIValue  **value) {   if (( m == NULL ) || ( m->GetType( ) != VALUE_MAP ) ||       ( m->size == 0 ) || ( key == NULL ) || ( value == NULL ))     return NULL;    // Allocate an iterator map   VXIMapIterator *it = new VXIMapIterator (m);   if ( it == NULL )     return NULL;      // Get the first property   it->GetKeyValue (key, value);   return it; }   /**  * Get the next property of an Map based on an iterator  *  * Note: this is used to traverse all the properties within an map,  * there is no gaurantee on what order the properties will be  * returned.  *  * @param   it     Iterator used to access the map as obtained  *                 from VXIMapGetFirstProperty( ), this operation  *                 will advance the iterator to the next property on  *                 success  * @param   key    Set to point at the property name for read-only   *                 access (must not be modified, invalidated if the  *                 Map is modified)                   * @param   value  Set to point at the property value for read-only   *                 access (must not be modified, invalidated if the  *                 Map is modified)  * @return         VXIvalue_RESULT_SUCCESS on success (property name   *                 and value returned, iterator advanced),   *                 VXIvalue_RESULT_FAILURE if there are no more properties  *                 to read, or a VXIvalueResult error code for severe errors  */ VXIVALUE_API VXIvalueResult VXIMapGetNextProperty(VXIMapIterator  *it, 						  const VXIchar  **key, 						  const VXIValue **value) {   if (( it == NULL ) || ( key == NULL ) || ( value == NULL ))     return VXIvalue_RESULT_INVALID_ARGUMENT;    (*it)++;   return it->GetKeyValue (key, value); }   /**  * Destroy an iterator  *  * @param   it     Iterator to destroy as obtained from   *                 VXIMapGetFirstProperty( )  */ VXIVALUE_API void VXIMapIteratorDestroy(VXIMapIterator **it) {   if (( it ) && ( *it )) {     delete *it;     *it = NULL;   } }   /**  * Create an empty Vector  *  * @return   New vector on success, NULL otherwise  */ VXIVALUE_API VXIVector *VXIVectorCreate(void) {   return new VXIVector; }   /**  * Vector destructor  *  * Note: this recursively destroys all the values contained within the  * Vector, including all the values of Vectors stored within this  * vector. However, for Ptr values the user is responsible for  * freeing the held memory if appropriate.  *  * @param   v   Vector to destroy   */ VXIVALUE_API void VXIVectorDestroy(VXIVector **v) {   if (( v ) && ( *v ) && ( (*v)->GetType( ) == VALUE_VECTOR )) {     delete *v;     *v = NULL;   } }   /**  * Vector clone  *  * Recursively copies all values contained within the vector,  * including all the values of Vectors and Maps stored within this  * vector.  *  * Note: functionally redundant with VXIValueClone( ), but provided to  * reduce the need for C casts for this common operation  *  * @param    v   Vector to clone  * @return Clone of the Vector on success, NULL otherwise */ VXIVALUE_API VXIVector *VXIVectorClone(const VXIVector *v) {   if (( v == NULL ) || ( v->GetType( ) != VALUE_VECTOR ))     return NULL;    VXIVector *vec = new VXIVector (*v);   if (( vec ) && ( vec->badState )) {     delete vec;     vec = NULL;   }    return vec; }   /**  * Adds an element to the end of the Vector  *  * The value can be a Vector so frames can be implemented.  *  * @param   v    Vector to access  * @param   val  Value to append to the vector, ownership is passed  *               to the Vector (a simple pointer copy is done), so on  *               success the user must not delete, modify, or otherwise  *               use this. Also be careful to not add a Vector as a  *               element of itself (directly or indirectly), otherwise  *               infinite loops may occur on access or deletion.  * @return       VXIvalue_RESULT_SUCCESS on success  */ VXIVALUE_API VXIvalueResult VXIVectorAddElement(VXIVector      *v,  						VXIValue       *val) {   if (( v == NULL ) || ( v->GetType( ) != VALUE_VECTOR ) ||        ( val == NULL ))     return VXIvalue_RESULT_INVALID_ARGUMENT;    return v->Add (val); }   /**  * Set an indexed vector element  *  * Overwrites the specified element with the new value. The existing  * value is first destroyed using VXIValueDestroy( ) (thus recursively  * deleting held values within it if it is an Map or Vector), then  * does the set operation with the new value.  *  * The value can be a Vector so frames can be implemented.  *  * @param   v     Vector to access  * @param   n     Element index to set, it is an error to pass a  *                index that is greater then the number of values  *                currently in the vector  * @param   val   Value to set the element to, ownership is passed  *                to the Vector (a simple pointer copy is done), so on  *                success the user must not delete, modify, or otherwise  *                use this. Also be careful to not add a Vector as a  *                element of itself (directly or indirectly), otherwise  *                infinite loops may occur on access or deletion.  * @return        VXIvalue_RESULT_SUCCESS on success  */ VXIVALUE_API VXIvalueResult VXIVectorSetElement(VXIVector      *v,  						VXIunsigned     n,  						VXIValue       *val) {   if (( v == NULL ) || ( v->GetType( ) != VALUE_VECTOR ) ||        ( val == NULL ) || ( n >= v->size ))     return VXIvalue_RESULT_INVALID_ARGUMENT;    // Delete the old one, we allocated the memory so we call an explicit   // destructor that doesn't free the memory   v->data[n].DestroyValue( );   v->data[n].~VXIElement( );    // Create the new one   VXIElement *element = new (&v->data[n]) VXIElement (NULL, val);   return VXIvalue_RESULT_SUCCESS; }   /**  * Get an indexed vector element  *  * The element value is returned for read-only access and is  * invalidated if the Vector is modified. The client must clone it if  * they wish to perform modifications or wish to retain the value even  * after modifying this Vector.  *  * @param   v     Vector to access  * @param   n     Element index to set, it is an error to pass a  *                index that is greater or equal to then the number of values  *                currently in the vector (i.e. range is 0 to length-1)  * @return        On success the value of the property for read-only   *                access (invalidated if the Vector is modified), NULL  *                on error   */ VXIVALUE_API const VXIValue *VXIVectorGetElement(const VXIVector *v,  						 VXIunsigned      n) {   if (( v == NULL ) || ( v->GetType( ) != VALUE_VECTOR ) ||       ( n >= v->size ))     return NULL;    return v->data[n].GetValue( ); }   /**  * Return number of elements in a Vector  *  * This computes only the length of the Vector, elements within  * Vectors and Maps within it are not counted.  *  * @param   v    Vector to access  * @return       Number of elements stored in the Vector  */ VXIVALUE_API VXIunsigned VXIVectorLength(const VXIVector *v) {   if (( v == NULL ) || ( v->GetType( ) != VALUE_VECTOR ))     return 0;    return v->size; }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -