📄 cxxmultipleconstraints.c
字号:
}/*switch(curr......SINGLE)*/ }/*if(curr.......SINGLE)*/ curr=curr->next; }/*while(curr)*/ src=src;/*avoids warning on unused parameter*/ return found;}/*int BasicTypeInt_LISTS*//*Handles constraints found in the subtypes of primitives*/int PrintCxxMultiConstraintOrHandler PARAMS((hdr, src, definedName, e, i), FILE* hdr _AND_ FILE* src _AND_ char* definedName _AND_ NamedType* e _AND_ int i){ int returnvalue=0; char *pszGlobalExport=""; char *className; char *tmpClassName; className = strdup(e->type->cxxTypeRefInfo->fieldName); className[0] = (char)toupper(className[0]); if(!strcmp(className, e->type->cxxTypeRefInfo->className)) { tmpClassName = strdup(className); free(className); className = malloc(strlen(tmpClassName) + 3); strcpy(className, tmpClassName); strcat(className, "_\0"); free(tmpClassName); } else if(i == 1 || i == 3) { if(!strcmp(className, definedName) ) { tmpClassName = strdup(className); free(className); className = malloc(strlen(tmpClassName) + 3); strcpy(className, tmpClassName); strcat(className, "_\0"); free(tmpClassName); } } className = Asn1TypeName2CTypeName(className); e->type->cxxTypeRefInfo->fieldName = Asn1TypeName2CTypeName(e->type->cxxTypeRefInfo->fieldName); e->type->cxxTypeRefInfo->className = Asn1TypeName2CTypeName(e->type->cxxTypeRefInfo->className); if (bVDAGlobalDLLExport) pszGlobalExport = bVDAGlobalDLLExport; switch(e->type->basicType->choiceId) { case BASICTYPE_INTEGER: { Subtype* s_type; Subtype* currS_type=NULL; Subtype* andS_type=NULL; Subtype* fakeList=NULL; AsnListNode* curr; AsnListNode* and_curr; int iVRPresent = 0; int count = 0; ValueRange vrList[15]; s_type = e->type->subtypes; if(s_type->choiceId==SUBTYPE_AND) { and_curr=s_type->a.and->first; while(and_curr) { andS_type=and_curr->data; if(andS_type->choiceId == SUBTYPE_OR) { curr=andS_type->a.or->first; iVRPresent += ValueRange_LISTS(hdr, src, vrList, iVRPresent, curr, currS_type); } else if(andS_type->choiceId == SUBTYPE_SINGLE) { fakeList = MT(Subtype); fakeList->choiceId = SUBTYPE_OR; APPEND(andS_type, fakeList->a.or); curr = fakeList->a.or->first; iVRPresent += ValueRange_LISTS(hdr, src, vrList, iVRPresent, curr, currS_type); } and_curr=and_curr->next; } } else if(s_type->choiceId == SUBTYPE_OR) { curr=s_type->a.or->first; iVRPresent += ValueRange_LISTS(hdr, src, vrList, iVRPresent, curr, currS_type); } else if(s_type->choiceId == SUBTYPE_SINGLE) { fakeList = MT(Subtype); fakeList->choiceId = SUBTYPE_OR; APPEND(s_type, fakeList->a.or); curr = fakeList->a.or->first; iVRPresent += ValueRange_LISTS(hdr, src, vrList, iVRPresent, curr, currS_type); } /*print the generic header for the generated class*/ fprintf (hdr, "class %s %s: public AsnInt {\n", pszGlobalExport, className); fprintf (hdr, " public:\n"); fprintf (hdr, " %s(AsnIntType val=0):AsnInt(val){ }\n", className); fprintf (hdr, " %s(const char *str, bool unsignedFlag = true):AsnInt(str, unsignedFlag){ }\n", className); fprintf (hdr, " %s(const AsnOcts &o, bool unsignedFlag = true):AsnInt(o, unsignedFlag){ }\n", className); fprintf (hdr, " %s(const char *str, const size_t len, bool unsignedFlag = true):AsnInt(str, len, unsignedFlag){ }\n", className); fprintf (hdr, " %s(const %s &that):AsnInt(that){ }\n\n", className, className); fprintf(hdr, " %s & operator =(const %s &o);\n", className, className); if(i == 1 || i == 3) { fprintf(src, "%s::", definedName); } fprintf(src, "%s & \n", className); if(i == 1 || i == 3) { fprintf(src, "%s::", definedName); } fprintf(src, "%s::operator =(const %s &that)\n", className, className); fprintf(src, "{\n"); fprintf(src, " m_len = that.m_len;\n"); fprintf(src, " delete m_bytes;\n"); fprintf(src, " m_bytes = new unsigned char[m_len];\n"); fprintf(src, " memcpy(m_bytes, that.m_bytes, m_len);\n"); fprintf(src, " return *this;\n}\n\n"); fprintf (hdr, " const ValueRange* ValueRanges(int &sizeVRList) const;\n\n"); fprintf (src, "const ValueRange* \n"); if(i == 1 || i == 3) { fprintf(src, "%s::", definedName); } fprintf(src, "%s::ValueRanges(int &sizeVRList) const\n", className); fprintf (src, "{\n"); if(iVRPresent > 0) { fprintf(src, " static const ValueRange %s_ValueRangeList[] = \n {", e->type->cxxTypeRefInfo->fieldName); for(count = 0; count < iVRPresent; count++) { fprintf(src, "{ %ld, %ld, %d }", vrList[count].lowerBound, vrList[count].upperBound, vrList[count].upperBoundExists); if(count + 1 < iVRPresent) { fprintf(src, ",\n "); } } fprintf(src, "};\n\n"); fprintf(src, " sizeVRList = %d;\n", iVRPresent); fprintf(src, " return &%s_ValueRangeList[0];\n", e->type->cxxTypeRefInfo->fieldName); } else { fprintf(src, " sizeVRList = 0;\n"); fprintf(src, " return NULL;\n"); } fprintf (src, "}\n\n");/* fprintf(hdr, " AsnLen PEnc (AsnBufBits &_b, bool bAlign = false){return PEncConstraints(_b, bAlign);}\n"); fprintf(hdr, " void PDec (AsnBufBits &_b, AsnLen &bitsDecoded, bool bAlign = false){PDecConstraints(_b, bitsDecoded, bAlign);}\n");*/ fprintf (hdr, " };\n"); if(i != 3 && i != 0) { /* Last we declare an instance of the internal class we */ /* just created */ if(i==0) { fprintf (hdr, "typedef "); }/*if(i==0)*/ fprintf (hdr, " %s ", className); if (e->type->cxxTypeRefInfo->isPtr) { fprintf (hdr, "*"); }/*if (e->type->cxxTypeRefInfo->isPtr)*/ fprintf (hdr, "%s;\n", e->type->cxxTypeRefInfo->fieldName); fprintf (hdr, "\n\n"); } free(e->type->cxxTypeRefInfo->className); e->type->cxxTypeRefInfo->className = strdup(className); returnvalue=1; break; }/*case BASICTYPE_INTEGER*/ case BASICTYPE_NUMERIC_STR: case BASICTYPE_PRINTABLE_STR: case BASICTYPE_IA5_STR: case BASICTYPE_VISIBLE_STR: { int bAlphafound=0; unsigned char cPermittedAlphabet[500]; char cAlpha[1000]; int iAlphasize = 0; int iSort1 = 0; int iSort2 = 0; unsigned char cSort = 0x00; int j = 0; Subtype* s_type; Subtype* currS_type=NULL; Subtype* andS_type=NULL; Subtype* fakeList = NULL; AsnListNode* curr; AsnListNode* and_curr; char* cTmp; int iSCPresent = 0; int count = 0; int iSCLowerBound = 0; int iSCUpperBound = 0; SizeConstraint scList[15]; /*print the generic header for the generated class*/ fprintf (hdr, "class %s %s: public %s {\n", pszGlobalExport, className, e->type->cxxTypeRefInfo->className); s_type = e->type->subtypes; iSort2 = iSort2; if(s_type->choiceId==SUBTYPE_AND) { and_curr=s_type->a.and->first; while(and_curr) { andS_type=and_curr->data; if(andS_type->choiceId == SUBTYPE_OR) { curr=andS_type->a.or->first; cTmp=FindPermittedAlpha(curr, cPermittedAlphabet, &iAlphasize); } else if(andS_type->choiceId == SUBTYPE_SINGLE) { fakeList = MT(Subtype); fakeList->choiceId = SUBTYPE_OR; APPEND(andS_type, fakeList->a.or); curr = fakeList->a.or->first; cTmp=FindPermittedAlpha(curr, cPermittedAlphabet, &iAlphasize); } and_curr=and_curr->next; } } else if(s_type->choiceId == SUBTYPE_OR) { curr=s_type->a.or->first; cTmp=FindPermittedAlpha(curr, cPermittedAlphabet, &iAlphasize); } else if(s_type->choiceId == SUBTYPE_SINGLE) { fakeList = MT(Subtype); fakeList->choiceId = SUBTYPE_OR; APPEND(s_type, fakeList->a.or); curr = fakeList->a.or->first; cTmp=FindPermittedAlpha(curr, cPermittedAlphabet, &iAlphasize); } if(iAlphasize > 0) { bAlphafound=1; for(iSort1 = 0; iSort1 < iAlphasize; iSort1++) { for(iSort2 = (iSort1 +1); iSort2 < iAlphasize; iSort2++) { if(cPermittedAlphabet[iSort1] > cPermittedAlphabet[iSort2]) { cSort = cPermittedAlphabet[iSort2]; cPermittedAlphabet[iSort2] = cPermittedAlphabet[iSort1]; cPermittedAlphabet[iSort1] = cSort; } } } for(iSort1 = 0; iSort1 < iAlphasize; iSort1++) { if(iSort1 == 0) j += sprintf(cAlpha+j, "0x%x", cPermittedAlphabet[iSort1]); else j += sprintf(cAlpha+j, ",0x%x", cPermittedAlphabet[iSort1]); } } s_type = e->type->subtypes; if(s_type->choiceId==SUBTYPE_AND) { and_curr=s_type->a.and->first; while(and_curr) { andS_type=and_curr->data; if(andS_type->choiceId == SUBTYPE_OR) { curr=andS_type->a.or->first; iSCPresent = BasicTypeString_LISTS(hdr, src, scList, iSCPresent, curr, currS_type); } else if(andS_type->choiceId == SUBTYPE_SINGLE) { fakeList = MT(Subtype); fakeList->choiceId = SUBTYPE_OR; APPEND(andS_type, fakeList->a.or); curr = fakeList->a.or->first; iSCPresent = BasicTypeString_LISTS(hdr, src, scList, iSCPresent, curr, currS_type); } and_curr=and_curr->next; } } else if(s_type->choiceId == SUBTYPE_OR) { curr=s_type->a.or->first; iSCPresent = BasicTypeString_LISTS(hdr, src, scList, iSCPresent, curr, currS_type); } else if(s_type->choiceId == SUBTYPE_SINGLE) { fakeList = MT(Subtype); fakeList->choiceId = SUBTYPE_OR; APPEND(s_type, fakeList->a.or); curr = fakeList->a.or->first; iSCPresent = BasicTypeString_LISTS(hdr, src, scList, iSCPresent, curr, currS_type); } fprintf (hdr, " public:\n"); fprintf (hdr, " %s():%s(){ }\n\n", className, e->type->cxxTypeRefInfo->className); fprintf (hdr, " const SizeConstraint* SizeConstraints(int &sizeList)const;\n\n"); fprintf (src, "const SizeConstraint* \n"); if(i == 1 || i == 3) { fprintf(src, "%s::", definedName); } fprintf(src, "%s::SizeConstraints(int &sizeList)const\n", className); fprintf (src, "{\n"); if(iSCPresent > 0 ) { count = 0; if(scList[count].upperBoundExists == 1 && scList[count].upperBound > iSCUpperBound) { iSCUpperBound = scList[count].upperBound; } if(scList[count].upperBoundExists == 0 && scList[count].lowerBound > iSCUpperBound) { iSCUpperBound = scList[count].lowerBound; } if(scList[count].lowerBound < iSCLowerBound) { iSCLowerBound = scList[count].lowerBound; } while(count < iSCPresent) { if(scList[count].upperBoundExists == 2) { iSCPresent = 0; } count++; } } if(iSCPresent > 0 ) { fprintf(src, " static const SizeConstraint %s_SizeConstraintList[] = \n {", e->type->cxxTypeRefInfo->fieldName); for(count = 0; count < iSCPresent; count++) { fprintf(src, "{ %ld, %ld, %d }", scList[count].lowerBound, scList[count].upperBound, scList[count].upperBoundExists); if(count + 1 < iSCPresent) { fprintf(src, ",\n "); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -