📄 psyntreestackapi.c
字号:
IN HPST hSyn,
IN RvPstNodeId nodeId,
IN int fieldId)
{
/* todo: make it faster by removing this function */
stNodeExt* elementBuffer;
if(hSyn==NULL || fieldId<0)
return RV_ERROR_UNKNOWN;
elementBuffer = (stNodeExt *)stGetNodeDataByNodeId(hSyn, (int)nodeId);
return stGetChildByNodeAndFieldName(hSyn, (int)nodeId, (int)m_numOfChilds(elementBuffer), fieldId, NULL);
}
/* convert field internal id to field name */
/* null terminated field name */
char* pstGetFieldNamePtr(
IN HPST hSyn,
IN RvInt32 fieldId
)
{
char* string = stGetNameByNameId(hSyn, fieldId, NULL);
return (string != NULL) ? string : (char *)"";
}
int /* type of node */
pstGetNodeRangeExt(
IN HPST hSyn,
IN int nodeId,
OUT int * from,
OUT int * to,
OUT RvBool* _fromAbsent,
OUT RvBool* _toAbsent)
{
stNodeExt* node;
node = (stNodeExt *)stGetNodeDataByNodeId(hSyn, nodeId);
if (node == NULL) return RV_ERROR_UNKNOWN;
if (from) *from = (int)m_from(node);
if (to) *to = (int)m_to(node);
if (_fromAbsent) *_fromAbsent = m_flags(node) & fromAbsent;
if (_toAbsent) *_toAbsent = m_flags(node) & toAbsent;
return 0;
}
int
pstChildIsSpecial(
IN HPST hSyn,
IN RvPstNodeId nodeId, /* node id of parent */
IN int childIndex /* index of child */
)
{
stChildExt *fieldInfo;
RvUint32 * err;
err = stGetChildByIndex(hSyn, (int)nodeId, childIndex, &fieldInfo);
if (err == NULL) return RV_ERROR_UNKNOWN;
return m_isSpecial(fieldInfo);
}
int pstGetTypeFromConstraint(
IN HPST hSyn,
IN RvPstNodeId specialTypeNodeId,
OUT pstTypeFromConstraint* specialType)
{
synStruct *syn = (synStruct *)hSyn;
RvUint8 * node;
if (!syn || !RV_PST_NODEID_IS_VALID(specialTypeNodeId) || !specialType) return RV_ERROR_UNKNOWN;
node = (RvUint8 *)stGetNodeDataByNodeId(hSyn, (int)specialTypeNodeId);
*specialType=*(pstTypeFromConstraint*)node;
return RV_TRUE;
}
int pstGetConstrainingField(
IN HPST hSyn,
IN RvPstNodeId specialTypeNodeId,
OUT pstConstrainingField* constrainingField)
{
synStruct *syn = (synStruct *)hSyn;
RvUint8 * node;
if (!syn || specialTypeNodeId < 0 || !constrainingField) return RV_ERROR_UNKNOWN;
node = (RvUint8 *)stGetNodeDataByNodeId(hSyn, (int)specialTypeNodeId + 3);
*constrainingField=*(pstConstrainingField*)node;
return RV_TRUE;
}
int pstGetFieldOfObjectReference(
IN HPST hSyn,
IN int objectNodeId,
IN int index,
OUT pstFieldOfObjectReference* fieldOfObject)
{
RvUint32* node;
RvUint32* err;
if (!hSyn || objectNodeId < 0 || !fieldOfObject) return RV_ERROR_UNKNOWN;
err = stGetChildByIndexUnbounded(hSyn, objectNodeId, index, &node);
if (err == NULL) return RV_ERROR_UNKNOWN;
*fieldOfObject=*(pstFieldOfObjectReference*)node;
return RV_TRUE;
}
int pstGetValueTreeStruct(
IN HPST hSyn,
IN int vtStructNodeId,
OUT pstValueTreeStruct* valueTreeStruct)
{
stValueTree* node;
if (!hSyn || vtStructNodeId < 0 || !valueTreeStruct) return RV_ERROR_UNKNOWN;
node = (stValueTree *)stGetNodeDataByNodeId(hSyn, vtStructNodeId);
valueTreeStruct->typeReference = m_valueTreeTypeReference(node);
valueTreeStruct->isString = (pstValueType)m_valueTreeIsString(node);
valueTreeStruct->value = m_valueTreeValue(node);
return 0;
}
int pstGetValueNodeStruct(
IN HPST hSyn,
IN int vtNodeNodeId,
OUT pstValueNodeStruct* valueTreeNode)
{
stValueNode* node;
if (!hSyn || vtNodeNodeId < 0 || !valueTreeNode) return RV_ERROR_UNKNOWN;
node = (stValueNode *)stGetNodeDataByNodeId(hSyn, vtNodeNodeId);
valueTreeNode->fieldName = m_valueNodeFieldName(node);
valueTreeNode->isString = (pstValueType)m_valueNodeIsString(node);
valueTreeNode->value = m_valueNodeValue(node);
return 0;
}
/************************************************************************
* pstFindObjectInAT
* purpose: Find the type of field from the association table that matches
* a given tree node. This is used when trying to encode/decode
* messages with object sets.
* input : hSyn - Syntax tree used
* atNodeId - Association table node ID in the syntax tree
* compareFunc - Comparison functio to use for nodes
* context - Context to use for comparison function
* output : none
* return : Node ID of the matching syntax value on success
* Negative value on failure
************************************************************************/
int pstFindObjectInAT(
IN HPST hSyn,
IN int atNodeId,
IN pstCompareFunction compareFunc,
IN void* context)
{
stAssociationTable* atNode;
int numObjects;
stAssociationTableValue* base;
stAssociationTableValue* node;
stATSearchStruct key;
/* Find out how many items are then in this association table */
atNode = (stAssociationTable *)stGetNodeDataByNodeId(hSyn, atNodeId);
numObjects = m_ATNumObjects(atNode);
/* Find the position of the first object in the association table */
base = (stAssociationTableValue *)m_ATTable(atNode);
/* Set the key to search for */
key.hSyn = hSyn;
key.compareFunc = compareFunc;
key.context = context;
/* Use binary search to look for the specific object id that matches */
node = (stAssociationTableValue *)
RvBsearch(&key, base, (RvSize_t)numObjects, m_ATObjectSize(atNode), pstSearch);
/* Make sure we've got something */
if (node == NULL) return RV_ERROR_UNKNOWN;
/* Found! get the syntax tree for this object */
return m_ATValueObject(node);
}
/* RV_TRUE if nodes have the same structure */
RvBool pstAreNodesCongruent(
IN HPST hSyn1,
IN RvPstNodeId synNodeId1,
IN HPST hSyn2,
IN RvPstNodeId synNodeId2)
{
synStruct *syn1 = (synStruct *)hSyn1;
synStruct *syn2 = (synStruct *)hSyn2;
stNodeExt *node1=NULL;
stNodeExt *node2=NULL;
pstChildExt child1;
pstChildExt child2;
RvUint32* iter1;
RvUint32* iter2;
RvInt i;
if (syn1==NULL || syn2==NULL ||
(syn1->syntax != syn2->syntax)) return RV_FALSE;
if (!synNodeId1) synNodeId1=pstGetRoot(hSyn1);
if (!synNodeId2) synNodeId2=pstGetRoot(hSyn2);
node1 = (stNodeExt *)stGetNodeDataByNodeId(hSyn1, (int)synNodeId1);
node2 = (stNodeExt *)stGetNodeDataByNodeId(hSyn2, (int)synNodeId2);
if (!node1 || !node2) return RV_FALSE;
if (m_isExtension(node1) != m_isExtension(node2)) return RV_FALSE;
if (m_numOfChilds(node1) != m_numOfChilds(node2)) return RV_FALSE;
if (m_from(node1) != m_from(node2)) return RV_FALSE;
if (m_to(node1) != m_to(node2)) return RV_FALSE;
if (m_ofId(node1) != m_ofId(node2)) return RV_FALSE;
if (m_fromId(node1) != m_fromId(node2)) return RV_FALSE;
/* check childs */
iter1 = pstGetChildExt(hSyn1, synNodeId1, 1, &child1);
iter2 = pstGetChildExt(hSyn2, synNodeId2, 1, &child2);
for (i=1; i<=(RvInt)m_numOfChilds(node1); i++)
{
/*if (child1->fieldId != child2->fieldId) return RV_FALSE;*/
if (child1.nodeId != child2.nodeId) return RV_FALSE;
if (child1.isExtended != child2.isExtended) return RV_FALSE;
if (child1.isOptional != child2.isOptional) return RV_FALSE;
iter1 = pstGetBrotherExt(hSyn1, i+1, iter1, &child1);
iter2 = pstGetBrotherExt(hSyn2, i+1, iter2, &child2);
}
return RV_TRUE;
}
RvBool pstIsNodeComplex(
IN HPST hSyn,
IN RvPstNodeId nodeId)
{
pstNodeType type = pstGetNodeType(hSyn, nodeId);
if (type <0) return RV_FALSE;
switch (type)
{
case pstChoice:
case pstSequence:
case pstSet:
case pstSequenceOf:
case pstSetOf: return RV_TRUE;
default: break;
}
return RV_FALSE;
}
char* /* actual length of the fromString or negative value on failure */
pstGetFROMStringPtr(
/* Get the character constraints of the syntax node */
IN HPST hSyn,
IN RvPstNodeId nodeId,
OUT int*actualLength)
{
stNodeExt* node=NULL;
char* string=NULL;
*actualLength = 0;
node = (stNodeExt *)stGetNodeDataByNodeId(hSyn, (int)nodeId);
if (node == NULL) return NULL;
if(m_fromId(node)<0) return NULL;
string = stGetNameByNameId(hSyn, m_fromId(node), actualLength);
return string;
}
RvPstNodeId pstGetRoot(IN HPST hSyn)
{
synStruct *syn = (synStruct *)hSyn;
if (!syn)
return RV_PST_ERROR_UNKNOWN;
return syn->rootNodeId;
}
#ifdef __cplusplus
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -