?? assign.cpp
字號:
/* Sep 25 1995 282U */
/* Sep 25 1995 GARDINER added assignment, comparison and conversion operators */
/*****************************************************************************
File: assign.C
Contents: Functions to implement the assignment operator for ASN.1 objects.
System: ASN development.
Created:
Author: Charles W. Gardiner <gardiner@bbn.com>
Remarks:
COPYRIGHT 1995 BBN Systems and Technologies, A Division of Bolt Beranek and
Newman Inc.
150 CambridgePark Drive
Cambridge, Ma. 02140
617-873-4000
*****************************************************************************/
#ifndef lint
const char assign_rcsid[]="$Header: /nfs/sub-rosa/u2/IOS_Project/ASN/Dev/rcs/lib/asn_obj/assign.C,v 1.2 1995/09/25 22:15:17 gardiner Exp $";
const char assign_sfcsid[] = "@(#)assign.C 282P";
#endif
#include "includes.h"
#include "asn_obj.h"
void AsnObj::operator=(const AsnObj & frobj)
{
const AsnObj *fobjp = &frobj;
AsnObj *tobjp;
// fprintf(stderr, "this = %lX, type = %lX\n", (long)this, (long)this->_type);
if ((_flags & ASN_FILLED_FLAG)) this->clear();
if ((fobjp->_flags & ASN_POINTER_FLAG) &&
!(fobjp = ((AsnPtr &)frobj)._ptr)) return;
if ((this->_flags & ASN_POINTER_FLAG))
{
AsnPtr *ptobjp = (AsnPtr *)this; // just a cast
ptobjp->_point();
tobjp = ptobjp->_ptr;
}
else tobjp = this;
if (tobjp->_type != fobjp->_type || (tobjp->_flags & ASN_OF_FLAG) !=
(fobjp->_flags & ASN_OF_FLAG))
{
asn_obj_err(ASN_MATCH_ERR);
return;
}
if (!(fobjp->_flags & ASN_FILLED_FLAG)) return;
if (fobjp->_type == ASN_CHOICE) *((AsnChoice *)tobjp) = *((AsnChoice *)fobjp);
else if ((fobjp->_flags & ASN_OF_FLAG)) *((AsnOf *)tobjp) = *((AsnOf *)fobjp);
else if (fobjp->_type == ASN_SEQUENCE)
*((AsnSequence *)tobjp) = *((AsnSequence *)fobjp);
else if (fobjp->_type == ASN_SET) *((AsnSet *)tobjp) = *((AsnSet *)fobjp);
else if (!fobjp->_valp) return;
else if ((tobjp->_flags & ASN_TABLE_FLAG) || tobjp->_sub)
{ // a definer or a defined INTEGER, ENUM or BIT STRING.
if (fobjp->copy(tobjp) < 0) return; // to check the value
}
else
{
fobjp->_valp->copy(tobjp);
tobjp->fill_upward(ASN_FILLED_FLAG);
}
}
void AsnChoice::operator=(const AsnChoice & frobj)
{
const AsnObj *fsubp;
AsnObj *tsubp;
int flag;
if ((_flags & ASN_DEFINED_FLAG) != (frobj._flags & ASN_DEFINED_FLAG))
{
asn_obj_err(ASN_MATCH_ERR);
return;
}
flag = ((_flags & ASN_DEFINED_FLAG))? ASN_CHOSEN_FLAG: ASN_FILLED_FLAG;
for (fsubp = frobj._sub; fsubp && !(fsubp->_flags & flag); fsubp = fsubp->_next);
if (!fsubp) return;
if (!(_flags & ASN_DEFINED_FLAG)) // a CHOICE
{
for (tsubp = _sub; tsubp && tsubp->_tag != fsubp->_tag;
tsubp = tsubp->_next);
}
else for (tsubp = _sub; tsubp && !(tsubp->_flags & flag); tsubp = tsubp->_next);
if (!tsubp) return;
(*tsubp) = (*fsubp);
}
void AsnOf::operator=(const AsnOf & frobj)
{
int map_num;
const AsnObj *fsubp;
AsnObj *ntsubp, *tsubp;
if ((_flags & ASN_FILLED_FLAG)) this->clear();
for (fsubp = (AsnArray *)frobj._sub, tsubp = (AsnArray *)_sub,
map_num = 0; fsubp && fsubp->_next; fsubp = fsubp->_next, map_num++)
{
if (_max && map_num > _max)
{
asn_obj_err(ASN_OF_BOUNDS_ERR);
return;
}
ntsubp = ((AsnArray *)tsubp)->_dup();
if (!tsubp->_next)
{
ntsubp->_next = tsubp;
_sub = ntsubp;
}
else
{
ntsubp->_next = tsubp->_next;
tsubp->_next = ntsubp;
}
tsubp = ntsubp;
(*tsubp) = (*fsubp);
}
}
void AsnSequence::operator=(const AsnSequence & frobj)
{
const AsnObj *fsubp;
AsnObj *tsubp;
if ((_flags & ASN_FILLED_FLAG)) this->clear();
for (fsubp = frobj._sub, tsubp = _sub; tsubp && fsubp; fsubp = fsubp->_next,
tsubp = tsubp->_next)
{
(*tsubp) = (*fsubp);
}
}
void AsnSet::operator=(const AsnSet & frobj)
{
const AsnObj *fsubp;
AsnObj *tsubp;
if ((_flags & ASN_FILLED_FLAG)) this->clear();
for (fsubp = frobj._sub; fsubp; fsubp = fsubp->_next)
{
for (tsubp = _sub; tsubp && tsubp->_tag != fsubp->_tag;
tsubp = tsubp->_next);
AsnLink *relinkp;
if (!this->_relinksp) this->_relinksp = relinkp = new AsnLink;
else
{
for (relinkp = _relinksp; relinkp->_next; relinkp = relinkp->_next);
relinkp->_next = new AsnLink;
relinkp = relinkp->_next;
}
relinkp->objp = tsubp;
(*tsubp) = (*fsubp);
}
}
void AsnTableObj::operator=(const AsnTableObj &frobj)
{
const AsnObj *fobjp = &frobj;
*((AsnObj *)this) = (*fobjp);
}
void AsnPtr::operator=(const AsnPtr &frobj)
{
const AsnObj *fsubp = frobj._ptr;
AsnObj *tsubp;
if (!fsubp) return;
if (_ptr) clear();
_point();
tsubp = _ptr;
(*tsubp) = (*fsubp);
}
AsnNumeric::operator long() const
{
long i;
read(&i);
return i;
}
void AsnNumeric::operator=(const long val) { write(val); }
void AsnBoolean::operator=(const long val) { write(val); }
void AsnInteger::operator=(const long val) { write(val); }
void AsnOctetString::operator=(const char *c) { write((uchar *)c, strlen(c)); }
void AsnObjectIdentifier::operator=(const char *c) { write(c, strlen(c)); }
void AsnEnumerated::operator=(const long val) { write(val); }
void AsnNumericString::operator=(const char *c) { write((uchar *)c, strlen(c)); }
void AsnPrintableString::operator=(const char *c) { write((uchar *)c, strlen(c)); }
void AsnVideotexString::operator=(const char *c) { write((uchar *)c, strlen(c)); }
void AsnTeletexString::operator=(const char *c) { write((uchar *)c, strlen(c)); }
void AsnUTCTime::operator=(const long val) { write(val); }
void AsnGeneralizedTime::operator=(const long val) { write(val); }
void AsnNumericArray::operator=(const long val) { write(val); }
void AsnStringArray::operator=(const char *c) { write((uchar *)c, strlen(c)); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -