📄 asner.cxx
字号:
namesCount = other.namesCount;
if (other.CheckCreate())
choice = (PASN_Object *)other.choice->Clone();
else
choice = NULL;
return *this;
}
PASN_Choice::~PASN_Choice()
{
delete choice;
}
void PASN_Choice::SetTag(unsigned newTag, TagClass tagClass)
{
PASN_Object::SetTag(newTag, tagClass);
delete choice;
if (CreateObject())
choice->SetTag(newTag, tagClass);
}
PString PASN_Choice::GetTagName() const
{
PINDEX idx = FindNameByValue(names, namesCount, tag);
if (idx != P_MAX_INDEX)
return names[idx].name;
if (CheckCreate() &&
PIsDescendant(choice, PASN_Choice) &&
choice->GetTag() == tag &&
choice->GetTagClass() == tagClass)
return PString(choice->GetClass()) + "->" + ((PASN_Choice *)choice)->GetTagName();
return psprintf("<%u>", tag);
}
BOOL PASN_Choice::CheckCreate() const
{
if (choice != NULL)
return TRUE;
return ((PASN_Choice *)this)->CreateObject();
}
PASN_Object & PASN_Choice::GetObject() const
{
PAssert(CheckCreate(), "NULL Choice");
return *choice;
}
#if defined(__GNUC__) && __GNUC__ <= 2 && __GNUC_MINOR__ < 9
#define CHOICE_CAST_OPERATOR(cls) \
PASN_Choice::operator cls &() const \
{ \
PAssert(CheckCreate(), "Cast of NULL choice"); \
PAssert(choice->IsDescendant(cls::Class()), PInvalidCast); \
return *(cls *)choice; \
} \
#else
#define CHOICE_CAST_OPERATOR(cls) \
PASN_Choice::operator cls &() \
{ \
PAssert(CheckCreate(), "Cast of NULL choice"); \
PAssert(PIsDescendant(choice, cls), PInvalidCast); \
return *(cls *)choice; \
} \
PASN_Choice::operator const cls &() const \
{ \
PAssert(CheckCreate(), "Cast of NULL choice"); \
PAssert(PIsDescendant(choice, cls), PInvalidCast); \
return *(const cls *)choice; \
} \
#endif
CHOICE_CAST_OPERATOR(PASN_Null)
CHOICE_CAST_OPERATOR(PASN_Boolean)
CHOICE_CAST_OPERATOR(PASN_Integer)
CHOICE_CAST_OPERATOR(PASN_Enumeration)
CHOICE_CAST_OPERATOR(PASN_Real)
CHOICE_CAST_OPERATOR(PASN_ObjectId)
CHOICE_CAST_OPERATOR(PASN_BitString)
CHOICE_CAST_OPERATOR(PASN_OctetString)
CHOICE_CAST_OPERATOR(PASN_NumericString)
CHOICE_CAST_OPERATOR(PASN_PrintableString)
CHOICE_CAST_OPERATOR(PASN_VisibleString)
CHOICE_CAST_OPERATOR(PASN_IA5String)
CHOICE_CAST_OPERATOR(PASN_GeneralString)
CHOICE_CAST_OPERATOR(PASN_BMPString)
CHOICE_CAST_OPERATOR(PASN_Sequence)
PObject::Comparison PASN_Choice::Compare(const PObject & obj) const
{
PAssert(PIsDescendant(&obj, PASN_Choice), PInvalidCast);
const PASN_Choice & other = (const PASN_Choice &)obj;
CheckCreate();
other.CheckCreate();
if (choice == other.choice)
return EqualTo;
if (choice == NULL)
return LessThan;
if (other.choice == NULL)
return GreaterThan;
if (tag < other.tag)
return LessThan;
if (tag > other.tag)
return GreaterThan;
return choice->Compare(*other.choice);
}
void PASN_Choice::PrintOn(ostream & strm) const
{
strm << GetTagName();
if (choice != NULL)
strm << ' ' << *choice;
else
strm << " (NULL)";
}
PString PASN_Choice::GetTypeAsString() const
{
return "Choice";
}
PINDEX PASN_Choice::GetDataLength() const
{
if (CheckCreate())
return choice->GetDataLength();
return 0;
}
BOOL PASN_Choice::IsPrimitive() const
{
if (CheckCreate())
return choice->IsPrimitive();
return FALSE;
}
BOOL PASN_Choice::Decode(PASN_Stream & strm)
{
return strm.ChoiceDecode(*this);
}
void PASN_Choice::Encode(PASN_Stream & strm) const
{
strm.ChoiceEncode(*this);
}
PINDEX PASN_Choice::GetValueByName(PString name) const
{
for(unsigned uiIndex = 0; uiIndex < numChoices; uiIndex++){
if(strcmp(names[uiIndex].name, name) == 0){
return names[uiIndex].value;
}
}
return UINT_MAX;
}
///////////////////////////////////////////////////////////////////////
PASN_Sequence::PASN_Sequence(unsigned tag, TagClass tagClass,
unsigned nOpts, BOOL extend, unsigned nExtend)
: PASN_Object(tag, tagClass, extend)
{
optionMap.SetConstraints(PASN_ConstrainedObject::FixedConstraint, nOpts);
knownExtensions = nExtend;
totalExtensions = 0;
endBasicEncoding = 0;
}
PASN_Sequence::PASN_Sequence(const PASN_Sequence & other)
: PASN_Object(other),
fields(other.fields.GetSize()),
optionMap(other.optionMap),
extensionMap(other.extensionMap)
{
for (PINDEX i = 0; i < other.fields.GetSize(); i++)
fields.SetAt(i, other.fields[i].Clone());
knownExtensions = other.knownExtensions;
totalExtensions = other.totalExtensions;
endBasicEncoding = 0;
}
PASN_Sequence & PASN_Sequence::operator=(const PASN_Sequence & other)
{
PASN_Object::operator=(other);
fields.SetSize(other.fields.GetSize());
for (PINDEX i = 0; i < other.fields.GetSize(); i++)
fields.SetAt(i, other.fields[i].Clone());
optionMap = other.optionMap;
knownExtensions = other.knownExtensions;
totalExtensions = other.totalExtensions;
extensionMap = other.extensionMap;
return *this;
}
BOOL PASN_Sequence::HasOptionalField(PINDEX opt) const
{
if (opt < (PINDEX)optionMap.GetSize())
return optionMap[opt];
else
return extensionMap[opt - optionMap.GetSize()];
}
void PASN_Sequence::IncludeOptionalField(PINDEX opt)
{
if (opt < (PINDEX)optionMap.GetSize())
optionMap.Set(opt);
else {
PAssert(extendable, "Must be extendable type");
opt -= optionMap.GetSize();
if (opt >= (PINDEX)extensionMap.GetSize())
extensionMap.SetSize(opt+1);
extensionMap.Set(opt);
}
}
void PASN_Sequence::RemoveOptionalField(PINDEX opt)
{
if (opt < (PINDEX)optionMap.GetSize())
optionMap.Clear(opt);
else {
PAssert(extendable, "Must be extendable type");
opt -= optionMap.GetSize();
extensionMap.Clear(opt);
}
}
PObject::Comparison PASN_Sequence::Compare(const PObject & obj) const
{
PAssert(PIsDescendant(&obj, PASN_Sequence), PInvalidCast);
const PASN_Sequence & other = (const PASN_Sequence &)obj;
return fields.Compare(other.fields);
}
PObject * PASN_Sequence::Clone() const
{
PAssert(IsClass(PASN_Sequence::Class()), PInvalidCast);
return new PASN_Sequence(*this);
}
void PASN_Sequence::PrintOn(ostream & strm) const
{
int indent = strm.precision() + 2;
strm << "{\n";
for (PINDEX i = 0; i < fields.GetSize(); i++) {
strm << setw(indent+6) << "field[" << i << "] <";
switch (fields[i].GetTagClass()) {
case UniversalTagClass :
strm << "Universal";
break;
case ApplicationTagClass :
strm << "Application";
break;
case ContextSpecificTagClass :
strm << "ContextSpecific";
break;
case PrivateTagClass :
strm << "Private";
default :
break;
}
strm << '-' << fields[i].GetTag() << '-'
<< fields[i].GetTypeAsString() << "> = "
<< fields[i] << '\n';
}
strm << setw(indent-1) << "}";
}
PString PASN_Sequence::GetTypeAsString() const
{
return "Sequence";
}
PINDEX PASN_Sequence::GetDataLength() const
{
PINDEX len = 0;
for (PINDEX i = 0; i < fields.GetSize(); i++)
len += fields[i].GetObjectLength();
return len;
}
BOOL PASN_Sequence::IsPrimitive() const
{
return FALSE;
}
BOOL PASN_Sequence::Decode(PASN_Stream & strm)
{
return PreambleDecode(strm) && UnknownExtensionsDecode(strm);
}
void PASN_Sequence::Encode(PASN_Stream & strm) const
{
PreambleEncode(strm);
UnknownExtensionsEncode(strm);
}
BOOL PASN_Sequence::PreambleDecode(PASN_Stream & strm)
{
return strm.SequencePreambleDecode(*this);
}
void PASN_Sequence::PreambleEncode(PASN_Stream & strm) const
{
strm.SequencePreambleEncode(*this);
}
BOOL PASN_Sequence::KnownExtensionDecode(PASN_Stream & strm, PINDEX fld, PASN_Object & field)
{
return strm.SequenceKnownDecode(*this, fld, field);
}
void PASN_Sequence::KnownExtensionEncode(PASN_Stream & strm, PINDEX fld, const PASN_Object & field) const
{
strm.SequenceKnownEncode(*this, fld, field);
}
BOOL PASN_Sequence::UnknownExtensionsDecode(PASN_Stream & strm)
{
return strm.SequenceUnknownDecode(*this);
}
void PASN_Sequence::UnknownExtensionsEncode(PASN_Stream & strm) const
{
strm.SequenceUnknownEncode(*this);
}
///////////////////////////////////////////////////////////////////////
PASN_Set::PASN_Set(unsigned tag, TagClass tagClass,
unsigned nOpts, BOOL extend, unsigned nExtend)
: PASN_Sequence(tag, tagClass, nOpts, extend, nExtend)
{
}
PObject * PASN_Set::Clone() const
{
PAssert(IsClass(PASN_Set::Class()), PInvalidCast);
return new PASN_Set(*this);
}
PString PASN_Set::GetTypeAsString() const
{
return "Set";
}
///////////////////////////////////////////////////////////////////////
PASN_Array::PASN_Array(unsigned tag, TagClass tagClass)
: PASN_ConstrainedObject(tag, tagClass)
{
}
PASN_Array::PASN_Array(const PASN_Array & other)
: PASN_ConstrainedObject(other),
array(other.array.GetSize())
{
for (PINDEX i = 0; i < other.array.GetSize(); i++)
array.SetAt(i, other.array[i].Clone());
}
PASN_Array & PASN_Array::operator=(const PASN_Array & other)
{
PASN_ConstrainedObject::operator=(other);
array.SetSize(other.array.GetSize());
for (PINDEX i = 0; i < other.array.GetSize(); i++)
array.SetAt(i, other.array[i].Clone());
return *this;
}
BOOL PASN_Array::SetSize(PINDEX newSize)
{
if (newSize > MaximumArraySize)
return FALSE;
PINDEX originalSize = array.GetSize();
if (!array.SetSize(newSize))
return FALSE;
for (PINDEX i = originalSize; i < newSize; i++) {
PASN_Object * obj = CreateObject();
if (obj == NULL)
return FALSE;
array.SetAt(i, obj);
}
return TRUE;
}
PObject::Comparison PASN_Array::Compare(const PObject & obj) const
{
PAssert(PIsDescendant(&obj, PASN_Array), PInvalidCast);
const PASN_Array & other = (const PASN_Array &)obj;
return array.Compare(other.array);
}
void PASN_Array::PrintOn(ostream & strm) const
{
int indent = strm.precision() + 2;
strm << array.GetSize() << " entries {\n";
for (PINDEX i = 0; i < array.GetSize(); i++)
strm << setw(indent+1) << "[" << i << "]=" << setprecision(indent) << array[i] << '\n';
strm << setw(indent-1) << "}";
}
void PASN_Array::SetConstraintBounds(ConstraintType type, int lower, unsigned upper)
{
if (lower < 0)
return;
PASN_ConstrainedObject::SetConstraintBounds(type, lower, upper);
if (constraint != Unconstrained) {
if (GetSize() < (PINDEX)lowerLimit)
SetSize(lowerLimit);
else if (GetSize() > (PINDEX)upperLimit)
SetSize(upperLimit);
}
}
PString PASN_Array::GetTypeAsString() const
{
return "Array";
}
PINDEX PASN_Array::GetDataLength() const
{
PINDEX len = 0;
for (PINDEX i = 0; i < array.GetSize(); i++)
len += array[i].GetObjectLength();
return len;
}
BOOL PASN_Array::IsPrimitive() const
{
return FALSE;
}
BOOL PASN_Array::Decode(PASN_Stream & strm)
{
return strm.ArrayDecode(*this);
}
void PASN_Array::Encode(PASN_Stream & strm) const
{
strm.ArrayEncode(*this);
}
//////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -