📄 psyntreestackapi.c
字号:
/***********************************************************************
Copyright (c) 2002 RADVISION Ltd.
************************************************************************
NOTICE:
This document contains information that is confidential and proprietary
to RADVISION Ltd.. No part of this document may be reproduced in any
form whatsoever without written prior approval by RADVISION Ltd..
RADVISION Ltd. reserve the right to revise this publication and make
changes without obligation to notify any person of such revisions or
changes.
***********************************************************************/
/*
psyntreeStackApi
Internal Syntax-Tree functions used as API for other stack modules.
*/
#include "rvstdio.h"
#include "intutils.h"
#include "psyntreeDef.h"
#include "psyntreeDb.h"
#include "psyntreeStackApi.h"
#ifdef __cplusplus
extern "C" {
#endif
/************************************************************************
*
* Private constants
*
************************************************************************/
/************************************************************************
* ones array
* This array holds the amount of '1' bits in binary representation for
* the index value from 0 to 31. We use this to check how many optional
* fields a type is holding. By checking the number of bits we actually
* know the position of the optional field inside the type, since it
* may vary.
* The comments indicate which kind of field we're looking for in each
* of the values.
************************************************************************/
unsigned char ones[32] =
{
/* Bits: to, from, fromID, toID, tag */
0, /* 00000 */ /* Should never happen */
/* tag existance */
1, /* 00001 */
/* ofId for arrays */
1, /* 00010 */
2, /* 00011 */
/* fromId for strings */
1, /* 00100 */
2, /* 00101 */
2, /* 00110 */
3, /* 00111 */
/* from constraint */
1, /* 01000 */
2, /* 01001 */
2, /* 01010 */
3, /* 01011 */
2, /* 01100 */
3, /* 01101 */
3, /* 01110 */
4, /* 01111 */
/* to constraint */
1, /* 10000 */
2, /* 10001 */
2, /* 10010 */
3, /* 10011 */
2, /* 10100 */
3, /* 10101 */
3, /* 10110 */
4, /* 10111 */
2, /* 11000 */
3, /* 11001 */
3, /* 11010 */
4, /* 11011 */
3, /* 11100 */
4, /* 11101 */
4, /* 11110 */
5 /* 11111 */
};
/************************************************************************
* stATSearchStruct
* Association table search struct.
* Used on calls to RvH323BinarySearch().
* hSyn - Syntax tree used
* compareFunc - Comparison function to call
* context - Context used
************************************************************************/
typedef struct
{
HPST hSyn;
pstCompareFunction compareFunc;
void* context;
} stATSearchStruct;
/************************************************************************
*
* Private functions
*
************************************************************************/
/************************************************************************
* pstSearch
* purpose: Prepare parameters when trying to search an object inside
* an association table (=object set).
* input : eKey - Key element we're searching for
* elem - Element we're currently comparing with
* output : none
* return : Negative if the key is lower than elem in dictionary comparison
* 0 if the key and the element are equal
* Positive if the key is higher than elem in dictionary comparison
************************************************************************/
int pstSearch(IN const void *eKey, IN const void *elem)
{
stATSearchStruct* key = (stATSearchStruct *)eKey;
stAssociationTableValue* atNode = (stAssociationTableValue *)elem;
return key->compareFunc(key->hSyn, (int)m_ATValueValue(atNode), key->context);
}
/************************************************************************
*
* Public functions
*
************************************************************************/
/************************************************************************
* pstGetChildExt
* purpose: Return extended information about one of the child nodes of
* a parent node
* input : hSyn - Syntax tree used
* nodeId - Parent's node ID
* childIndex - Index of the child (1-based)
* output : child - Extended child node information
* return : Pointer to use with pstGetBrotherExt() on success,
* NULL on errror
************************************************************************/
RvUint32* pstGetChildExt(
IN HPST hSyn,
IN RvPstNodeId nodeId,
IN int childIndex,
OUT pstChildExt* child)
{
stChildExt* fieldInfo;
RvUint32* err;
if (child)
child->index = RV_ERROR_UNKNOWN; /* assume the worst */
/* Get the information */
err = stGetChildByIndex(hSyn, (int)nodeId, childIndex, &fieldInfo);
if (err != NULL)
{
/* Convert it to something readable */
child->index = childIndex;
child->nodeId = (RvPstNodeId)m_structId(fieldInfo);
child->fieldId = m_fieldId(fieldInfo);
child->isOptional = m_isOptional(fieldInfo);
child->isDefault = m_isDefault(fieldInfo);
child->isExtended = m_isExtended(fieldInfo);
child->speciality = (pstFieldSpeciality)m_isSpecial(fieldInfo);
child->enumerationValue = m_enumerationValue(fieldInfo);
}
return err;
}
/************************************************************************
* pstGetBrotherExt
* purpose: Return extended information about the right brother of a
* node. responsibility not to call for a non-existant brother
* is on the caller (use num of children)
* input : hSyn - Syntax tree used
* childIndex - index of the child (not really needed)
* nodePtr - Node pointer to which we want the brother
* output : brother - Extended child node information
* return : Pointer to use (responsibly) in subsequesnt calls to
* stGetBrother()
************************************************************************/
RvUint32* pstGetBrotherExt(
IN HPST hSyn,
IN int childIndex,
IN RvUint32* nodePtr,
OUT pstChildExt* brother)
{
stChildExt* fieldInfo;
RvUint32* err;
if (brother)
brother->index = RV_ERROR_UNKNOWN; /* assume the worst */
/* Get the information */
err = stGetBrother(hSyn, nodePtr, &fieldInfo);
if (err != NULL)
{
/* Convert it to something readable */
brother->index = childIndex;
brother->nodeId = (RvPstNodeId)m_structId(fieldInfo);
brother->fieldId = m_fieldId(fieldInfo);
brother->isOptional = m_isOptional(fieldInfo);
brother->isDefault = m_isDefault(fieldInfo);
brother->isExtended = m_isExtended(fieldInfo);
brother->speciality = (pstFieldSpeciality)m_isSpecial(fieldInfo);
brother->enumerationValue = m_enumerationValue(fieldInfo);
}
return err;
}
int
pstGetField(
IN HPST hSyn,
IN RvPstNodeId nodeId, /* node id of parent */
IN int fieldId, /* index of child */
OUT pstChild* child
)
{
int index=pstGetFieldIndex(hSyn,nodeId,fieldId);
if (child)
pstGetChild(hSyn, nodeId, index, child);
return index;
}
int
pstGetFieldExt(
IN HPST hSyn,
IN RvPstNodeId nodeId, /* node id of parent */
IN int fieldId, /* index of child */
OUT pstChildExt* child)
{
int index;
if (nodeId<0)
return RV_ERROR_UNKNOWN;
index=pstGetFieldIndex(hSyn,nodeId,fieldId);
if (child)
pstGetChildExt(hSyn, nodeId, index, child);
return index;
}
int
pstChildIsExtended(
IN HPST hSyn,
IN int nodeId, /* node id of parent */
IN int childIndex /* index of child */
)
{
stChildExt *fieldInfo;
RvUint32 * err;
err = stGetChildByIndex(hSyn, nodeId, childIndex, &fieldInfo);
if (err == NULL) return RV_ERROR_UNKNOWN;
return m_isExtended(fieldInfo);
}
int
pstGetFirstExtendedChild(
IN HPST hSyn,
IN int nodeId)
{
stNodeExt* node;
node = stGetNodeDataByNodeId(hSyn, nodeId);
if (node == NULL) return RV_ERROR_UNKNOWN;
return m_childsBeforeExt(node) + 1;
}
int
pstGetNumberOfOptionalBeforeExtension(
IN HPST hSyn,
IN int nodeId)
{
stNodeExt* node;
node = stGetNodeDataByNodeId(hSyn, nodeId);
if (node == NULL) return RV_ERROR_UNKNOWN;
return m_numOptBeforeExt(node);
}
RvInt32 /* Field index or negative value on failure */
pstGetFieldIndex(
/* convert field name to internal id */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -