📄 asn_obj.cpp
字号:
{
wherep = (UcharArray *)0;
}
AsnTableObj::~AsnTableObj()
{
if (wherep)
{
delete wherep;
wherep = (UcharArray *)0;
}
}
int AsnTableObj::set_definees(int table_index) const
{
/**
Function: Clears and optionally sets the definees of *objp
Inputs: index into defined member (-1 means just clear)
Returns: 1 IF OK, ELSE -1
Procedure:
1. FOR each character in the defining string
IF the character is '-', go up one
ELSE IF it is greater than '0'
WHILE the character is greater than '0'
Go to the next item in the chain
Decrement the 'where' char
IF the chain is not long enough, report error
IF the next character in the string shows there's more to do
Go down one level
ELSE IF it is space OR NULL
Clear all the choices
Clear out all sub-items
IF setting a defined item
IF not at a defined item, return with error message
IF the next higher item is a CHOICE
Mark it as DEFINED
Clear all CHOSEN flags in its children
Mark the current child CHOSEN
Clear out all the sub-items
Find the currently defined item
Mark it CHOSEN
IF the defined item is a choice with min-max
Apply the min-max to all the item's choices
Reset to start from objp again in case there's a second
defined item
**/
uchar x;
int i, j;
AsnObj *defineep, *tobjp;
for (i = 0, defineep = (AsnObj *)this; 1; i++)
{
if ((x = (*this->wherep)[i]) == '-') defineep = defineep->_supra;
else if (x >= '0')
{
for (x -= '0' ; x-- && defineep; defineep = defineep->_next);
if (!defineep) return asn_obj_err(ASN_DEFINED_ERR);
if ((*this->wherep)[i + 1] >= '0') defineep = defineep->_sub;
}
else if (x == ' ' || !x)
{
for (tobjp = defineep->_sub; tobjp; tobjp = tobjp->_next)
{
tobjp->_flags &= ~(ASN_CHOSEN_FLAG);
if ((tobjp->_flags & ASN_FILLED_FLAG)) tobjp->_clear(-1);
}
defineep->_flags &= ~(ASN_FILLED_FLAG);
if (table_index >= 0)
{
if (!(defineep->_flags & ASN_DEFINED_FLAG))
return asn_obj_err(ASN_NO_DEF_ERR);
if (defineep->_supra->_type == ASN_CHOICE)
{
defineep->_supra->_flags |= ASN_DEFINED_FLAG;
for (tobjp = defineep; tobjp; tobjp = tobjp->_next)
{
tobjp->_flags &= ~(ASN_CHOSEN_FLAG);
if ((tobjp->_flags & ASN_FILLED_FLAG)) tobjp->_clear(-1);
}
defineep->_flags |= ASN_CHOSEN_FLAG;
}
for (tobjp = defineep->_sub, j = table_index; tobjp && j--;
tobjp = tobjp->_next);
if (!tobjp) return asn_obj_err(ASN_NO_DEF_ERR);
tobjp->_flags |= ASN_CHOSEN_FLAG;
if ((tobjp->_type == ASN_CHOICE) && tobjp->_max)
{
for (tobjp = tobjp->_sub; tobjp; tobjp = tobjp->_next)
{
tobjp->_min = tobjp->_supra->_min;
tobjp->_max = tobjp->_supra->_max;
}
}
}
if (!x) break;
defineep = (AsnObj *)this;
}
}
return 1;
}
AsnAny::AsnAny() { _tag = _type = ASN_ANY; }
AsnBoolean::AsnBoolean() { _tag = _type = ASN_BOOLEAN; _default = 0; }
AsnInteger::AsnInteger() { _tag = _type = ASN_INTEGER; }
AsnBitString::AsnBitString() { _tag = _type = ASN_BITSTRING; }
AsnOctetString::AsnOctetString() { _tag = _type = ASN_OCTETSTRING; }
AsnNull::AsnNull() { _tag = _type = ASN_NULL; }
AsnObjectIdentifier::AsnObjectIdentifier() { _tag = _type = ASN_OBJ_ID; }
AsnEnumerated::AsnEnumerated() { _tag = _type = ASN_ENUMERATED; }
AsnNumericString::AsnNumericString()
{
_tag = _type = ASN_NUMERIC_STRING;
_mask = ASN_NUMERIC_MASK;
}
AsnPrintableString::AsnPrintableString()
{
_tag = _type = ASN_PRINTABLE_STRING;
_mask = ASN_PRINTABLE_MASK;
}
AsnVideotexString::AsnVideotexString() { _tag = _type = ASN_VIDEOTEX_STRING; }
AsnTeletexString::AsnTeletexString()
{
_tag = _type = ASN_T61_STRING;
_mask = ASN_T61_MASK;
}
AsnIA5String::AsnIA5String()
{
_tag = _type = ASN_IA5_STRING;
_mask = ASN_IA5_MASK;
}
AsnUTCTime::AsnUTCTime() { _tag = _type = ASN_UTCTIME; }
AsnGeneralizedTime::AsnGeneralizedTime() { _tag = _type = ASN_GENTIME; }
AsnSequence::AsnSequence() { _tag = _type = ASN_SEQUENCE; }
AsnLink::AsnLink()
{
_next = 0;
objp = 0;
}
AsnLink::~AsnLink()
{
delete _next;
_next = 0;
}
AsnSet::AsnSet() { _tag = _type = ASN_SET; _relinksp = 0; }
AsnSet::~AsnSet()
{
if (_relinksp)
{
delete _relinksp;
_relinksp = 0;
}
}
AsnOf::AsnOf () { _flags |= ASN_OF_FLAG; }
int AsnOf::numitems() const
{
int count;
AsnObj *objp;
for (count = 0, objp = _sub; objp->_tag == _sub->_tag && objp->_next;
objp = objp->_next, count++);
if (objp->_tag != _sub->_tag) return asn_obj_err(ASN_OF_ERR);
return count;
}
AsnSequenceOf::AsnSequenceOf() { _tag = _type = ASN_SEQUENCE; }
AsnSetOf::AsnSetOf() { _tag = _type = ASN_SET; }
AsnDup *AsnDup::_dup() // basic virtual function
{
AsnDup *objp = new AsnDup;
_set_pointers(objp);
return objp;
}
void AsnDup::_set_pointers(AsnDup *objp)
{
/**
Function: Fills in pointers etc. for duplicated object
**/
objp->_flags |= _flags | ASN_DUPED_FLAG;
objp->_flags &= ~(ASN_FILLED_FLAG);
objp->_tag = _tag;
objp->_type = _type;
objp->_supra = _supra;
}
AsnPtr::AsnPtr() { _ptr = (AsnObj *)0; }
void AsnPtr:: _point() // basic virtual function
{
/**
Function: Makes a new object for a PTR object to point to. Used by tag_search()
**/
_ptr = new AsnObj;
_set_ptr();
}
void AsnPtr::_set_ptr()
{
_ptr->_flags |= ASN_DUPED_FLAG;
_ptr->_supra = this;
}
void AsnPtr::operator=(AsnObj *objp)
{
_ptr = objp;
objp->_supra = this;
objp->fill_upward((objp->_flags & ASN_FILLED_FLAG));
}
AsnPtr::~AsnPtr()
{
if (_ptr)
{
if ((_ptr->_flags & ASN_DUPED_FLAG)) delete _ptr;
_ptr = (AsnObj *)0;
}
}
AsnArray::~AsnArray()
{
AsnObj *nextp, *objp;
/* exported items are derived from AsnArray, but may not be used in an OF */
if (!_supra || !(_supra->_flags & ASN_OF_FLAG)) return;
for (objp = this->_supra->_sub; objp->_next; objp = nextp)
{
nextp = objp->_next;
objp->_next = objp->_supra = 0;
if ((objp->_flags & ASN_DUPED_FLAG)) delete objp;
}
}
AsnArray *AsnArray::index_op(int index)
{
/**
Function: General indexing function
Returns: Pointer to the indexed object
Procedure:
1. IF this isn't an array-type object, return itself (unnecessary test?)
Count forward the specified number of items OR to the end of the chain
IF didn't reach the desired item, report error (may go to the item with no
_next, because this may be followed by an insert()
2. Return item
**/
AsnArray *objp;
if (!_supra || !(_supra->_flags & ASN_OF_FLAG)) return objp;
if (!_next) objp = (AsnArray *)_supra->_sub;
else objp = this;
for( ; index-- && objp->_next; objp = (AsnArray *)objp->_next);
if (index >= 0) asn_obj_err(ASN_OF_BOUNDS_ERR);
return objp;
}
int AsnArray::insert()
{
/**
Function: Inserts another instance of 'this'. For an array, the new instance
goes before 'this'; for a pointer, 'this->_ptr' points to it
Returns: IF no error, the index at which the new item was inserted
ELSE -1
Procedure:
1. IF not in an array item, return error
IF the insertion will make the chain bigger than allowed, return error
2. Make a new item
IF inserting at the head (index = 0), link it in there
ELSE
Find the index and the prior item
Link the new one in there
Return the index
**/
AsnArray *prevp;
AsnDup *objp;
AsnOf *superp;
int index;
/* step 1 */
if (!_supra || !(_supra->_flags & ASN_OF_FLAG))
return asn_obj_err(ASN_NOT_OF_ERR);
superp = (AsnOf *)_supra;
if (superp->_max && superp->numitems() >= superp->_max)
return asn_obj_err(ASN_OF_BOUNDS_ERR);
/* step 2 */
objp = _dup();
if (superp->_sub == this)
{
index = 0;
objp->_next = superp->_sub;
superp->_sub = objp;
}
else
{
for (index = 1, prevp = (AsnArray *)(superp->_sub); prevp->_next &&
(AsnArray *)prevp->_next != this;
prevp = (AsnArray *)prevp->_next, index++);
objp->_next = prevp->_next;
prevp->_next = objp;
}
return index;
}
int AsnArray::remove()
{
/**
Function: Removes the specified item from an OF chain
Returns: IF error, -1; ELSE index of item in chain
Procedure:
1. IF this isn't part of an OF chain, return -1
IF is is first in chain
Change _supra->_sub to unlink this
IF chain is now empty, mark parent
ELSE
Find the index of this item and its previous object
Unlink this
2. Delete this item
Return index
**/
AsnObj *prevp;
int index;
if (!_supra || !(_supra->_flags & ASN_OF_FLAG)) /* step 1 */
return asn_obj_err(ASN_NOT_OF_ERR);
if (_supra->_sub == this)
{
index = 0;
if (!_next) return asn_obj_err(ASN_OF_BOUNDS_ERR);
_supra->_sub = _next;
if (!_next->_next) _supra->_flags &= ~(ASN_FILLED_FLAG);
}
else
{
for (index = 1, prevp = _supra->_sub; prevp->_next && prevp->_next != this;
prevp = prevp->_next, index++);
prevp->_next = _next;
}
_next = _supra = (AsnObj *)0;
/* step 2 */
delete this;
return index;
}
/*
AsnArray& AsnArray::operator++()
{
Function: Prints error message and returns pointer to 'guard' item as an
error
AsnArray *objp;
write_err("++");
for (objp = this; objp->_next; objp = (AsnArray *)objp->_next);
return *objp;
}
AsnArray& AsnArray::operator--()
{
Function: Prints error message and returns pointer to 'guard' item as an
error
AsnArray *objp;
write_err("--");
for (objp = this; objp->_next; objp = (AsnArray *)objp->_next);
return *objp;
}
*/
AsnArray& AsnArray::operator[](int index)
{
/**
Function: Indexing operator for primitives (which don't have their own
indexing functions)
Returns: Pointer to new object
**/
AsnArray *objp = index_op(index);
return *objp;
}
AsnOfArray::AsnOfArray() { _flags |= ASN_OF_FLAG; }
int AsnOfArray::numitems() const
{
int count = 0;
AsnObj *objp;
for (count = 0, objp = _sub; objp->_tag == _sub->_tag && objp->_next;
objp = objp->_next, count++);
if (objp->_tag != _sub->_tag) return asn_obj_err(ASN_OF_ERR);
return count;
}
AsnArrayOfSequencesOf::AsnArrayOfSequencesOf() { _tag = _type = ASN_SEQUENCE; }
AsnArrayOfSetsOf::AsnArrayOfSetsOf() { _tag = _type = ASN_SET; }
AsnPtrArray::AsnPtrArray() { _ptr = (AsnObj *)0; }
AsnPtrArray::~AsnPtrArray()
{
AsnPtr *nextp, *objp;
/* exported items are derived from AsnArray, but may not be used in an OF */
if (!_supra || !(_supra->_flags & ASN_OF_FLAG)) return;
for (objp = (AsnPtrArray *)this->_supra->_sub; objp->_next; objp = nextp)
{
nextp = (AsnPtrArray *)objp->_next;
objp->_next = objp->_supra = 0;
if (objp->_ptr && (objp->_ptr->_flags & ASN_DUPED_FLAG))
{
delete objp->_ptr;
_ptr = (AsnObj *)0;
}
if ((objp->_flags & ASN_DUPED_FLAG)) delete objp;
}
}
int AsnPtrArray::insert()
{
return ((AsnArray *)this)->insert();
}
int AsnPtrArray::remove()
{
return ((AsnArray *)this)->remove();
}
AsnPtrArray *AsnPtrArray::index_op(int index)
{
return (AsnPtrArray *)((AsnArray *)this)->index_op(index);
}
int AsnPtrOfArray::numitems() const
{
int count = 0;
AsnObj *objp;
for (count = 0, objp = _ptr->_sub; objp->_tag == _sub->_tag && objp->_next;
objp = objp->_next, count++);
if (objp->_tag != _sub->_tag) return asn_obj_err(ASN_OF_ERR);
return count;
}
AsnPtrArraySequenceOf::AsnPtrArraySequenceOf() { _tag = _type = ASN_SEQUENCE; }
AsnPtrArraySetOf::AsnPtrArraySetOf() { _tag = _type = ASN_SET; }
AsnChoice::AsnChoice() { _tag = _type = ASN_CHOICE; }
AsnNone::AsnNone() { _tag = _type = ASN_NONE; _flags |= ASN_OPTIONAL_FLAG; }
AsnNotAsn1::AsnNotAsn1() { _tag = _type = ASN_NOTASN1; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -