├── .gitattributes ├── .gitignore ├── BasicParserCPP ├── Autotest │ ├── Autotest.vcxproj │ ├── Autotest.vcxproj.filters │ ├── Include │ │ └── usdsAutotest.h │ └── Source │ │ ├── UnitTest │ │ ├── Base │ │ │ ├── usdsBinaryInputTest.cpp │ │ │ ├── usdsBinaryOutputTest.cpp │ │ │ ├── usdsErrorTest.cpp │ │ │ ├── usdsObjectPoolTest.cpp │ │ │ └── usdsTypeConversionTest.cpp │ │ ├── Body │ │ │ ├── usdsArrayTest.cpp │ │ │ ├── usdsBooleanTest.cpp │ │ │ ├── usdsByteTest.cpp │ │ │ ├── usdsDoubleTest.cpp │ │ │ ├── usdsEnumTest.cpp │ │ │ ├── usdsFloatTest.cpp │ │ │ ├── usdsIntTest.cpp │ │ │ ├── usdsLongTest.cpp │ │ │ ├── usdsPolymorphTest.cpp │ │ │ ├── usdsShortTest.cpp │ │ │ ├── usdsStringTest.cpp │ │ │ ├── usdsStructTest.cpp │ │ │ ├── usdsUByteTest.cpp │ │ │ ├── usdsUIntTest.cpp │ │ │ ├── usdsULongTest.cpp │ │ │ ├── usdsUShortTest.cpp │ │ │ ├── usdsUVarintTest.cpp │ │ │ └── usdsVarintTest.cpp │ │ ├── Converters │ │ │ └── Parsers │ │ │ │ ├── usdsDictionaryTextParserAttributes.cpp │ │ │ │ ├── usdsDictionaryTextParserEnum.cpp │ │ │ │ ├── usdsDictionaryTextParserPolymorph.cpp │ │ │ │ ├── usdsDictionaryTextParserTest.cpp │ │ │ │ └── usdsDictionaryTextParserTestAutoId.cpp │ │ └── Dictionary │ │ │ ├── dictionaryArrayTest.cpp │ │ │ ├── dictionaryEnumTest.cpp │ │ │ ├── dictionaryPolymorphTest.cpp │ │ │ ├── dictionarySimpleTest.cpp │ │ │ ├── dictionaryStringTest.cpp │ │ │ ├── dictionaryStructTest.cpp │ │ │ ├── dictionaryTagLinkTest.cpp │ │ │ └── usdsDictionaryTest.cpp │ │ ├── usdsAutotest.cpp │ │ └── usdsTestGenerator.py ├── BasicParser │ ├── BasicParser.vcxproj │ ├── BasicParser.vcxproj.filters │ ├── Include │ │ ├── binary │ │ │ ├── usdsBinaryInput.h │ │ │ ├── usdsBinaryOutput.h │ │ │ └── usdsTypeConverter.h │ │ ├── body │ │ │ ├── bodyObjectPool.h │ │ │ ├── dataTypes │ │ │ │ ├── usdsArray.h │ │ │ │ ├── usdsBoolean.h │ │ │ │ ├── usdsByte.h │ │ │ │ ├── usdsDouble.h │ │ │ │ ├── usdsEnum.h │ │ │ │ ├── usdsFloat.h │ │ │ │ ├── usdsInt.h │ │ │ │ ├── usdsLong.h │ │ │ │ ├── usdsShort.h │ │ │ │ ├── usdsString.h │ │ │ │ ├── usdsStruct.h │ │ │ │ ├── usdsUByte.h │ │ │ │ ├── usdsUInt.h │ │ │ │ ├── usdsULong.h │ │ │ │ ├── usdsUShort.cpp │ │ │ │ ├── usdsUShort.h │ │ │ │ ├── usdsUVarint.h │ │ │ │ └── usdsVarint.h │ │ │ ├── usdsBaseType.h │ │ │ └── usdsBody.h │ │ ├── common │ │ │ ├── errorMessage.h │ │ │ └── objectPool.h │ │ ├── converters │ │ │ ├── usdsBinaryCreator.h │ │ │ ├── usdsBinaryParser.h │ │ │ ├── usdsBodyBinaryCreator.h │ │ │ ├── usdsBodyBinaryParser.h │ │ │ ├── usdsBodyJsonCreator.h │ │ │ ├── usdsDictionaryBinaryCreator.h │ │ │ ├── usdsDictionaryBinaryParser.h │ │ │ ├── usdsDictionaryTextCreator.h │ │ │ └── usdsDictionaryTextParser.h │ │ ├── dictionary │ │ │ ├── dataTypes │ │ │ │ ├── dictionaryArray.h │ │ │ │ ├── dictionaryBoolean.h │ │ │ │ ├── dictionaryByte.h │ │ │ │ ├── dictionaryDouble.h │ │ │ │ ├── dictionaryEnum.h │ │ │ │ ├── dictionaryFloat.h │ │ │ │ ├── dictionaryInt.h │ │ │ │ ├── dictionaryLong.h │ │ │ │ ├── dictionaryPolymorph.h │ │ │ │ ├── dictionaryShort.h │ │ │ │ ├── dictionaryString.h │ │ │ │ ├── dictionaryStruct.h │ │ │ │ ├── dictionaryTagLink.h │ │ │ │ ├── dictionaryUByte.h │ │ │ │ ├── dictionaryUInt.h │ │ │ │ ├── dictionaryULong.h │ │ │ │ ├── dictionaryUShort.h │ │ │ │ ├── dictionaryUVarint.h │ │ │ │ └── dictionaryVarint.h │ │ │ ├── dicObjectPool.h │ │ │ ├── dictionaryBaseType.h │ │ │ └── usdsDictionary.h │ │ ├── usdsBasicParser.h │ │ ├── usdsErrors.h │ │ └── usdsTypes.h │ └── Source │ │ ├── Binary │ │ ├── usdsBinaryInput.cpp │ │ ├── usdsBinaryOutput.cpp │ │ └── usdsTypeConverter.cpp │ │ ├── Body │ │ ├── DataTypes │ │ │ ├── usdsArray.cpp │ │ │ ├── usdsBoolean.cpp │ │ │ ├── usdsByte.cpp │ │ │ ├── usdsDouble.cpp │ │ │ ├── usdsEnum.cpp │ │ │ ├── usdsFloat.cpp │ │ │ ├── usdsInt.cpp │ │ │ ├── usdsLong.cpp │ │ │ ├── usdsShort.cpp │ │ │ ├── usdsString.cpp │ │ │ ├── usdsStruct.cpp │ │ │ ├── usdsUByte.cpp │ │ │ ├── usdsUInt.cpp │ │ │ ├── usdsULong.cpp │ │ │ ├── usdsUVarint.cpp │ │ │ └── usdsVarint.cpp │ │ ├── bodyObjectPool.cpp │ │ ├── usdsBaseType.cpp │ │ └── usdsBody.cpp │ │ ├── Common │ │ ├── errorMessage.cpp │ │ └── objectPool.cpp │ │ ├── Converters │ │ ├── DictionaryTextParser │ │ │ ├── bisonDictionaryTextParser.cc │ │ │ ├── bisonDictionaryTextParser.hh │ │ │ ├── bisonDictionaryTextParser.y │ │ │ ├── flexDictionaryTextScanner.c │ │ │ ├── flexDictionaryTextScanner.cpp │ │ │ ├── flexDictionaryTextScanner.h │ │ │ ├── flexDictionaryTextScanner.l │ │ │ ├── location.hh │ │ │ ├── position.hh │ │ │ ├── stack.hh │ │ │ ├── updateBisonOutput.py │ │ │ ├── usdsDictionaryTextParser.cpp │ │ │ └── win_create_parser.bat │ │ ├── FlexLexer │ │ │ └── FlexLexer.h │ │ ├── usdsBinaryCreator.cpp │ │ ├── usdsBinaryParser.cpp │ │ ├── usdsBodyBinaryCreator.cpp │ │ ├── usdsBodyBinaryParser.cpp │ │ ├── usdsBodyJsonCreator.cpp │ │ ├── usdsDictionaryBinaryCreator.cpp │ │ ├── usdsDictionaryBinaryParser.cpp │ │ └── usdsDictionaryTextCreator.cpp │ │ ├── Dictionary │ │ ├── DataTypes │ │ │ ├── dictionaryArray.cpp │ │ │ ├── dictionaryBoolean.cpp │ │ │ ├── dictionaryByte.cpp │ │ │ ├── dictionaryDouble.cpp │ │ │ ├── dictionaryEnum.cpp │ │ │ ├── dictionaryFloat.cpp │ │ │ ├── dictionaryInt.cpp │ │ │ ├── dictionaryLong.cpp │ │ │ ├── dictionaryPolymorph.cpp │ │ │ ├── dictionaryShort.cpp │ │ │ ├── dictionaryString.cpp │ │ │ ├── dictionaryStruct.cpp │ │ │ ├── dictionaryTagLink.cpp │ │ │ ├── dictionaryUByte.cpp │ │ │ ├── dictionaryUInt.cpp │ │ │ ├── dictionaryULong.cpp │ │ │ ├── dictionaryUShort.cpp │ │ │ ├── dictionaryUVarint.cpp │ │ │ └── dictionaryVarint.cpp │ │ ├── dicObjectPool.cpp │ │ ├── dictionaryBaseType.cpp │ │ └── usdsDictionary.cpp │ │ ├── usdsBasicParser.cpp │ │ └── usdsTypes.cpp ├── BasicParserCPP.sln ├── Example │ ├── Source │ │ └── UsdsExample.cpp │ ├── UsdsExample.sln │ ├── UsdsExample.vcxproj │ └── UsdsExample.vcxproj.filters └── Performance.psess ├── BenchmarkCPP ├── Benchmark.VC.db ├── Benchmark.sln ├── Benchmark.vcxproj ├── Benchmark.vcxproj.filters ├── Include │ ├── ASN │ │ ├── asnTest.h │ │ └── asn_bench.h │ ├── BSON │ │ └── bsonTest.h │ ├── JSON │ │ └── jsonTest.h │ ├── Protobuf │ │ ├── protobufTest.h │ │ └── protobufTicketSales.h │ ├── USDS Basic │ │ └── usdsBasicTest.h │ ├── USDS DOM │ │ ├── usdsDomParser.h │ │ └── usdsDomTest.h │ ├── USDS │ │ ├── usdsDeserializer.h │ │ ├── usdsSerializer.h │ │ └── usdsTest.h │ ├── XML │ │ ├── tinyxml2.h │ │ └── xmlTest.h │ ├── baseTest.h │ ├── ticketSales.h │ └── usdsBenchmark.h └── Source │ ├── ASN │ ├── asnTest.cpp │ └── asn_bench.cpp │ ├── BSON │ └── bsonTest.cpp │ ├── JSON │ └── jsonTest.cpp │ ├── Protobuf │ ├── protobufTest.cpp │ ├── protobufTicketSales.cpp │ └── protobufTicketSales.proto │ ├── USDS Basic │ └── usdsBasicTest.cpp │ ├── USDS DOM │ ├── usdsDomParser.cpp │ └── usdsDomTest.cpp │ ├── USDS │ ├── usdsDeserializer.cpp │ ├── usdsSerializer.cpp │ └── usdsTest.cpp │ ├── XML │ ├── tinyxml2.cpp │ └── xmlTest.cpp │ ├── baseTest.cpp │ ├── ticketSales.cpp │ └── usdsBenchmark.cpp ├── SaxParser ├── AutotestCPP │ ├── Source │ │ ├── TestSimpleStruct │ │ │ ├── Include │ │ │ │ ├── testSimpleStruct.h │ │ │ │ └── testStruct.h │ │ │ ├── Resource │ │ │ │ └── api.1.0.udic │ │ │ ├── Source │ │ │ │ └── testSimpleStruct.cpp │ │ │ └── usdsAgent.ini │ │ ├── baseTestClass.h │ │ ├── testSaxParser.cpp │ │ └── testSaxParser.h │ ├── testSaxParser.sln │ ├── testSaxParser.vcxproj │ └── testSaxParser.vcxproj.filters └── UsdsAgent │ ├── Include │ ├── CodeReaders │ │ ├── CPPCodeReader │ │ │ └── cppCodeReader.h │ │ └── codeReader.h │ ├── Common │ │ └── fileSearcher.h │ ├── Communication │ │ ├── packer.h │ │ └── sender.h │ ├── Configuration │ │ └── agentConfig.h │ ├── DictionaryReader │ │ └── dictionaryReader.h │ └── usdsAgent.h │ ├── Source │ ├── CodeReaders │ │ ├── CppCodeReader │ │ │ ├── CppTextReader │ │ │ │ ├── bisonCppTextReader.cc │ │ │ │ ├── bisonCppTextReader.hh │ │ │ │ ├── bisonCppTextReader.y │ │ │ │ ├── flexCppTextReader.cpp │ │ │ │ ├── flexCppTextReader.h │ │ │ │ ├── flexCppTextReader.l │ │ │ │ ├── flexLexerCppTextReader.h │ │ │ │ ├── location.hh │ │ │ │ ├── patchFlexAndBison.py │ │ │ │ ├── position.hh │ │ │ │ ├── stack.hh │ │ │ │ └── win_create_reader.bat │ │ │ ├── cppCodeReader.cpp │ │ │ └── usdsCppCodeReader.udic │ │ ├── codeReader.cpp │ │ └── usdsSaxParser.udic │ ├── Common │ │ └── fileSearcher.cpp │ ├── Communication │ │ ├── packer.cpp │ │ └── sender.cpp │ ├── Configuration │ │ └── agentConfig.cpp │ ├── DictionaryReader │ │ └── dictionaryReader.cpp │ └── usdsAgent.cpp │ ├── UsdsAgent.sln │ ├── UsdsAgent.vcxproj │ └── UsdsAgent.vcxproj.filters └── readme.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | usdsCPP/BasicParser/Debug/BasicParser.tlog/unsuccessfulbuild 3 | *.user 4 | *.exe 5 | *.ilk 6 | *.pdb 7 | usdsCPP/BasicParser/Release/BasicParser.tlog/unsuccessfulbuild 8 | *.dll 9 | *.idb 10 | *.obj 11 | *.tlog 12 | *.suo 13 | *.sdf 14 | *.lib 15 | *.opensdf 16 | *.vsp 17 | usdsCPP/usdsCPP.VC.db 18 | UsdsAgent/UsdsAgent.VC.db 19 | UsdsAgent/UsdsAgent/bin/1.txt 20 | UsdsAgent/UsdsAgent/bin/config.ini 21 | UsdsAgent/UsdsAgent/config.ini 22 | *.db 23 | *.db 24 | SaxParser/UsdsAgent/bin/usdsAgent.ini -------------------------------------------------------------------------------- /BasicParserCPP/Autotest/Source/UnitTest/Body/usdsBooleanTest.cpp: -------------------------------------------------------------------------------- 1 | #include "usdsAutotest.h" 2 | 3 | #include "body\dataTypes\usdsBoolean.h" 4 | #include "body\usdsBody.h" 5 | #include "dictionary\dataTypes\dictionaryBoolean.h" 6 | #include "dictionary\usdsDictionary.h" 7 | 8 | void UsdsBooleanTest::test_1() 9 | { 10 | usds::Dictionary dict(0); 11 | dict.setID("name", 1, 0, 0); 12 | usds::Body body; 13 | usds::DictionaryBoolean* dict_boolean = 0; 14 | usds::UsdsBoolean* body_boolean = 0; 15 | 16 | // step 1 17 | dict_boolean = (usds::DictionaryBoolean*)dict.addTag(usds::USDS_BOOLEAN, 1, "boolean", 0); 18 | dict.finalizeDictionary(); 19 | body_boolean = (usds::UsdsBoolean*)body.addTag(dict_boolean); 20 | if (body_boolean->getType() != usds::USDS_BOOLEAN) 21 | { 22 | throw "Failed at the step 1\n"; 23 | } 24 | 25 | // step 2 26 | bool bool_value = true; 27 | try 28 | { 29 | body_boolean->setValue(bool_value); 30 | if (body_boolean->getValue() != true) 31 | throw "Failed at the step 2\n"; 32 | } 33 | catch (...) 34 | { 35 | throw "Failed at the step 2\n"; 36 | } 37 | 38 | // step 3 39 | int32_t int_value = 1000; 40 | try 41 | { 42 | body_boolean->setValue(int_value); 43 | throw "Failed at the step 3\n"; 44 | } 45 | catch (usds::ErrorStack& err) 46 | { 47 | if (err.getCode() != usds::UNSUPPORTED_TYPE_CONVERSION) 48 | { 49 | throw "Failed at the step 3\n"; 50 | } 51 | } 52 | 53 | // step 4 54 | double double_value = 1.25; 55 | try 56 | { 57 | body_boolean->setValue(double_value); 58 | throw "Failed at the step 3\n"; 59 | } 60 | catch (usds::ErrorStack& err) 61 | { 62 | if (err.getCode() != usds::UNSUPPORTED_TYPE_CONVERSION) 63 | { 64 | throw "Failed at the step 3\n"; 65 | } 66 | } 67 | 68 | } 69 | 70 | void UsdsBooleanTest::test_2() 71 | { 72 | usds::Dictionary dict(0); 73 | dict.setID("name", 1, 0, 0); 74 | usds::Body body; 75 | usds::DictionaryBoolean* dict_boolean = 0; 76 | usds::UsdsBoolean* body_boolean = 0; 77 | 78 | // step 1 79 | dict_boolean = (usds::DictionaryBoolean*)dict.addTag(usds::USDS_BOOLEAN, 1, "double", 0); 80 | dict.finalizeDictionary(); 81 | body_boolean = (usds::UsdsBoolean*)body.addTag(dict_boolean); 82 | if (body_boolean->getType() != usds::USDS_BOOLEAN) 83 | { 84 | throw "Failed at the step 1\n"; 85 | }; 86 | 87 | // step 2 88 | body_boolean->setValue(false); 89 | try 90 | { 91 | body_boolean->getValue(); 92 | if (body_boolean->getValue() != false) 93 | throw "Failed at the step 2\n"; 94 | } 95 | catch (...) 96 | { 97 | throw "Failed at the step 2\n"; 98 | } 99 | 100 | // step 3 101 | body_boolean->setValue(false); 102 | try 103 | { 104 | body_boolean->getValue(); 105 | throw "Failed at the step 3\n"; 106 | } 107 | catch (usds::ErrorStack& err) 108 | { 109 | if (err.getCode() != usds::UNSUPPORTED_TYPE_CONVERSION) 110 | { 111 | throw "Failed at the step 3\n"; 112 | } 113 | } 114 | 115 | // step 4 116 | body_boolean->setValue(false); 117 | try 118 | { 119 | body_boolean->getValue(); 120 | throw "Failed at the step 4\n"; 121 | } 122 | catch (usds::ErrorStack& err) 123 | { 124 | if (err.getCode() != usds::UNSUPPORTED_TYPE_CONVERSION) 125 | { 126 | throw "Failed at the step 4\n"; 127 | } 128 | } 129 | 130 | // step 5 131 | body_boolean->setValue(false); 132 | try 133 | { 134 | body_boolean->getValue(); 135 | throw "Failed at the step 5\n"; 136 | } 137 | catch (usds::ErrorStack& err) 138 | { 139 | if (err.getCode() != usds::UNSUPPORTED_TYPE_CONVERSION) 140 | { 141 | throw "Failed at the step 5\n"; 142 | } 143 | } 144 | 145 | 146 | } 147 | 148 | 149 | -------------------------------------------------------------------------------- /BasicParserCPP/Autotest/Source/UnitTest/Converters/Parsers/usdsDictionaryTextParserAttributes.cpp: -------------------------------------------------------------------------------- 1 | #include "usdsAutotest.h" 2 | 3 | #include "converters/usdsDictionaryTextParser.h" 4 | #include "dictionary/usdsDictionary.h" 5 | #include "dictionary/dataTypes/dictionaryString.h" 6 | #include "dictionary/dataTypes/dictionaryEnum.h" 7 | 8 | void DictionaryTextParserTestAttributes::test_1() 9 | { 10 | usds::DictionaryTextParser* parser = new usds::DictionaryTextParser(); 11 | usds::Dictionary dict(0); 12 | 13 | // step 1 14 | const char* text_dict = 15 | "USDS MyLittleAPI 0.1\n\ 16 | ENCODE:UTF-8\n\ 17 | ENUMERATOR : UBYTE\n\ 18 | {\n\ 19 | 1: STRING str1;\n\ 20 | 2: STRING str2;\n\ 21 | 3: ENUM enum1 { v1, v2 };\n\ 22 | 4: ENUM enum2 { v1, v2 };\n\ 23 | }"; 24 | parser->parse(text_dict, usds::USDS_UTF8, &dict); 25 | if (dict.getTagNumber() != 4 || dict.getDictionaryID() != 0 || dict.getMajorVersion() != 0 || dict.getMinorVersion() != 1) 26 | throw "Failed at the step 1\n"; 27 | 28 | // step 2 29 | const char* name = dict.getTag(1)->getName(); 30 | if (strcmp(name, "str1") != 0) 31 | throw "Failed at the step 2\n"; 32 | if (dict.getTag(1)->getType() != usds::USDS_STRING) 33 | throw "Failed at the step 2\n"; 34 | if (((usds::DictionaryString*)dict.getTag(1))->getDefaultEncode() != usds::USDS_UTF8) 35 | throw "Failed at the step 2\n"; 36 | 37 | // step 3 38 | name = dict.getTag(2)->getName(); 39 | if (strcmp(name, "str2") != 0) 40 | throw "Failed at the step 3\n"; 41 | if (dict.getTag(2)->getType() != usds::USDS_STRING) 42 | throw "Failed at the step 3\n"; 43 | if (((usds::DictionaryString*)dict.getTag(2))->getDefaultEncode() != usds::USDS_UTF8) 44 | throw "Failed at the step 3\n"; 45 | 46 | // step 4 47 | name = dict.getTag(3)->getName(); 48 | if (strcmp(name, "enum1") != 0) 49 | throw "Failed at the step 4\n"; 50 | if (dict.getTag(3)->getType() != usds::USDS_ENUM) 51 | throw "Failed at the step 4\n"; 52 | if (((usds::DictionaryEnum*)dict.getTag(3))->getSubtype() != usds::USDS_UBYTE) 53 | throw "Failed at the step 4\n"; 54 | 55 | // step 5 56 | name = dict.getTag(4)->getName(); 57 | if (strcmp(name, "enum2") != 0) 58 | throw "Failed at the step 5\n"; 59 | if (dict.getTag(4)->getType() != usds::USDS_ENUM) 60 | throw "Failed at the step 5\n"; 61 | if (((usds::DictionaryEnum*)dict.getTag(4))->getSubtype() != usds::USDS_SHORT) 62 | throw "Failed at the step 5\n"; 63 | 64 | } -------------------------------------------------------------------------------- /BasicParserCPP/Autotest/Source/UnitTest/Dictionary/dictionaryStringTest.cpp: -------------------------------------------------------------------------------- 1 | #include "usdsAutotest.h" 2 | 3 | #include "dictionary\dataTypes\dictionaryString.h" 4 | 5 | void DictionaryStringTest::test_1() 6 | { 7 | // step 1 8 | 9 | usds::DictionaryString object(0); 10 | if (object.getType() != usds::USDS_STRING) 11 | { 12 | throw "Failed at the step 1\n"; 13 | } 14 | 15 | // step 2 16 | 17 | object.initType(0, 1, "string", 0); 18 | if (object.getDefaultEncode() != usds::USDS_NO_DEFAULT_ENCODE) 19 | { 20 | throw "Failed at the step 2\n"; 21 | } 22 | 23 | // step 3 24 | 25 | object.setDefaultEncode(usds::USDS_UTF8); 26 | if (object.getDefaultEncode() != usds::USDS_UTF8) 27 | { 28 | throw "Failed at the step 3\n"; 29 | } 30 | 31 | // step 4 32 | try 33 | { 34 | object.finalize(); 35 | } 36 | catch (usds::ErrorStack) 37 | { 38 | throw "Failed at the step 4\n"; 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /BasicParserCPP/Autotest/Source/UnitTest/Dictionary/dictionaryTagLinkTest.cpp: -------------------------------------------------------------------------------- 1 | #include "usdsAutotest.h" 2 | 3 | #include "dictionary\usdsDictionary.h" 4 | #include "dictionary\dataTypes\dictionaryTagLink.h" 5 | 6 | void DictionaryTagLinkTest::test_1() 7 | { 8 | usds::Dictionary dict(0); 9 | dict.setID("name", 1, 0, 0); 10 | usds::DictionaryTagLink* object = (usds::DictionaryTagLink*)dict.addField(usds::USDS_TAG, 0, 1, "tag_link", 0); 11 | 12 | // step 1 13 | 14 | try 15 | { 16 | object->finalize(); 17 | throw "Failed at the step 1\n"; 18 | 19 | 20 | } 21 | catch (usds::ErrorStack& err) 22 | { 23 | if (err.getCode() != usds::DIC_TAG_LINK__NOT_INITIALIZED) 24 | { 25 | throw "Failed at the step 1\n"; 26 | 27 | } 28 | } 29 | 30 | // step 2 31 | 32 | dict.addTag(usds::USDS_INT, 1, "int", 0); 33 | dict.finalizeDictionary(); 34 | try 35 | { 36 | object->setTag(2); 37 | object->finalize(); 38 | throw "Failed at the step 2\n"; 39 | 40 | 41 | } 42 | catch (usds::ErrorStack& err) 43 | { 44 | if (err.getCode() != usds::DICTIONARY__TAG_ID_ERROR_VALUE) 45 | { 46 | throw "Failed at the step 2\n"; 47 | 48 | } 49 | } 50 | 51 | // step 3 52 | 53 | try 54 | { 55 | object->setTag("array", 0); 56 | object->finalize(); 57 | throw "Failed at the step 3\n"; 58 | 59 | 60 | } 61 | catch (usds::ErrorStack& err) 62 | { 63 | if (err.getCode() != usds::DIC_TAG_LINK__TAG_NOT_FOUND) 64 | { 65 | throw "Failed at the step 3\n"; 66 | 67 | } 68 | } 69 | 70 | } 71 | 72 | void DictionaryTagLinkTest::test_2() 73 | { 74 | usds::Dictionary dict(0); 75 | dict.setID("name", 1, 0, 0); 76 | usds::DictionaryTagLink* object = (usds::DictionaryTagLink*)dict.addField(usds::USDS_TAG, 0, 1, "tag_link", 0); 77 | dict.addTag(usds::USDS_INT, 1, "int", 0); 78 | dict.finalizeDictionary(); 79 | 80 | // step 1 81 | 82 | try 83 | { 84 | object->setTag(0); 85 | throw "Failed at the step 1\n"; 86 | 87 | 88 | } 89 | catch (usds::ErrorStack& err) 90 | { 91 | if (err.getCode() != usds::DIC_TAG_LINK__ERROR_ELEMENT_ID) 92 | { 93 | throw "Failed at the step 1\n"; 94 | 95 | } 96 | } 97 | 98 | // step 2 99 | 100 | try 101 | { 102 | object->setTag(1); 103 | object->finalize(); 104 | } 105 | catch (usds::ErrorStack) 106 | { 107 | throw "Failed at the step 2\n"; 108 | 109 | } 110 | 111 | // step 3 112 | 113 | try 114 | { 115 | if(strcmp(object->getTag()->getName(), "int") != 0) 116 | throw "Failed at the step 3\n"; 117 | } 118 | catch (usds::ErrorStack) 119 | { 120 | throw "Failed at the step 3\n"; 121 | 122 | } 123 | 124 | } 125 | 126 | void DictionaryTagLinkTest::test_3() 127 | { 128 | usds::Dictionary dict(0); 129 | dict.setID("name", 1, 0, 0); 130 | usds::DictionaryTagLink* object = (usds::DictionaryTagLink*)dict.addField(usds::USDS_TAG, 0, 1, "tag_link", 0); 131 | dict.addTag(usds::USDS_INT, 1, "int", 0); 132 | dict.finalizeDictionary(); 133 | 134 | // step 1 135 | 136 | try 137 | { 138 | object->setTag(0, 0); 139 | throw "Failed at the step 1\n"; 140 | 141 | 142 | } 143 | catch (usds::ErrorStack& err) 144 | { 145 | if (err.getCode() != usds::DIC_TAG_LINK__ERROR_ELEMENT_NAME) 146 | { 147 | throw "Failed at the step 1\n"; 148 | 149 | } 150 | } 151 | 152 | // step 2 153 | 154 | try 155 | { 156 | object->setTag("int", 0); 157 | object->finalize(); 158 | } 159 | catch (usds::ErrorStack) 160 | { 161 | throw "Failed at the step 2\n"; 162 | 163 | } 164 | 165 | // step 3 166 | 167 | try 168 | { 169 | if (object->getTag()->getID() != 1) 170 | throw "Failed at the step 3\n"; 171 | } 172 | catch (usds::ErrorStack) 173 | { 174 | throw "Failed at the step 3\n"; 175 | 176 | } 177 | 178 | } -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/binary/usdsBinaryInput.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_BINARY_INPUT_H 2 | #define USDS_BINARY_INPUT_H 3 | 4 | #include "common\errorMessage.h" 5 | 6 | namespace usds 7 | { 8 | enum binaryInputErrorCodes 9 | { 10 | BIN_IN__NULL_BUFF = 21, 11 | BIN_IN__NULL_SIZE = 22, 12 | BIN_IN__BUFF_OVERFLOW = 23, 13 | BIN_IN__BEEG_UVARINT = 24, 14 | BIN_IN__UVARINT_ERROR_FORMAT = 25, 15 | BIN_IN__BOOLEAN_ERROR_FORMAT = 26, 16 | BIN_IN__VARINT_ERROR_FORMAT = 27 17 | }; 18 | 19 | class BinaryInput 20 | { 21 | public: 22 | BinaryInput(); 23 | ~BinaryInput(); 24 | 25 | void setBinary(const uint8_t* buff, size_t size) throw(...); 26 | 27 | void clear(); // it does not release memory in buffer 28 | 29 | // deserialization 30 | bool readBool() throw(...); 31 | int8_t readByte() throw(...); 32 | uint8_t readUByte() throw(...); 33 | int16_t readShort() throw(...); 34 | uint16_t readUShort() throw(...); 35 | int32_t readInt() throw(...); 36 | uint32_t readUInt() throw(...); 37 | int64_t readLong() throw(...); 38 | uint64_t readULong() throw(...); 39 | float readFloat() throw(...); 40 | double readDouble() throw(...); 41 | 42 | size_t readVarint(int64_t* value) throw(...); 43 | 44 | size_t readUVarint(uint64_t* value) throw(...); 45 | size_t readUVarint(uint32_t* value) throw(...); 46 | size_t readUVarint(int32_t* value) throw(...); 47 | 48 | void readByteArray(void* buff, size_t size) throw(...); 49 | const void* readByteArray(size_t size) throw(...); 50 | 51 | void stepBack(size_t size) throw(...); 52 | void stepForward(size_t size) throw(...); 53 | 54 | bool isEnd() throw(...); 55 | const uint8_t* getCurrentPosition() throw(...); 56 | const uint8_t* getFirstPosition() throw(...); 57 | size_t getSize() throw(...); 58 | 59 | private: 60 | // Buffer for USDS input document 61 | const uint8_t* usdsBuff; 62 | const uint8_t* buffLastPos; // It is a position after last valid position in the Buffer. The Buffer size is buff_last_pos - usds_buff 63 | const uint8_t* buffCurrentPos; // Last unread position in the Buffer. The document size is buff_current_pos - usds_buff 64 | 65 | }; 66 | }; 67 | 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/body/bodyObjectPool.h: -------------------------------------------------------------------------------- 1 | #ifndef BODY_OBJECT_POOL_H 2 | #define BODY_OBJECT_POOL_H 3 | 4 | #include "usdsErrors.h" 5 | #include "usdsTypes.h" 6 | #include "common\objectPool.h" 7 | 8 | namespace usds 9 | { 10 | class UsdsBaseType; 11 | class DictionaryBaseType; 12 | class Body; 13 | 14 | class BodyObjectPool 15 | { 16 | public: 17 | BodyObjectPool(Body* parent_body); 18 | ~BodyObjectPool(); 19 | 20 | UsdsBaseType* addObject(DictionaryBaseType* dict_parent, UsdsBaseType* body_parent) throw(...); 21 | 22 | // Clear pool, it does not release memory 23 | void clear(); 24 | 25 | 26 | private: 27 | 28 | // Pool of objects 29 | BasePoolClass* pools[USDS_LAST_TYPE]; 30 | 31 | }; 32 | 33 | } 34 | 35 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/body/dataTypes/usdsBoolean.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_BOOLEAN_H 2 | #define USDS_BOOLEAN_H 3 | 4 | #include "body\usdsBaseType.h" 5 | 6 | namespace usds 7 | { 8 | class UsdsBoolean : public UsdsBaseType 9 | { 10 | public: 11 | UsdsBoolean(Body* parent_body); 12 | virtual ~UsdsBoolean(); 13 | 14 | usdsType getType() { return USDS_BOOLEAN; }; 15 | const char* getTypeName() { return "BOOLEAN"; }; 16 | 17 | // Slow methods (virtual) 18 | void setValue(bool value) throw (...); 19 | 20 | using UsdsBaseType::setValue; 21 | 22 | void getValue(bool* value) throw (...); 23 | 24 | using UsdsBaseType::getValue; 25 | 26 | // Fast methods (not virtual) 27 | bool get(); 28 | void set(bool value); 29 | 30 | private: 31 | 32 | void additionalInitObject(); 33 | 34 | bool objectValue; 35 | 36 | }; 37 | 38 | } 39 | 40 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/body/dataTypes/usdsByte.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_BYTE_H 2 | #define USDS_BYTE_H 3 | 4 | #include "body\usdsBaseType.h" 5 | 6 | namespace usds 7 | { 8 | class UsdsByte : public UsdsBaseType 9 | { 10 | public: 11 | UsdsByte(Body* parent_body); 12 | virtual ~UsdsByte(); 13 | 14 | usdsType getType() { return USDS_BYTE; }; 15 | const char* getTypeName() { return "BYTE"; }; 16 | 17 | // Slow methods (virtual) 18 | void setValue(int8_t value) throw (...); 19 | void setValue(uint8_t value) throw (...); 20 | void setValue(int16_t value) throw (...); 21 | void setValue(uint16_t value) throw (...); 22 | void setValue(int32_t value) throw (...); 23 | void setValue(uint32_t value) throw (...); 24 | void setValue(int64_t value) throw (...); 25 | void setValue(uint64_t value) throw (...); 26 | 27 | using UsdsBaseType::setValue; 28 | 29 | void getValue(int8_t* value) throw (...); 30 | void getValue(uint8_t* value) throw (...); 31 | void getValue(int16_t* value) throw (...); 32 | void getValue(uint16_t* value) throw (...); 33 | void getValue(int32_t* value) throw (...); 34 | void getValue(uint32_t* value) throw (...); 35 | void getValue(int64_t* value) throw (...); 36 | void getValue(uint64_t* value) throw (...); 37 | 38 | using UsdsBaseType::getValue; 39 | 40 | 41 | // Fast methods (not virtual) 42 | int8_t get(); 43 | void set(int8_t value); 44 | 45 | private: 46 | 47 | void additionalInitObject(); 48 | 49 | int8_t objectValue; 50 | 51 | }; 52 | 53 | 54 | } 55 | 56 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/body/dataTypes/usdsDouble.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_DOUBLE_H 2 | #define USDS_DOUBLE_H 3 | 4 | #include "body\usdsBaseType.h" 5 | 6 | namespace usds 7 | { 8 | class UsdsDouble : public UsdsBaseType 9 | { 10 | public: 11 | UsdsDouble(Body* parent_body); 12 | virtual ~UsdsDouble(); 13 | 14 | usdsType getType() { return USDS_DOUBLE; }; 15 | const char* getTypeName() { return "DOUBLE"; }; 16 | 17 | // Slow methods (virtual) 18 | void setValue(float value) throw (...); 19 | void setValue(double value) throw (...); 20 | 21 | using UsdsBaseType::setValue; 22 | 23 | void getValue(double* value) throw (...); 24 | 25 | using UsdsBaseType::getValue; 26 | 27 | // Fast methods (not virtual) 28 | double get(); 29 | void set(double value); 30 | 31 | bool isBigendian(); 32 | 33 | private: 34 | 35 | void additionalInitObject(); 36 | 37 | double objectValue; 38 | 39 | }; 40 | 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/body/dataTypes/usdsEnum.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_ENUM_H 2 | #define USDS_ENUM_H 3 | 4 | #include "body\usdsBaseType.h" 5 | 6 | namespace usds 7 | { 8 | class UsdsEnum : public UsdsBaseType 9 | { 10 | public: 11 | UsdsEnum(Body* parent_body); 12 | virtual ~UsdsEnum(); 13 | 14 | usdsType getType() { return USDS_ENUM; }; 15 | const char* getTypeName() { return "ENUM"; }; 16 | 17 | usdsType getSubtype(); 18 | bool isSubtypeBigendian(); 19 | 20 | // Slow methods (virtual) 21 | void setValue(int8_t value) throw (...); 22 | void setValue(uint8_t value) throw (...); 23 | void setValue(int16_t value) throw (...); 24 | void setValue(uint16_t value) throw (...); 25 | void setValue(int32_t value) throw (...); 26 | void setValue(uint32_t value) throw (...); 27 | void setValue(int64_t value) throw (...); 28 | void setValue(uint64_t value) throw (...); 29 | 30 | using UsdsBaseType::setValue; 31 | 32 | void getValue(int8_t* value) throw (...); 33 | void getValue(uint8_t* value) throw (...); 34 | void getValue(int16_t* value) throw (...); 35 | void getValue(uint16_t* value) throw (...); 36 | void getValue(int32_t* value) throw (...); 37 | void getValue(uint32_t* value) throw (...); 38 | void getValue(int64_t* value) throw (...); 39 | void getValue(uint64_t* value) throw (...); 40 | 41 | using UsdsBaseType::getValue; 42 | 43 | // Fast methods (not virtual) 44 | int64_t get(); 45 | void set(int64_t value); 46 | 47 | void setFromUTF8(const char* name) throw (...); 48 | void setFromUTF8(const char* name, size_t byte_size) throw (...); 49 | 50 | const char* getUTF8Value() throw (...); 51 | const char* getUTF8Value(size_t* byte_size) throw (...); 52 | 53 | private: 54 | 55 | void additionalInitObject(); 56 | 57 | int64_t objectValue; 58 | 59 | usdsType subType; 60 | 61 | }; 62 | 63 | } 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/body/dataTypes/usdsFloat.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_FLOAT_H 2 | #define USDS_FLOAT_H 3 | 4 | #include "body\usdsBaseType.h" 5 | 6 | namespace usds 7 | { 8 | class UsdsFloat : public UsdsBaseType 9 | { 10 | public: 11 | UsdsFloat(Body* parent_body); 12 | virtual ~UsdsFloat(); 13 | 14 | usdsType getType() { return USDS_FLOAT; }; 15 | const char* getTypeName() { return "FLOAT"; }; 16 | 17 | // Slow methods (virtual) 18 | void setValue(float value) throw (...); 19 | 20 | using UsdsBaseType::setValue; 21 | 22 | void getValue(float* value) throw (...); 23 | void getValue(double* value) throw (...); 24 | 25 | using UsdsBaseType::getValue; 26 | 27 | 28 | // Fast methods (not virtual) 29 | float get(); 30 | void set(float value); 31 | 32 | bool isBigendian(); 33 | 34 | private: 35 | 36 | void additionalInitObject(); 37 | 38 | float objectValue; 39 | 40 | }; 41 | 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/body/dataTypes/usdsInt.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_INT_H 2 | #define USDS_INT_H 3 | 4 | #include "body\usdsBaseType.h" 5 | 6 | namespace usds 7 | { 8 | class UsdsInt : public UsdsBaseType 9 | { 10 | public: 11 | UsdsInt(Body* parent_body); 12 | virtual ~UsdsInt(); 13 | 14 | usdsType getType() { return USDS_INT; }; 15 | const char* getTypeName() { return "INT"; }; 16 | 17 | // Slow methods (virtual) 18 | void setValue(int8_t value) throw (...); 19 | void setValue(uint8_t value) throw (...); 20 | void setValue(int16_t value) throw (...); 21 | void setValue(uint16_t value) throw (...); 22 | void setValue(int32_t value) throw (...); 23 | void setValue(uint32_t value) throw (...); 24 | void setValue(int64_t value) throw (...); 25 | void setValue(uint64_t value) throw (...); 26 | 27 | using UsdsBaseType::setValue; 28 | 29 | void getValue(int8_t* value) throw (...); 30 | void getValue(uint8_t* value) throw (...); 31 | void getValue(int16_t* value) throw (...); 32 | void getValue(uint16_t* value) throw (...); 33 | void getValue(int32_t* value) throw (...); 34 | void getValue(uint32_t* value) throw (...); 35 | void getValue(int64_t* value) throw (...); 36 | void getValue(uint64_t* value) throw (...); 37 | 38 | using UsdsBaseType::getValue; 39 | 40 | 41 | // Fast methods (not virtual) 42 | int32_t get(); 43 | void set(int32_t value); 44 | 45 | bool isBigendian(); 46 | 47 | private: 48 | 49 | void additionalInitObject(); 50 | 51 | int32_t objectValue; 52 | 53 | }; 54 | 55 | 56 | } 57 | 58 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/body/dataTypes/usdsLong.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_LONG_H 2 | #define USDS_LONG_H 3 | 4 | #include "body\usdsBaseType.h" 5 | 6 | namespace usds 7 | { 8 | class UsdsLong : public UsdsBaseType 9 | { 10 | public: 11 | UsdsLong(Body* parent_body); 12 | virtual ~UsdsLong(); 13 | 14 | usdsType getType() { return USDS_LONG; }; 15 | const char* getTypeName() { return "LONG"; }; 16 | 17 | // Slow methods (virtual) 18 | void setValue(int8_t value) throw (...); 19 | void setValue(uint8_t value) throw (...); 20 | void setValue(int16_t value) throw (...); 21 | void setValue(uint16_t value) throw (...); 22 | void setValue(int32_t value) throw (...); 23 | void setValue(uint32_t value) throw (...); 24 | void setValue(int64_t value) throw (...); 25 | void setValue(uint64_t value) throw (...); 26 | 27 | using UsdsBaseType::setValue; 28 | 29 | void getValue(int8_t* value) throw (...); 30 | void getValue(uint8_t* value) throw (...); 31 | void getValue(int16_t* value) throw (...); 32 | void getValue(uint16_t* value) throw (...); 33 | void getValue(int32_t* value) throw (...); 34 | void getValue(uint32_t* value) throw (...); 35 | void getValue(int64_t* value) throw (...); 36 | void getValue(uint64_t* value) throw (...); 37 | 38 | using UsdsBaseType::getValue; 39 | 40 | 41 | // Fast methods (not virtual) 42 | int64_t get(); 43 | void set(int64_t value); 44 | 45 | bool isBigendian(); 46 | 47 | private: 48 | 49 | void additionalInitObject(); 50 | 51 | int64_t objectValue; 52 | 53 | }; 54 | 55 | } 56 | 57 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/body/dataTypes/usdsShort.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_SHORT_H 2 | #define USDS_SHORT_H 3 | 4 | #include "body\usdsBaseType.h" 5 | 6 | namespace usds 7 | { 8 | class UsdsShort : public UsdsBaseType 9 | { 10 | public: 11 | UsdsShort(Body* parent_body); 12 | virtual ~UsdsShort(); 13 | 14 | usdsType getType() { return USDS_SHORT; }; 15 | const char* getTypeName() { return "SHORT"; }; 16 | 17 | // Slow methods (virtual) 18 | void setValue(int8_t value) throw (...); 19 | void setValue(uint8_t value) throw (...); 20 | void setValue(int16_t value) throw (...); 21 | void setValue(uint16_t value) throw (...); 22 | void setValue(int32_t value) throw (...); 23 | void setValue(uint32_t value) throw (...); 24 | void setValue(int64_t value) throw (...); 25 | void setValue(uint64_t value) throw (...); 26 | 27 | using UsdsBaseType::setValue; 28 | 29 | void getValue(int8_t* value) throw (...); 30 | void getValue(uint8_t* value) throw (...); 31 | void getValue(int16_t* value) throw (...); 32 | void getValue(uint16_t* value) throw (...); 33 | void getValue(int32_t* value) throw (...); 34 | void getValue(uint32_t* value) throw (...); 35 | void getValue(int64_t* value) throw (...); 36 | void getValue(uint64_t* value) throw (...); 37 | 38 | using UsdsBaseType::getValue; 39 | 40 | 41 | // Fast methods (not virtual) 42 | int16_t get(); 43 | void set(int16_t value); 44 | 45 | bool isBigendian(); 46 | 47 | private: 48 | 49 | void additionalInitObject(); 50 | 51 | int16_t objectValue; 52 | 53 | }; 54 | 55 | 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/body/dataTypes/usdsString.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_STRING_H 2 | #define USDS_STRING_H 3 | 4 | #include "body\usdsBaseType.h" 5 | 6 | namespace usds 7 | { 8 | class UsdsString : public UsdsBaseType 9 | { 10 | public: 11 | UsdsString(Body* parent_body); 12 | virtual ~UsdsString(); 13 | 14 | usdsType getType() { return USDS_STRING; }; 15 | const char* getTypeName() { return "STRING"; }; 16 | 17 | void setEncode(usdsEncode encode) throw(...); 18 | usdsEncode getEncode() throw(...); 19 | 20 | void setFromUTF8(const char* value) throw (...); 21 | void setFromUTF8(const char* value, size_t byte_size) throw (...); 22 | 23 | const char* getUTF8Value() throw (...); 24 | const char* getUTF8Value(size_t* byte_size) throw (...); 25 | 26 | // For binary body parser 27 | const uint8_t* getByteValue() throw (...); 28 | size_t getByteSize() throw (...); 29 | 30 | uint8_t* reserveBinaryForValue(size_t byte_size); 31 | 32 | private: 33 | 34 | void additionalInitObject() throw (...); 35 | 36 | usdsEncode textEncode; 37 | 38 | uint8_t* objectValue; 39 | size_t valueSize; 40 | size_t valueBufferSize; 41 | 42 | 43 | }; 44 | 45 | } 46 | 47 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/body/dataTypes/usdsUByte.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_UBYTE_H 2 | #define USDS_UBYTE_H 3 | 4 | #include "body\usdsBaseType.h" 5 | 6 | namespace usds 7 | { 8 | class UsdsUByte : public UsdsBaseType 9 | { 10 | public: 11 | UsdsUByte(Body* parent_body); 12 | virtual ~UsdsUByte(); 13 | 14 | usdsType getType() { return USDS_UBYTE; }; 15 | const char* getTypeName() { return "UBYTE"; }; 16 | 17 | // Slow methods (virtual) 18 | void setValue(int8_t value) throw (...); 19 | void setValue(uint8_t value) throw (...); 20 | void setValue(int16_t value) throw (...); 21 | void setValue(uint16_t value) throw (...); 22 | void setValue(int32_t value) throw (...); 23 | void setValue(uint32_t value) throw (...); 24 | void setValue(int64_t value) throw (...); 25 | void setValue(uint64_t value) throw (...); 26 | 27 | using UsdsBaseType::setValue; 28 | 29 | void getValue(int8_t* value) throw (...); 30 | void getValue(uint8_t* value) throw (...); 31 | void getValue(int16_t* value) throw (...); 32 | void getValue(uint16_t* value) throw (...); 33 | void getValue(int32_t* value) throw (...); 34 | void getValue(uint32_t* value) throw (...); 35 | void getValue(int64_t* value) throw (...); 36 | void getValue(uint64_t* value) throw (...); 37 | 38 | using UsdsBaseType::getValue; 39 | 40 | // Fast methods (not virtual) 41 | uint8_t get() throw (...); 42 | void set(uint8_t value) throw (...); 43 | 44 | private: 45 | 46 | void additionalInitObject(); 47 | 48 | uint8_t objectValue; 49 | 50 | }; 51 | 52 | 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/body/dataTypes/usdsUInt.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_UINT_H 2 | #define USDS_UINT_H 3 | 4 | #include "body\usdsBaseType.h" 5 | 6 | namespace usds 7 | { 8 | class UsdsUInt : public UsdsBaseType 9 | { 10 | public: 11 | UsdsUInt(Body* parent_body); 12 | virtual ~UsdsUInt(); 13 | 14 | usdsType getType() { return USDS_UINT; }; 15 | const char* getTypeName() { return "UINT"; }; 16 | 17 | // Slow methods (virtual) 18 | void setValue(int8_t value) throw (...); 19 | void setValue(uint8_t value) throw (...); 20 | void setValue(int16_t value) throw (...); 21 | void setValue(uint16_t value) throw (...); 22 | void setValue(int32_t value) throw (...); 23 | void setValue(uint32_t value) throw (...); 24 | void setValue(int64_t value) throw (...); 25 | void setValue(uint64_t value) throw (...); 26 | 27 | using UsdsBaseType::setValue; 28 | 29 | void getValue(int8_t* value) throw (...); 30 | void getValue(uint8_t* value) throw (...); 31 | void getValue(int16_t* value) throw (...); 32 | void getValue(uint16_t* value) throw (...); 33 | void getValue(int32_t* value) throw (...); 34 | void getValue(uint32_t* value) throw (...); 35 | void getValue(int64_t* value) throw (...); 36 | void getValue(uint64_t* value) throw (...); 37 | 38 | using UsdsBaseType::getValue; 39 | 40 | // Fast methods (not virtual) 41 | uint32_t get(); 42 | void set(uint32_t value); 43 | 44 | bool isBigendian(); 45 | 46 | private: 47 | 48 | void additionalInitObject(); 49 | 50 | uint32_t objectValue; 51 | 52 | }; 53 | 54 | 55 | } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/body/dataTypes/usdsULong.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_ULONG_H 2 | #define USDS_ULONG_H 3 | 4 | #include "body\usdsBaseType.h" 5 | 6 | namespace usds 7 | { 8 | class UsdsULong : public UsdsBaseType 9 | { 10 | public: 11 | UsdsULong(Body* parent_body); 12 | virtual ~UsdsULong(); 13 | 14 | usdsType getType() { return USDS_ULONG; }; 15 | const char* getTypeName() { return "ULONG"; }; 16 | 17 | // Slow methods (virtual) 18 | void setValue(int8_t value) throw (...); 19 | void setValue(uint8_t value) throw (...); 20 | void setValue(int16_t value) throw (...); 21 | void setValue(uint16_t value) throw (...); 22 | void setValue(int32_t value) throw (...); 23 | void setValue(uint32_t value) throw (...); 24 | void setValue(int64_t value) throw (...); 25 | void setValue(uint64_t value) throw (...); 26 | 27 | using UsdsBaseType::setValue; 28 | 29 | void getValue(int8_t* value) throw (...); 30 | void getValue(uint8_t* value) throw (...); 31 | void getValue(int16_t* value) throw (...); 32 | void getValue(uint16_t* value) throw (...); 33 | void getValue(int32_t* value) throw (...); 34 | void getValue(uint32_t* value) throw (...); 35 | void getValue(int64_t* value) throw (...); 36 | void getValue(uint64_t* value) throw (...); 37 | 38 | using UsdsBaseType::getValue; 39 | 40 | 41 | // Fast methods (not virtual) 42 | uint64_t get(); 43 | void set(uint64_t value); 44 | 45 | bool isBigendian(); 46 | 47 | private: 48 | 49 | void additionalInitObject(); 50 | 51 | uint64_t objectValue; 52 | 53 | }; 54 | 55 | } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/body/dataTypes/usdsUShort.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_USHORT_H 2 | #define USDS_USHORT_H 3 | 4 | #include "body\usdsBaseType.h" 5 | 6 | namespace usds 7 | { 8 | class UsdsUShort : public UsdsBaseType 9 | { 10 | public: 11 | UsdsUShort(Body* parent_body); 12 | virtual ~UsdsUShort(); 13 | 14 | usdsType getType() { return USDS_USHORT; }; 15 | const char* getTypeName() { return "USHORT"; }; 16 | 17 | // Slow methods (virtual) 18 | void setValue(int8_t value) throw (...); 19 | void setValue(uint8_t value) throw (...); 20 | void setValue(int16_t value) throw (...); 21 | void setValue(uint16_t value) throw (...); 22 | void setValue(int32_t value) throw (...); 23 | void setValue(uint32_t value) throw (...); 24 | void setValue(int64_t value) throw (...); 25 | void setValue(uint64_t value) throw (...); 26 | 27 | using UsdsBaseType::setValue; 28 | 29 | void getValue(int8_t* value) throw (...); 30 | void getValue(uint8_t* value) throw (...); 31 | void getValue(int16_t* value) throw (...); 32 | void getValue(uint16_t* value) throw (...); 33 | void getValue(int32_t* value) throw (...); 34 | void getValue(uint32_t* value) throw (...); 35 | void getValue(int64_t* value) throw (...); 36 | void getValue(uint64_t* value) throw (...); 37 | 38 | using UsdsBaseType::getValue; 39 | 40 | 41 | // Fast methods (not virtual) 42 | uint16_t get(); 43 | void set(uint16_t value); 44 | 45 | bool isBigendian(); 46 | 47 | private: 48 | 49 | void additionalInitObject(); 50 | 51 | uint16_t objectValue; 52 | 53 | }; 54 | 55 | 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/body/dataTypes/usdsUVarint.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_UVARINT_H 2 | #define USDS_UVARINT_H 3 | 4 | #include "body\usdsBaseType.h" 5 | 6 | namespace usds 7 | { 8 | class UsdsUVarint : public UsdsBaseType 9 | { 10 | public: 11 | UsdsUVarint(Body* parent_body); 12 | virtual ~UsdsUVarint(); 13 | 14 | usdsType getType() { return USDS_UVARINT; }; 15 | const char* getTypeName() { return "UVARINT"; }; 16 | 17 | // Slow methods (virtual) 18 | void setValue(int8_t value) throw (...); 19 | void setValue(uint8_t value) throw (...); 20 | void setValue(int16_t value) throw (...); 21 | void setValue(uint16_t value) throw (...); 22 | void setValue(int32_t value) throw (...); 23 | void setValue(uint32_t value) throw (...); 24 | void setValue(int64_t value) throw (...); 25 | void setValue(uint64_t value) throw (...); 26 | 27 | using UsdsBaseType::setValue; 28 | 29 | void getValue(int8_t* value) throw (...); 30 | void getValue(uint8_t* value) throw (...); 31 | void getValue(int16_t* value) throw (...); 32 | void getValue(uint16_t* value) throw (...); 33 | void getValue(int32_t* value) throw (...); 34 | void getValue(uint32_t* value) throw (...); 35 | void getValue(int64_t* value) throw (...); 36 | void getValue(uint64_t* value) throw (...); 37 | 38 | using UsdsBaseType::getValue; 39 | 40 | // Fast methods (not virtual) 41 | uint64_t get(); 42 | void set(uint64_t value); 43 | 44 | 45 | private: 46 | 47 | void additionalInitObject(); 48 | 49 | uint64_t objectValue; 50 | 51 | 52 | }; 53 | 54 | } 55 | 56 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/body/dataTypes/usdsVarint.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_VARINT_H 2 | #define USDS_VARINT_H 3 | 4 | #include "body\usdsBaseType.h" 5 | 6 | namespace usds 7 | { 8 | class UsdsVarint : public UsdsBaseType 9 | { 10 | public: 11 | UsdsVarint(Body* parent_body); 12 | virtual ~UsdsVarint(); 13 | 14 | usdsType getType() { return USDS_VARINT; }; 15 | const char* getTypeName() { return "VARINT"; }; 16 | 17 | // Slow methods (virtual) 18 | void setValue(int8_t value) throw (...); 19 | void setValue(uint8_t value) throw (...); 20 | void setValue(int16_t value) throw (...); 21 | void setValue(uint16_t value) throw (...); 22 | void setValue(int32_t value) throw (...); 23 | void setValue(uint32_t value) throw (...); 24 | void setValue(int64_t value) throw (...); 25 | void setValue(uint64_t value) throw (...); 26 | 27 | using UsdsBaseType::setValue; 28 | 29 | void getValue(int8_t* value) throw (...); 30 | void getValue(uint8_t* value) throw (...); 31 | void getValue(int16_t* value) throw (...); 32 | void getValue(uint16_t* value) throw (...); 33 | void getValue(int32_t* value) throw (...); 34 | void getValue(uint32_t* value) throw (...); 35 | void getValue(int64_t* value) throw (...); 36 | void getValue(uint64_t* value) throw (...); 37 | 38 | using UsdsBaseType::getValue; 39 | 40 | 41 | // Fast methods (not virtual) 42 | int64_t get(); 43 | void set(int64_t value); 44 | 45 | private: 46 | 47 | void additionalInitObject(); 48 | 49 | int64_t objectValue; 50 | 51 | }; 52 | 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/body/usdsBaseType.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_BASE_TYPE_H 2 | #define USDS_BASE_TYPE_H 3 | 4 | #include "usdsErrors.h" 5 | #include "usdsTypes.h" 6 | #include "common\objectPool.h" 7 | 8 | #include "binary\usdsTypeConverter.h" 9 | 10 | namespace usds 11 | { 12 | class DictionaryBaseType; 13 | class UsdsBaseType; 14 | class Body; 15 | 16 | class UsdsBaseType : public BasePoolObject 17 | { 18 | public: 19 | UsdsBaseType(Body* parent_body); 20 | virtual ~UsdsBaseType(); 21 | 22 | const char* getName() throw(...); 23 | size_t getNameSize() throw(...); 24 | int32_t getID() throw(...); 25 | 26 | virtual usdsType getType() = 0; 27 | virtual const char* getTypeName() = 0; 28 | 29 | virtual void setValue(bool value) throw (...); 30 | virtual void setValue(int8_t value) throw (...); 31 | virtual void setValue(uint8_t value) throw (...); 32 | virtual void setValue(int16_t value) throw (...); 33 | virtual void setValue(uint16_t value) throw (...); 34 | virtual void setValue(int32_t value) throw (...); 35 | virtual void setValue(uint32_t value) throw (...); 36 | virtual void setValue(int64_t value) throw (...); 37 | virtual void setValue(uint64_t value) throw (...); 38 | virtual void setValue(float value) throw (...); 39 | virtual void setValue(double value) throw (...); 40 | 41 | virtual void getValue(bool* value) throw (...); 42 | virtual void getValue(int8_t* value) throw (...); 43 | virtual void getValue(uint8_t* value) throw (...); 44 | virtual void getValue(int16_t* value) throw (...); 45 | virtual void getValue(uint16_t* value) throw (...); 46 | virtual void getValue(int32_t* value) throw (...); 47 | virtual void getValue(uint32_t* value) throw (...); 48 | virtual void getValue(int64_t* value) throw (...); 49 | virtual void getValue(uint64_t* value) throw (...); 50 | virtual void getValue(float* value) throw (...); 51 | virtual void getValue(double* value) throw (...); 52 | 53 | template out_type getValue() throw (...); 54 | 55 | // Internal methods 56 | // For initialization in ObjectPool 57 | void initObject(DictionaryBaseType* dict_parent, UsdsBaseType* body_parent) throw(...); 58 | 59 | UsdsBaseType* getNext() throw (...); 60 | UsdsBaseType* getPrevious() throw (...); 61 | UsdsBaseType* getParent() throw (...); 62 | 63 | void setNext(UsdsBaseType* next); 64 | void setPrevious(UsdsBaseType* previous); 65 | void setParent(UsdsBaseType* parent); 66 | 67 | protected: 68 | 69 | // it's executed in initObject() 70 | virtual void additionalInitObject() = 0; 71 | 72 | DictionaryBaseType* parentDictionaryObject; 73 | Body* parentBody; 74 | 75 | private: 76 | UsdsBaseType* parentObject; 77 | UsdsBaseType* nextObject; 78 | UsdsBaseType* previousObject; 79 | 80 | 81 | }; 82 | 83 | template out_type UsdsBaseType::getValue() throw (...) 84 | try 85 | { 86 | out_type value; 87 | getValue(&value); 88 | return value; 89 | } 90 | catch (ErrorStack& err) 91 | { 92 | err.addLevel("template out_type UsdsBaseType::getValue"); 93 | throw; 94 | }; 95 | } 96 | 97 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/body/usdsBody.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_BODY_H 2 | #define USDS_BODY_H 3 | 4 | #include "usdsErrors.h" 5 | #include "usdsTypes.h" 6 | 7 | #include "body\bodyObjectPool.h" 8 | 9 | #include "body\dataTypes\usdsArray.h" 10 | #include "body\dataTypes\usdsBoolean.h" 11 | #include "body\dataTypes\usdsDouble.h" 12 | #include "body\dataTypes\usdsInt.h" 13 | #include "body\dataTypes\usdsLong.h" 14 | #include "body\dataTypes\usdsString.h" 15 | #include "body\dataTypes\usdsStruct.h" 16 | #include "body\dataTypes\usdsUVarint.h" 17 | 18 | namespace usds 19 | { 20 | class Dictionary; 21 | 22 | class Body 23 | { 24 | public: 25 | Body(); 26 | virtual ~Body(); 27 | 28 | // Body construction 29 | UsdsBaseType* addTag(DictionaryBaseType* dict_tag) throw(...); 30 | UsdsBaseType* addField(DictionaryBaseType* dict_field, UsdsBaseType* parent_tag) throw(...); 31 | 32 | UsdsBaseType* getFirstTag() throw(...); 33 | UsdsBaseType* getLastTag() throw(...); 34 | 35 | UsdsBaseType* getFirstTag(int32_t tag_id) throw(...); 36 | 37 | 38 | void clear(); 39 | 40 | private: 41 | BodyObjectPool objectPool; 42 | 43 | UsdsBaseType* firstTag; 44 | UsdsBaseType* lastTag; 45 | void connectTagToBody(UsdsBaseType* tag); 46 | 47 | 48 | }; 49 | } 50 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/common/objectPool.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECT_POOL_H 2 | #define OBJECT_POOL_H 3 | 4 | #include "common\errorMessage.h" 5 | 6 | namespace usds 7 | { 8 | enum objectPoolErrorCodes 9 | { 10 | OBJECT_POOL__ALLOCATE_ERROR = 3 11 | }; 12 | 13 | class BasePoolClass; 14 | class BasePoolObject 15 | { 16 | friend class BasePoolClass; 17 | public: 18 | BasePoolObject(); 19 | virtual ~BasePoolObject(); 20 | // Hide object, not to delete 21 | void remove(); 22 | 23 | private: 24 | BasePoolObject* nextInPool; 25 | BasePoolObject* previousInPool; 26 | BasePoolClass* parentPool; 27 | }; 28 | 29 | class BasePoolClass 30 | { 31 | public: 32 | BasePoolClass(); 33 | virtual ~BasePoolClass(); 34 | 35 | BasePoolObject* addObject(); 36 | 37 | BasePoolObject* getFirstElement(); 38 | BasePoolObject* getLastElement(); 39 | BasePoolObject* getLastAllocatedElement(); 40 | 41 | BasePoolObject* getNextElement(BasePoolObject* object); 42 | BasePoolObject* getPreviousElement(BasePoolObject* object); 43 | 44 | size_t getFullSize(); 45 | size_t getAllocatedSize(); 46 | 47 | void clearPool(); 48 | 49 | // Hide object, not to delete 50 | void removeObject(BasePoolObject* object); 51 | 52 | protected: 53 | virtual BasePoolObject* createObject() = 0; 54 | 55 | BasePoolObject* firstElement; 56 | BasePoolObject* firstReservedElement; 57 | BasePoolObject* lastElement; 58 | 59 | }; 60 | 61 | 62 | // template for pools 63 | template 64 | class TemplateObjectPool : public BasePoolClass 65 | { 66 | public: 67 | TemplateObjectPool(parentPool_class* parent) 68 | { 69 | parentClass = parent; 70 | }; 71 | 72 | virtual ~TemplateObjectPool() { }; 73 | 74 | virtual BasePoolObject* createObject() throw(...) 75 | try 76 | { 77 | BasePoolObject* object = new T_classPool(parentClass); 78 | return object; 79 | } 80 | catch (...) 81 | { 82 | throw ErrorStack("TemplateObjectPool::createObject") << ErrorMessage(OBJECT_POOL__ALLOCATE_ERROR, "Can't allocate memory for the object"); 83 | }; 84 | 85 | private: 86 | 87 | parentPool_class* parentClass; 88 | }; 89 | 90 | }; 91 | 92 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/converters/usdsBinaryCreator.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_BINARY_CREATOR_H 2 | #define USDS_BINARY_CREATOR_H 3 | 4 | #include "converters\usdsBodyBinaryCreator.h" 5 | 6 | namespace usds 7 | { 8 | class BinaryOutput; 9 | class Dictionary; 10 | class Body; 11 | 12 | class BinaryCreator 13 | { 14 | public: 15 | BinaryCreator(); 16 | ~BinaryCreator(); 17 | 18 | void generate(BinaryOutput* buff, Dictionary* dict, Body* body) throw(...); 19 | 20 | private: 21 | BinaryOutput* binary; 22 | Dictionary* dictionary; 23 | 24 | // Serialization 25 | void addHeadToBinary() throw(...); 26 | 27 | BodyBinaryCreator bodyBinaryCreator; 28 | 29 | }; 30 | 31 | 32 | 33 | 34 | 35 | 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/converters/usdsBinaryParser.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_BINARY_PARSER_H 2 | #define USDS_BINARY_PARSER_H 3 | 4 | #include "binary\usdsBinaryInput.h" 5 | #include "converters\usdsDictionaryBinaryParser.h" 6 | #include "converters\usdsBodyBinaryParser.h" 7 | 8 | namespace usds 9 | { 10 | class Dictionary; 11 | class Body; 12 | 13 | class BinaryParser 14 | { 15 | public: 16 | BinaryParser(); 17 | ~BinaryParser(); 18 | 19 | void setBinary(const uint8_t* data, size_t data_size) throw(...); 20 | bool isHeadIncluded(); 21 | bool isDictionaryIncluded(); 22 | int32_t getDictionaryID(); 23 | uint8_t getDictionaryMajor(); 24 | uint8_t getDictionaryMinor(); 25 | bool isBodyIncluded(); 26 | 27 | void initDictionaryFromBinary(Dictionary* dict) throw(...); 28 | void initBodyFromBinary(Dictionary* dict, Body* body) throw(...); 29 | 30 | private: 31 | 32 | bool headExists; 33 | int32_t dictionaryID; 34 | uint8_t dictionaryMajor; 35 | uint8_t dictionaryMinor; 36 | size_t documentSize; 37 | 38 | bool dictionaryExists; 39 | bool bodyExists; 40 | 41 | BinaryInput binary; 42 | BinaryInput dictionaryBinary; 43 | BinaryInput bodyBinary; 44 | 45 | DictionaryBinaryParser dictionaryParser; 46 | BodyBinaryParser bodyParser; 47 | 48 | }; 49 | } 50 | 51 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/converters/usdsBodyBinaryCreator.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_BODY_BINARY_CREATOR_H 2 | #define USDS_BODY_BINARY_CREATOR_H 3 | 4 | #include "usdsErrors.h" 5 | #include "usdsTypes.h" 6 | 7 | 8 | 9 | namespace usds 10 | { 11 | class Body; 12 | class UsdsBaseType; 13 | class BinaryOutput; 14 | 15 | class BodyBinaryCreator 16 | { 17 | public: 18 | BodyBinaryCreator(); 19 | ~BodyBinaryCreator(); 20 | 21 | void generate(BinaryOutput* buff, Body* body) throw (...); 22 | 23 | private: 24 | BinaryOutput* usdsBuff; 25 | 26 | void (BodyBinaryCreator::*writeIndex[USDS_LAST_TYPE])(UsdsBaseType*); 27 | 28 | void writeTag(UsdsBaseType* object) throw (...); 29 | void writeBoolean(UsdsBaseType* object) throw (...); 30 | void writeByte(UsdsBaseType* object) throw (...); 31 | void writeUByte(UsdsBaseType* object) throw (...); 32 | void writeShort(UsdsBaseType* object) throw (...); 33 | void writeUShort(UsdsBaseType* object) throw (...); 34 | void writeInt(UsdsBaseType* object) throw (...); 35 | void writeUInt(UsdsBaseType* object) throw (...); 36 | void writeLong(UsdsBaseType* object) throw (...); 37 | void writeULong(UsdsBaseType* object) throw (...); 38 | void writeInt128(UsdsBaseType* object) throw (...); 39 | void writeUInt128(UsdsBaseType* object) throw (...); 40 | void writeFloat(UsdsBaseType* object) throw (...); 41 | void writeDouble(UsdsBaseType* object) throw (...); 42 | void writeVarint(UsdsBaseType* object) throw (...); 43 | void writeUVarint(UsdsBaseType* object) throw (...); 44 | void writeString(UsdsBaseType* object) throw (...); 45 | void writeArray(UsdsBaseType* object) throw (...); 46 | void writeStruct(UsdsBaseType* object) throw (...); 47 | 48 | }; 49 | 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/converters/usdsBodyBinaryParser.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_BODY_BINARY_PARSER_H 2 | #define USDS_BODY_BINARY_PARSER_H 3 | 4 | #include "usdsErrors.h" 5 | #include "usdsTypes.h" 6 | 7 | namespace usds 8 | { 9 | class Body; 10 | class Dictionary; 11 | class UsdsBaseType; 12 | class BinaryInput; 13 | 14 | class BodyBinaryParser 15 | { 16 | public: 17 | BodyBinaryParser(); 18 | ~BodyBinaryParser(); 19 | 20 | void parse(BinaryInput* buff, Dictionary* dict_object, Body* body_object) throw (...); 21 | 22 | private: 23 | BinaryInput* usdsBuff; 24 | Body* body; 25 | Dictionary* dict; 26 | 27 | void (BodyBinaryParser::*readIndex[USDS_LAST_TYPE])(UsdsBaseType*); 28 | 29 | void readTag(UsdsBaseType* object) throw (...); 30 | void readBoolean(UsdsBaseType* object) throw (...); 31 | void readByte(UsdsBaseType* object) throw (...); 32 | void readUByte(UsdsBaseType* object) throw (...); 33 | void readShort(UsdsBaseType* object) throw (...); 34 | void readUShort(UsdsBaseType* object) throw (...); 35 | void readInt(UsdsBaseType* object) throw (...); 36 | void readUInt(UsdsBaseType* object) throw (...); 37 | void readLong(UsdsBaseType* object) throw (...); 38 | void readULong(UsdsBaseType* object) throw (...); 39 | void readInt128(UsdsBaseType* object) throw (...); 40 | void readUInt128(UsdsBaseType* object) throw (...); 41 | void readFloat(UsdsBaseType* object) throw (...); 42 | void readDouble(UsdsBaseType* object) throw (...); 43 | void readVarint(UsdsBaseType* object) throw (...); 44 | void readUVarint(UsdsBaseType* object) throw (...); 45 | void readString(UsdsBaseType* object) throw (...); 46 | void readArray(UsdsBaseType* object) throw (...); 47 | void readStruct(UsdsBaseType* object) throw (...); 48 | 49 | }; 50 | 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/converters/usdsBodyJsonCreator.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_BODY_JSON_CREATOR_H 2 | #define USDS_BODY_JSON_CREATOR_H 3 | 4 | #include "usdsErrors.h" 5 | #include "usdsTypes.h" 6 | 7 | #include 8 | 9 | namespace usds 10 | { 11 | class Body; 12 | class UsdsBaseType; 13 | 14 | class BodyJsonCreator 15 | { 16 | public: 17 | BodyJsonCreator(); 18 | ~BodyJsonCreator(); 19 | 20 | void generate(usdsEncode encode, std::string* text, Body* body) throw (...); 21 | 22 | private: 23 | std::string* textBuff; 24 | 25 | void (BodyJsonCreator::*writeIndex[USDS_LAST_TYPE])(UsdsBaseType*); 26 | 27 | void writeBoolean(UsdsBaseType* object) throw (...); 28 | void writeByte(UsdsBaseType* object) throw (...); 29 | void writeUByte(UsdsBaseType* object) throw (...); 30 | void writeShort(UsdsBaseType* object) throw (...); 31 | void writeUShort(UsdsBaseType* object) throw (...); 32 | void writeInt(UsdsBaseType* object) throw (...); 33 | void writeUInt(UsdsBaseType* object) throw (...); 34 | void writeLong(UsdsBaseType* object) throw (...); 35 | void writeULong(UsdsBaseType* object) throw (...); 36 | void writeInt128(UsdsBaseType* object) throw (...); 37 | void writeUInt128(UsdsBaseType* object) throw (...); 38 | void writeFloat(UsdsBaseType* object) throw (...); 39 | void writeDouble(UsdsBaseType* object) throw (...); 40 | void writeVarint(UsdsBaseType* object) throw (...); 41 | void writeUVarint(UsdsBaseType* object) throw (...); 42 | void writeString(UsdsBaseType* object) throw (...); 43 | void writeArray(UsdsBaseType* object) throw (...); 44 | void writeStruct(UsdsBaseType* object) throw (...); 45 | void writeEnum(UsdsBaseType* object) throw (...); 46 | 47 | int32_t shiftLevel; 48 | 49 | }; 50 | 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/converters/usdsDictionaryBinaryCreator.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_DICTIONARY_BINARY_CREATOR_H 2 | #define USDS_DICTIONARY_BINARY_CREATOR_H 3 | 4 | #include "usdsTypes.h" 5 | #include "usdsErrors.h" 6 | 7 | namespace usds 8 | { 9 | class BinaryOutput; 10 | class Dictionary; 11 | class DictionaryBaseType; 12 | 13 | class DictionaryBinaryCreator 14 | { 15 | public: 16 | 17 | DictionaryBinaryCreator(); 18 | ~DictionaryBinaryCreator(); 19 | 20 | // Generate Binary Dictionary without size and signature 21 | void generate(BinaryOutput* buff, Dictionary* dict) throw (...); 22 | 23 | private: 24 | 25 | void (DictionaryBinaryCreator::*writeIndex[USDS_LAST_TYPE])(DictionaryBaseType*); 26 | 27 | void writeTag(DictionaryBaseType* object) throw (...); 28 | void writeBoolean(DictionaryBaseType* object) throw (...); 29 | void writeByte(DictionaryBaseType* object) throw (...); 30 | void writeUByte(DictionaryBaseType* object) throw (...); 31 | void writeShort(DictionaryBaseType* object) throw (...); 32 | void writeUShort(DictionaryBaseType* object) throw (...); 33 | void writeInt(DictionaryBaseType* object) throw (...); 34 | void writeUInt(DictionaryBaseType* object) throw (...); 35 | void writeLong(DictionaryBaseType* object) throw (...); 36 | void writeULong(DictionaryBaseType* object) throw (...); 37 | void writeInt128(DictionaryBaseType* object) throw (...); 38 | void writeUInt128(DictionaryBaseType* object) throw (...); 39 | void writeFloat(DictionaryBaseType* object) throw (...); 40 | void writeDouble(DictionaryBaseType* object) throw (...); 41 | void writeVarint(DictionaryBaseType* object) throw (...); 42 | void writeUVarint(DictionaryBaseType* object) throw (...); 43 | void writeString(DictionaryBaseType* object) throw (...); 44 | void writeArray(DictionaryBaseType* object) throw (...); 45 | void writeStruct(DictionaryBaseType* object) throw (...); 46 | 47 | BinaryOutput* outBuffer; 48 | 49 | }; 50 | } 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/converters/usdsDictionaryBinaryParser.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_DICTIONARY_BINARY_PARSER_H 2 | #define USDS_DICTIONARY_BINARY_PARSER_H 3 | 4 | #include "usdsTypes.h" 5 | #include "usdsErrors.h" 6 | 7 | namespace usds 8 | { 9 | class BinaryInput; 10 | class Dictionary; 11 | class DictionaryBaseType; 12 | 13 | class DictionaryBinaryParser 14 | { 15 | public: 16 | DictionaryBinaryParser(); 17 | ~DictionaryBinaryParser(); 18 | 19 | // read binary without size and signature 20 | void parse(BinaryInput* buff, Dictionary* dict) throw(...); 21 | 22 | private: 23 | 24 | void (DictionaryBinaryParser::*readIndex[USDS_LAST_TYPE])(DictionaryBaseType*); 25 | 26 | void readTag(DictionaryBaseType* object) throw (...); 27 | void readBoolean(DictionaryBaseType* object) throw (...); 28 | void readByte(DictionaryBaseType* object) throw (...); 29 | void readUByte(DictionaryBaseType* object) throw (...); 30 | void readShort(DictionaryBaseType* object) throw (...); 31 | void readUShort(DictionaryBaseType* object) throw (...); 32 | void readInt(DictionaryBaseType* object) throw (...); 33 | void readUInt(DictionaryBaseType* object) throw (...); 34 | void readLong(DictionaryBaseType* object) throw (...); 35 | void readULong(DictionaryBaseType* object) throw (...); 36 | void readInt128(DictionaryBaseType* object) throw (...); 37 | void readUInt128(DictionaryBaseType* object) throw (...); 38 | void readFloat(DictionaryBaseType* object) throw (...); 39 | void readDouble(DictionaryBaseType* object) throw (...); 40 | void readVarint(DictionaryBaseType* object) throw (...); 41 | void readUVarint(DictionaryBaseType* object) throw (...); 42 | void readString(DictionaryBaseType* object) throw (...); 43 | void readArray(DictionaryBaseType* object) throw (...); 44 | void readStruct(DictionaryBaseType* object) throw (...); 45 | 46 | BinaryInput* binary; 47 | Dictionary* dictionary; 48 | }; 49 | 50 | } 51 | 52 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/converters/usdsDictionaryTextCreator.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_DICTIONARY_TEXT_CREATOR_H 2 | #define USDS_DICTIONARY_TEXT_CREATOR_H 3 | 4 | #include "usdsErrors.h" 5 | #include "usdsTypes.h" 6 | 7 | #include 8 | 9 | namespace usds 10 | { 11 | class Dictionary; 12 | class DictionaryBaseType; 13 | 14 | class DictionaryTextCreator 15 | { 16 | public: 17 | DictionaryTextCreator(); 18 | ~DictionaryTextCreator() { }; 19 | 20 | void generate(usdsEncode encode, std::string* text, Dictionary* dict) throw (...); 21 | 22 | private: 23 | std::stringstream textBuff; 24 | 25 | void (DictionaryTextCreator::*writeIndex[USDS_LAST_TYPE])(DictionaryBaseType*); 26 | 27 | void writeTag(DictionaryBaseType* object) throw (...); 28 | void writeBoolean(DictionaryBaseType* object) throw (...); 29 | void writeByte(DictionaryBaseType* object) throw (...); 30 | void writeUByte(DictionaryBaseType* object) throw (...); 31 | void writeShort(DictionaryBaseType* object) throw (...); 32 | void writeUShort(DictionaryBaseType* object) throw (...); 33 | void writeInt(DictionaryBaseType* object) throw (...); 34 | void writeUInt(DictionaryBaseType* object) throw (...); 35 | void writeLong(DictionaryBaseType* object) throw (...); 36 | void writeULong(DictionaryBaseType* object) throw (...); 37 | void writeInt128(DictionaryBaseType* object) throw (...); 38 | void writeUInt128(DictionaryBaseType* object) throw (...); 39 | void writeFloat(DictionaryBaseType* object) throw (...); 40 | void writeDouble(DictionaryBaseType* object) throw (...); 41 | void writeVarint(DictionaryBaseType* object) throw (...); 42 | void writeUVarint(DictionaryBaseType* object) throw (...); 43 | void writeString(DictionaryBaseType* object) throw (...); 44 | void writeArray(DictionaryBaseType* object) throw (...); 45 | void writeStruct(DictionaryBaseType* object) throw (...); 46 | 47 | 48 | }; 49 | 50 | }; 51 | 52 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/converters/usdsDictionaryTextParser.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_DICTIONARY_TEXT_PARSER_H 2 | #define USDS_DICTIONARY_TEXT_PARSER_H 3 | 4 | #include "usdsTypes.h" 5 | #include "usdsErrors.h" 6 | 7 | namespace usds 8 | { 9 | class Dictionary; 10 | 11 | class DictionaryTextParser 12 | { 13 | public: 14 | DictionaryTextParser() {}; 15 | ~DictionaryTextParser() {}; 16 | 17 | void parse(const char* text_dict, usdsEncode encode, Dictionary* dict) throw (...); 18 | 19 | }; 20 | 21 | 22 | }; 23 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/dictionary/dataTypes/dictionaryArray.h: -------------------------------------------------------------------------------- 1 | #ifndef DICTIONARY_ARRAY_H 2 | #define DICTIONARY_ARRAY_H 3 | 4 | #include 5 | #include 6 | 7 | #include "usdsTypes.h" 8 | #include "usdsErrors.h" 9 | 10 | #include "dictionary\dictionaryBaseType.h" 11 | 12 | namespace usds 13 | { 14 | 15 | class DictionaryArray : public DictionaryBaseType 16 | { 17 | public: 18 | DictionaryArray(Dictionary* dict); 19 | virtual ~DictionaryArray() { }; 20 | 21 | void finalize() throw (...); 22 | 23 | usdsType getType() {return USDS_ARRAY;}; 24 | const char* getTypeName() {return "ARRAY";}; 25 | 26 | usdsType getElementType() throw (...); 27 | DictionaryBaseType* getElement() throw (...); 28 | 29 | DictionaryBaseType* setElementType(usdsType type_id) throw (...); 30 | 31 | bool hasDefaultValue() { return false; }; 32 | 33 | private: 34 | virtual void additionalInitType(); 35 | 36 | DictionaryBaseType* element; 37 | 38 | }; 39 | 40 | 41 | }; 42 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/dictionary/dataTypes/dictionaryBoolean.h: -------------------------------------------------------------------------------- 1 | #ifndef DICTIONARY_BOOLEAN_H 2 | #define DICTIONARY_BOOLEAN_H 3 | 4 | #include "usdsTypes.h" 5 | #include "usdsErrors.h" 6 | 7 | #include "dictionary\dictionaryBaseType.h" 8 | 9 | namespace usds 10 | { 11 | class DictionaryBoolean : public DictionaryBaseType 12 | { 13 | public: 14 | DictionaryBoolean(Dictionary* dict); 15 | virtual ~DictionaryBoolean() { }; 16 | 17 | void finalize() throw (...) { }; 18 | 19 | usdsType getType() { return USDS_BOOLEAN; }; 20 | const char* getTypeName() { return "BOOLEAN"; }; 21 | 22 | void setDefaultValue(bool value); 23 | bool getDefaultValue(); 24 | bool hasDefaultValue(); 25 | 26 | private: 27 | void additionalInitType(); 28 | 29 | bool isDefault; 30 | bool defaultValue; 31 | 32 | }; 33 | 34 | }; 35 | 36 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/dictionary/dataTypes/dictionaryByte.h: -------------------------------------------------------------------------------- 1 | #ifndef DICTIONARY_BYTE_H 2 | #define DICTIONARY_BYTE_H 3 | 4 | #include "usdsTypes.h" 5 | #include "usdsErrors.h" 6 | 7 | #include "dictionary\dictionaryBaseType.h" 8 | 9 | namespace usds 10 | { 11 | class DictionaryByte : public DictionaryBaseType 12 | { 13 | public: 14 | DictionaryByte(Dictionary* dict); 15 | virtual ~DictionaryByte() { }; 16 | 17 | void finalize() throw (...) { }; 18 | 19 | usdsType getType() { return USDS_BYTE; }; 20 | const char* getTypeName() { return "BYTE"; }; 21 | 22 | void setDefaultValue(int8_t value); 23 | int8_t getDefaultValue(); 24 | bool hasDefaultValue(); 25 | 26 | private: 27 | void additionalInitType(); 28 | 29 | bool isDefault; 30 | int8_t defaultValue; 31 | 32 | }; 33 | }; 34 | 35 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/dictionary/dataTypes/dictionaryDouble.h: -------------------------------------------------------------------------------- 1 | #ifndef DICTIONARY_DOUBLE_H 2 | #define DICTIONARY_DOUBLE_H 3 | 4 | #include "usdsTypes.h" 5 | #include "usdsErrors.h" 6 | 7 | #include "dictionary\dictionaryBaseType.h" 8 | 9 | namespace usds 10 | { 11 | class DictionaryDouble : public DictionaryBaseType 12 | { 13 | public: 14 | DictionaryDouble(Dictionary* dict); 15 | virtual ~DictionaryDouble() { }; 16 | 17 | void finalize() throw (...) { }; 18 | 19 | usdsType getType() { return USDS_DOUBLE; }; 20 | const char* getTypeName() { return "DOUBLE"; }; 21 | 22 | void setBigendian(bool is_bigendian) { isBigendian = is_bigendian; }; 23 | bool getBigendian() { return isBigendian; }; 24 | 25 | void setDefaultValue(double value); 26 | double getDefaultValue(); 27 | bool hasDefaultValue(); 28 | 29 | private: 30 | void additionalInitType(); 31 | 32 | bool isBigendian; 33 | 34 | bool isDefault; 35 | double defaultValue; 36 | 37 | }; 38 | 39 | }; 40 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/dictionary/dataTypes/dictionaryEnum.h: -------------------------------------------------------------------------------- 1 | #ifndef DICTIONARY_ENUM_H 2 | #define DICTIONARY_ENUM_H 3 | 4 | #include "usdsTypes.h" 5 | #include "usdsErrors.h" 6 | 7 | #include "dictionary\dictionaryBaseType.h" 8 | 9 | namespace usds 10 | { 11 | class DictionaryEnum : public DictionaryBaseType 12 | { 13 | public: 14 | DictionaryEnum(Dictionary* dict); 15 | virtual ~DictionaryEnum(); 16 | 17 | void setSubtype(usdsType subtype, bool is_bigendian); 18 | usdsType getSubtype(); 19 | bool isSubtypeBigendian(); 20 | 21 | void addEnumerator(int64_t value, const char* name, size_t name_size) throw(...); 22 | int64_t addEnumerator(const char* name, size_t name_size) throw(...); 23 | 24 | // return 0 if not found 25 | const char* getEnumerator(int64_t value); 26 | 27 | int64_t getValue(const char* name); 28 | int64_t getValue(const char* name, size_t name_size); 29 | 30 | void setDefaultValue(int64_t value); 31 | void setDefaultFromUTF8(const char* name); 32 | void setDefaultFromUTF8(const char* name, size_t size); 33 | 34 | int64_t getDefaultValue(); 35 | // return 0 if not found 36 | const char* getDefaultAsUTF8() throw (...); 37 | const char* getDefaultAsUTF8(size_t* byte_size) throw (...); 38 | 39 | bool hasDefaultValue(); 40 | 41 | // Dictionary finalization 42 | void finalize() throw (...); 43 | 44 | // for autotests 45 | bool isIndexed(); 46 | 47 | usdsType getType() { return USDS_ENUM; }; 48 | const char* getTypeName() { return "ENUM"; }; 49 | 50 | private: 51 | 52 | // it's executed in DicBaseTag.initType() 53 | void additionalInitType(); 54 | 55 | usdsType subType; 56 | bool isBigendian; 57 | 58 | bool isDefault; 59 | int64_t defaultValue; 60 | 61 | struct Enumerator 62 | { 63 | int64_t value; 64 | char name[512-sizeof(int64_t)]; 65 | }; 66 | 67 | Enumerator* enumerators; 68 | size_t enumeratorNumbers; 69 | size_t enumeratorBufferSize; 70 | 71 | // sorted enumerators 72 | Enumerator** index; 73 | size_t indexBufferSize; 74 | bool isIndexUsed; // index is not being used, if size is too big 75 | int64_t enumeratorMinValue; 76 | int64_t enumeratorMaxValue; 77 | int64_t lastAddedEnumerator; 78 | 79 | bool isFinalized; 80 | 81 | }; 82 | } 83 | 84 | #endif 85 | 86 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/dictionary/dataTypes/dictionaryFloat.h: -------------------------------------------------------------------------------- 1 | #ifndef DICTIONARY_FLOAT_H 2 | #define DICTIONARY_FLOAT_H 3 | 4 | #include "usdsTypes.h" 5 | #include "usdsErrors.h" 6 | 7 | #include "dictionary\dictionaryBaseType.h" 8 | 9 | namespace usds 10 | { 11 | class DictionaryFloat : public DictionaryBaseType 12 | { 13 | public: 14 | DictionaryFloat(Dictionary* dict); 15 | virtual ~DictionaryFloat() { }; 16 | 17 | void finalize() throw (...) { }; 18 | 19 | usdsType getType() { return USDS_FLOAT; }; 20 | const char* getTypeName() { return "FLOAT"; }; 21 | 22 | void setBigendian(bool is_bigendian) { isBigendian = is_bigendian; }; 23 | bool getBigendian() { return isBigendian; }; 24 | 25 | void setDefaultValue(float value); 26 | float getDefaultValue(); 27 | bool hasDefaultValue(); 28 | 29 | private: 30 | void additionalInitType(); 31 | 32 | bool isBigendian; 33 | 34 | bool isDefault; 35 | float defaultValue; 36 | 37 | }; 38 | 39 | }; 40 | #endif 41 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/dictionary/dataTypes/dictionaryInt.h: -------------------------------------------------------------------------------- 1 | #ifndef DICTIONARY_INT_H 2 | #define DICTIONARY_INT_H 3 | 4 | #include "usdsTypes.h" 5 | #include "usdsErrors.h" 6 | 7 | #include "dictionary\dictionaryBaseType.h" 8 | 9 | namespace usds 10 | { 11 | class DictionaryInt : public DictionaryBaseType 12 | { 13 | public: 14 | DictionaryInt(Dictionary* dict); 15 | virtual ~DictionaryInt() { }; 16 | 17 | void finalize() throw (...) { }; 18 | 19 | usdsType getType() { return USDS_INT; }; 20 | const char* getTypeName() { return "INT"; }; 21 | 22 | void setBigendian(bool is_bigendian) { isBigendian = is_bigendian; }; 23 | bool getBigendian() { return isBigendian; }; 24 | 25 | void setDefaultValue(int32_t value); 26 | int32_t getDefaultValue(); 27 | bool hasDefaultValue(); 28 | 29 | private: 30 | void additionalInitType(); 31 | 32 | bool isBigendian; 33 | 34 | bool isDefault; 35 | int32_t defaultValue; 36 | }; 37 | }; 38 | 39 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/dictionary/dataTypes/dictionaryLong.h: -------------------------------------------------------------------------------- 1 | #ifndef DICTIONARY_LONG_H 2 | #define DICTIONARY_LONG_H 3 | 4 | #include "usdsTypes.h" 5 | #include "usdsErrors.h" 6 | 7 | #include "dictionary\dictionaryBaseType.h" 8 | 9 | namespace usds 10 | { 11 | class DictionaryLong : public DictionaryBaseType 12 | { 13 | public: 14 | DictionaryLong(Dictionary* dict); 15 | virtual ~DictionaryLong() { }; 16 | 17 | void finalize() throw (...) { }; 18 | 19 | usdsType getType() { return USDS_LONG; }; 20 | const char* getTypeName() { return "LONG"; }; 21 | 22 | void setBigendian(bool is_bigendian) { isBigendian = is_bigendian; }; 23 | bool getBigendian() { return isBigendian; }; 24 | 25 | void setDefaultValue(int64_t value); 26 | int64_t getDefaultValue(); 27 | bool hasDefaultValue(); 28 | 29 | private: 30 | void additionalInitType(); 31 | 32 | bool isBigendian; 33 | 34 | bool isDefault; 35 | int64_t defaultValue; 36 | 37 | }; 38 | 39 | }; 40 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/dictionary/dataTypes/dictionaryPolymorph.h: -------------------------------------------------------------------------------- 1 | #ifndef DICTIONARY_POLYMORPH_H 2 | #define DICTIONARY_POLYMORPH_H 3 | 4 | #include "usdsTypes.h" 5 | #include "usdsErrors.h" 6 | 7 | #include "dictionary\dictionaryBaseType.h" 8 | 9 | 10 | namespace usds 11 | { 12 | class DictionaryTagLink; 13 | class DictionaryStruct; 14 | 15 | class DictionaryPolymorph : public DictionaryBaseType 16 | { 17 | public: 18 | DictionaryPolymorph(Dictionary* dict); 19 | virtual ~DictionaryPolymorph(); 20 | 21 | usdsType getType() { return USDS_POLYMORPH; }; 22 | const char* getTypeName() { return "POLYMORPH"; }; 23 | 24 | void addTag(const char* tag_name, size_t name_size) throw (...); 25 | void addTag(int32_t tag_id) throw (...); 26 | void setTags(DictionaryTagLink* tags_chain) throw (...); 27 | 28 | int32_t getSubtagId(const char* tag_name) throw (...); 29 | 30 | DictionaryStruct* getSubStruct(int32_t tag_id) throw (...); 31 | DictionaryStruct* getSubStruct(const char* tag_name) throw (...); 32 | 33 | void finalize() throw (...); 34 | void getSubStructs(DictionaryStruct** index) throw (...); 35 | DictionaryTagLink* getFirstTag() throw (...); 36 | 37 | bool hasDefaultValue() { return false; }; 38 | 39 | private: 40 | void additionalInitType(); 41 | 42 | DictionaryTagLink* firstSubTag; 43 | DictionaryTagLink* lastSubTag; 44 | bool tagsFinalized; 45 | bool checkRecursion; 46 | 47 | // field index 48 | int32_t subTagMaxID; 49 | DictionaryStruct** subTagIndex; 50 | int32_t buffIndexSize; 51 | bool indexed; 52 | 53 | 54 | }; 55 | } 56 | #endif 57 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/dictionary/dataTypes/dictionaryShort.h: -------------------------------------------------------------------------------- 1 | #ifndef DICTIONARY_SHORT_H 2 | #define DICTIONARY_SHORT_H 3 | 4 | #include "usdsTypes.h" 5 | #include "usdsErrors.h" 6 | 7 | #include "dictionary\dictionaryBaseType.h" 8 | 9 | namespace usds 10 | { 11 | class DictionaryShort : public DictionaryBaseType 12 | { 13 | public: 14 | DictionaryShort(Dictionary* dict); 15 | virtual ~DictionaryShort() { }; 16 | 17 | void finalize() throw (...) { }; 18 | 19 | usdsType getType() { return USDS_SHORT; }; 20 | const char* getTypeName() { return "SHORT"; }; 21 | 22 | void setBigendian(bool is_bigendian) { isBigendian = is_bigendian; }; 23 | bool getBigendian() { return isBigendian; }; 24 | 25 | void setDefaultValue(int16_t value); 26 | int16_t getDefaultValue(); 27 | bool hasDefaultValue(); 28 | 29 | private: 30 | void additionalInitType(); 31 | 32 | bool isBigendian; 33 | 34 | bool isDefault; 35 | int16_t defaultValue; 36 | 37 | }; 38 | }; 39 | 40 | #endif 41 | 42 | 43 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/dictionary/dataTypes/dictionaryString.h: -------------------------------------------------------------------------------- 1 | #ifndef DICTIONARY_STRING_H 2 | #define DICTIONARY_STRING_H 3 | 4 | #include 5 | 6 | #include "usdsTypes.h" 7 | #include "usdsErrors.h" 8 | 9 | #include "dictionary\dictionaryBaseType.h" 10 | 11 | namespace usds 12 | { 13 | class DictionaryString : public DictionaryBaseType 14 | { 15 | public: 16 | DictionaryString(Dictionary* dict); 17 | virtual ~DictionaryString(); 18 | 19 | void finalize() throw (...); 20 | 21 | usdsType getType() { return USDS_STRING; }; 22 | const char* getTypeName() { return "STRING"; }; 23 | 24 | void setDefaultEncode(usdsEncode value) throw(...); 25 | usdsEncode getDefaultEncode() throw(...); 26 | 27 | void setDefaultValueFromUTF8(const char* value); 28 | void setDefaultValueFromUTF8(const char* value, size_t byte_size); 29 | const char* getUTF8DefaultValue(); 30 | bool hasDefaultValue(); 31 | 32 | private: 33 | void additionalInitType(); 34 | 35 | usdsEncode defaultEncode; 36 | 37 | bool isDefault; 38 | char* defaultValue; 39 | size_t defaultValueBufferSize; 40 | }; 41 | 42 | 43 | }; 44 | #endif 45 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/dictionary/dataTypes/dictionaryStruct.h: -------------------------------------------------------------------------------- 1 | #ifndef DICTIONARY_STRUCT_H 2 | #define DICTIONARY_STRUCT_H 3 | 4 | #include "usdsTypes.h" 5 | #include "usdsErrors.h" 6 | 7 | #include "dictionary\dictionaryBaseType.h" 8 | 9 | namespace usds 10 | { 11 | class DictionaryStruct : public DictionaryBaseType 12 | { 13 | public: 14 | DictionaryStruct(Dictionary* dict); 15 | virtual ~DictionaryStruct(); 16 | 17 | DictionaryBaseType* addField(usdsType field_type, int32_t id, const char* name, size_t name_size) throw(...); 18 | DictionaryBaseType* addField(usdsType field_type, const char* name, size_t name_size) throw(...); 19 | 20 | DictionaryBaseType* getFirstField(); 21 | DictionaryBaseType* getLastField(); 22 | 23 | int32_t getFieldNumbers() throw (...); 24 | 25 | DictionaryBaseType* getField(int32_t id) throw (...); 26 | DictionaryBaseType* getField(const char* name) throw (...); 27 | DictionaryBaseType* getField(const char* name, size_t name_size) throw (...); 28 | 29 | // Find field ID by Name 30 | // return 0 if field not found 31 | int32_t findFieldID(const char* name) throw (...); 32 | int32_t findFieldID(const char* name, size_t name_size) throw (...); 33 | 34 | // Dictionary finalization 35 | void finalize() throw (...); 36 | 37 | usdsType getType() { return USDS_STRUCT; }; 38 | const char* getTypeName() { return "STRUCT"; }; 39 | 40 | bool hasDefaultValue() { return false; }; 41 | 42 | private: 43 | // it's executed in DicBaseTag.initType() 44 | void additionalInitType(); 45 | 46 | 47 | void connectFieldToTag(DictionaryBaseType* field); 48 | DictionaryBaseType* firstField; 49 | DictionaryBaseType* lastField; 50 | 51 | // field index 52 | int32_t fieldMaxID; 53 | int32_t fieldNumber; 54 | DictionaryBaseType** fieldIndex; 55 | int32_t buffIndexSize; 56 | bool indexed; 57 | 58 | }; 59 | 60 | 61 | 62 | 63 | 64 | 65 | }; 66 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/dictionary/dataTypes/dictionaryTagLink.h: -------------------------------------------------------------------------------- 1 | #ifndef DICTIONARY_TAG_H 2 | #define DICTIONARY_TAG_H 3 | 4 | #include "usdsTypes.h" 5 | #include "usdsErrors.h" 6 | 7 | #include "dictionary\dictionaryBaseType.h" 8 | 9 | namespace usds 10 | { 11 | class DictionaryTagLink : public DictionaryBaseType 12 | { 13 | public: 14 | DictionaryTagLink(Dictionary* dict); 15 | virtual ~DictionaryTagLink() { }; 16 | 17 | void finalize() throw (...); 18 | 19 | usdsType getType() { return USDS_TAG; }; 20 | const char* getTypeName() { return "TAG"; }; 21 | 22 | void setTag(const char* tag_name, size_t name_size) throw (...); 23 | void setTag(int32_t tag_id) throw (...); 24 | 25 | DictionaryBaseType* getTag() throw (...); 26 | 27 | bool hasDefaultValue() { return false; }; 28 | 29 | private: 30 | void additionalInitType(); 31 | 32 | DictionaryBaseType* tag; 33 | int32_t tagID; 34 | std::string tagName; 35 | 36 | }; 37 | 38 | }; 39 | 40 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/dictionary/dataTypes/dictionaryUByte.h: -------------------------------------------------------------------------------- 1 | #ifndef DICTIONARY_UBYTE_H 2 | #define DICTIONARY_UBYTE_H 3 | 4 | #include "usdsTypes.h" 5 | #include "usdsErrors.h" 6 | 7 | #include "dictionary\dictionaryBaseType.h" 8 | 9 | namespace usds 10 | { 11 | class DictionaryUByte : public DictionaryBaseType 12 | { 13 | public: 14 | DictionaryUByte(Dictionary* dict); 15 | virtual ~DictionaryUByte() { }; 16 | 17 | void finalize() throw (...) { }; 18 | 19 | usdsType getType() { return USDS_UBYTE; }; 20 | const char* getTypeName() { return "UBYTE"; }; 21 | 22 | void setDefaultValue(uint8_t value); 23 | uint8_t getDefaultValue(); 24 | bool hasDefaultValue(); 25 | 26 | private: 27 | void additionalInitType(); 28 | 29 | bool isDefault; 30 | uint8_t defaultValue; 31 | 32 | 33 | }; 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/dictionary/dataTypes/dictionaryUInt.h: -------------------------------------------------------------------------------- 1 | #ifndef DICTIONARY_UINT_H 2 | #define DICTIONARY_UINT_H 3 | 4 | #include "usdsTypes.h" 5 | #include "usdsErrors.h" 6 | 7 | #include "dictionary\dictionaryBaseType.h" 8 | 9 | namespace usds 10 | { 11 | class DictionaryUInt : public DictionaryBaseType 12 | { 13 | public: 14 | DictionaryUInt(Dictionary* dict); 15 | virtual ~DictionaryUInt() { }; 16 | 17 | void finalize() throw (...) { }; 18 | 19 | usdsType getType() { return USDS_UINT; }; 20 | const char* getTypeName() { return "UINT"; }; 21 | 22 | void setBigendian(bool is_bigendian) { isBigendian = is_bigendian; }; 23 | bool getBigendian() { return isBigendian; }; 24 | 25 | void setDefaultValue(uint32_t value); 26 | uint32_t getDefaultValue(); 27 | bool hasDefaultValue(); 28 | 29 | private: 30 | void additionalInitType(); 31 | 32 | bool isBigendian; 33 | 34 | bool isDefault; 35 | uint32_t defaultValue; 36 | }; 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/dictionary/dataTypes/dictionaryULong.h: -------------------------------------------------------------------------------- 1 | #ifndef DICTIONARY_ULONG_H 2 | #define DICTIONARY_ULONG_H 3 | 4 | #include "usdsTypes.h" 5 | #include "usdsErrors.h" 6 | 7 | #include "dictionary\dictionaryBaseType.h" 8 | 9 | namespace usds 10 | { 11 | class DictionaryULong : public DictionaryBaseType 12 | { 13 | public: 14 | DictionaryULong(Dictionary* dict); 15 | virtual ~DictionaryULong() { }; 16 | 17 | void finalize() throw (...) { }; 18 | 19 | usdsType getType() { return USDS_ULONG; }; 20 | const char* getTypeName() { return "ULONG"; }; 21 | 22 | void setBigendian(bool is_bigendian) { isBigendian = is_bigendian; }; 23 | bool getBigendian() { return isBigendian; }; 24 | 25 | void setDefaultValue(uint64_t value); 26 | uint64_t getDefaultValue(); 27 | bool hasDefaultValue(); 28 | 29 | private: 30 | void additionalInitType(); 31 | 32 | bool isBigendian; 33 | 34 | bool isDefault; 35 | uint64_t defaultValue; 36 | }; 37 | 38 | }; 39 | #endif 40 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/dictionary/dataTypes/dictionaryUShort.h: -------------------------------------------------------------------------------- 1 | #ifndef DICTIONARY_USHORT_H 2 | #define DICTIONARY_USHORT_H 3 | 4 | #include "usdsTypes.h" 5 | #include "usdsErrors.h" 6 | 7 | #include "dictionary\dictionaryBaseType.h" 8 | 9 | namespace usds 10 | { 11 | class DictionaryUShort : public DictionaryBaseType 12 | { 13 | public: 14 | DictionaryUShort(Dictionary* dict); 15 | virtual ~DictionaryUShort() { }; 16 | 17 | void finalize() throw (...) { }; 18 | 19 | usdsType getType() { return USDS_USHORT; }; 20 | const char* getTypeName() { return "USHORT"; }; 21 | 22 | void setBigendian(bool is_bigendian) { isBigendian = is_bigendian; }; 23 | bool getBigendian() { return isBigendian; }; 24 | 25 | void setDefaultValue(uint16_t value); 26 | uint16_t getDefaultValue(); 27 | bool hasDefaultValue(); 28 | 29 | private: 30 | void additionalInitType(); 31 | 32 | bool isBigendian; 33 | 34 | bool isDefault; 35 | uint16_t defaultValue; 36 | 37 | }; 38 | }; 39 | 40 | #endif 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/dictionary/dataTypes/dictionaryUVarint.h: -------------------------------------------------------------------------------- 1 | #ifndef DICTIONARY_UVARINT_H 2 | #define DICTIONARY_UVARINT_H 3 | 4 | #include "usdsTypes.h" 5 | #include "usdsErrors.h" 6 | 7 | #include "dictionary\dictionaryBaseType.h" 8 | 9 | namespace usds 10 | { 11 | class DictionaryUVarint : public DictionaryBaseType 12 | { 13 | public: 14 | DictionaryUVarint(Dictionary* dict); 15 | virtual ~DictionaryUVarint() { }; 16 | 17 | virtual void finalize() throw (...) { }; 18 | 19 | usdsType getType() { return USDS_UVARINT; }; 20 | const char* getTypeName() { return "UVARINT"; }; 21 | 22 | void setDefaultValue(uint64_t value); 23 | uint64_t getDefaultValue(); 24 | bool hasDefaultValue(); 25 | 26 | private: 27 | void additionalInitType(); 28 | 29 | bool isDefault; 30 | uint64_t defaultValue; 31 | 32 | }; 33 | 34 | 35 | }; 36 | 37 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/dictionary/dataTypes/dictionaryVarint.h: -------------------------------------------------------------------------------- 1 | #ifndef DICTIONARY_VARINT_H 2 | #define DICTIONARY_VARINT_H 3 | 4 | #include "usdsTypes.h" 5 | #include "usdsErrors.h" 6 | 7 | #include "dictionary\dictionaryBaseType.h" 8 | 9 | namespace usds 10 | { 11 | class DictionaryVarint : public DictionaryBaseType 12 | { 13 | public: 14 | DictionaryVarint(Dictionary* dict); 15 | virtual ~DictionaryVarint() { }; 16 | 17 | virtual void finalize() throw (...) { }; 18 | 19 | usdsType getType() { return USDS_VARINT; }; 20 | const char* getTypeName() { return "VARINT"; }; 21 | 22 | void setDefaultValue(int64_t value); 23 | int64_t getDefaultValue(); 24 | bool hasDefaultValue(); 25 | 26 | private: 27 | void additionalInitType(); 28 | 29 | bool isDefault; 30 | int64_t defaultValue; 31 | 32 | }; 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/dictionary/dicObjectPool.h: -------------------------------------------------------------------------------- 1 | #ifndef DIC_OBJECT_POOL_H 2 | #define DIC_OBJECT_POOL_H 3 | 4 | #include "usdsErrors.h" 5 | #include "usdsTypes.h" 6 | #include "common\objectPool.h" 7 | 8 | namespace usds 9 | { 10 | class Dictionary; 11 | class DictionaryBaseType; 12 | 13 | 14 | class DictionaryObjectPool 15 | { 16 | public: 17 | DictionaryObjectPool(Dictionary* dict); 18 | ~DictionaryObjectPool(); 19 | 20 | DictionaryBaseType* addObject(usdsType object_type, DictionaryBaseType* parent, int32_t id, const char* name, size_t name_size) throw(...); 21 | 22 | // Clear pool, it does not release memory 23 | void clear(); 24 | 25 | 26 | private: 27 | 28 | BasePoolClass* pools[USDS_LAST_TYPE]; 29 | 30 | 31 | 32 | }; 33 | 34 | }; 35 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/dictionary/dictionaryBaseType.h: -------------------------------------------------------------------------------- 1 | #ifndef DICTIONARY_BASE_TYPE_H 2 | #define DICTIONARY_BASE_TYPE_H 3 | 4 | #include "usdsTypes.h" 5 | #include "usdsErrors.h" 6 | #include "common\objectPool.h" 7 | 8 | #include 9 | 10 | namespace usds 11 | { 12 | class Dictionary; 13 | class DictionaryObjectPool; 14 | 15 | class DictionaryBaseType : public BasePoolObject 16 | { 17 | public: 18 | DictionaryBaseType(Dictionary* dict) { dictionary = dict; }; 19 | virtual ~DictionaryBaseType() { }; 20 | 21 | // For initialization in ObjectPool 22 | void initType(DictionaryBaseType* parent, int32_t id, const char* name, size_t name_size) throw(...); 23 | protected: 24 | virtual void additionalInitType() = 0; // it's executing in initType() 25 | 26 | public: 27 | virtual void finalize() throw(...) = 0; 28 | 29 | const char* getName() throw(...); 30 | size_t getNameSize() throw(...); 31 | int32_t getID() throw(...); 32 | 33 | virtual usdsType getType() = 0; 34 | virtual const char* getTypeName() = 0; 35 | 36 | DictionaryBaseType* getNext() throw (...); 37 | DictionaryBaseType* getPrevious() throw (...); 38 | DictionaryBaseType* getParent() throw (...); 39 | 40 | void setNext(DictionaryBaseType* next); 41 | void setPrevious(DictionaryBaseType* previous); 42 | void setParent(DictionaryBaseType* parent); 43 | 44 | void setRoot(bool is_root) throw(...); 45 | bool getRootStatus() { return isRoot; }; 46 | 47 | // for fields 48 | DictionaryBaseType* setNullable(bool is_nullable); 49 | bool isNullable(); 50 | virtual bool hasDefaultValue() = 0; 51 | 52 | protected: 53 | std::string objectName; 54 | int32_t objectID; 55 | 56 | // restrictions 57 | bool isRoot; 58 | 59 | Dictionary* dictionary; 60 | 61 | private: 62 | DictionaryBaseType* parentObject; 63 | DictionaryBaseType* nextObject; 64 | DictionaryBaseType* previousObject; 65 | 66 | // for fields 67 | bool nullableValue; 68 | }; 69 | 70 | 71 | 72 | } 73 | 74 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/dictionary/usdsDictionary.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_DICTIONARY_H 2 | #define USDS_DICTIONARY_H 3 | 4 | #include "usdsErrors.h" 5 | #include "usdsTypes.h" 6 | #include "dictionary\dicObjectPool.h" 7 | #include "binary\usdsBinaryOutput.h" 8 | 9 | #include 10 | #include 11 | 12 | namespace usds 13 | { 14 | class DictionaryStruct; 15 | class DictionaryBaseType; 16 | class BasicParser; 17 | 18 | class Dictionary : public BasePoolObject 19 | { 20 | public: 21 | Dictionary(BasicParser* parent); 22 | ~Dictionary(); 23 | 24 | // Dictionary construction 25 | void setID(const char* name, uint32_t id, uint8_t major, uint8_t minor) throw (...); 26 | void setID(const char* name, size_t name_size, uint32_t id, uint8_t major, uint8_t minor) throw (...); 27 | 28 | void setDefaultStringEncode(usdsEncode encode); 29 | usdsEncode getDefaultStringEncode(); 30 | 31 | void setDefaultEnumSubtype(usdsType subtype, bool bigendian); 32 | usdsType getDefaultEnumSubtype(); 33 | bool isDefaultEnumSubtypeBigendian(); 34 | 35 | 36 | // construction 37 | DictionaryBaseType* addTag(usdsType tag_type, int32_t id, const char* name, size_t name_size) throw (...); 38 | DictionaryBaseType* addTag(usdsType tag_type, const char* name, size_t name_size) throw (...); 39 | DictionaryBaseType* addField(usdsType field_type, DictionaryBaseType* parent, int32_t id, const char* name, size_t name_size) throw (...); 40 | 41 | // Replace Tag names to tag ID, check errors 42 | void finalizeDictionary() throw(...); 43 | 44 | // Dictionary information 45 | const char* getDictionaryName(); 46 | uint32_t getDictionaryID(); 47 | uint8_t getMajorVersion(); 48 | uint8_t getMinorVersion(); 49 | 50 | DictionaryBaseType* getFirstTag() throw (...); 51 | DictionaryBaseType* getLastTag() throw (...); 52 | 53 | // Find Tag ID by Name 54 | // returns 0 if tag not found 55 | int32_t findTagID(const char* name) throw (...); 56 | int32_t findTagID(const char* name, size_t name_size) throw (...); 57 | 58 | // Find Tag by Name 59 | // returns 0 if tag not found 60 | DictionaryBaseType* findTag(const char* name) throw (...); 61 | DictionaryBaseType* findTag(const char* name, size_t name_size) throw (...); 62 | 63 | // Get tag by ID 64 | DictionaryBaseType* getTag(int32_t tag_id) throw (...); 65 | int32_t getTagNumber() throw (...); 66 | 67 | // TODO kill it 68 | // Encode dictionary 69 | const uint8_t* getBinary(size_t* size) throw(...); 70 | // add existing binary 71 | void setBinary(const void* data, size_t size) throw(...); 72 | 73 | // Clear dictionary, it does not release memory in DictionaryObjectPool 74 | void clear(); 75 | 76 | private: 77 | uint8_t majorVersion; 78 | uint8_t minorVersion; 79 | uint32_t dictionaryID; 80 | char* dictName; 81 | size_t nameBufferSize; 82 | 83 | usdsEncode defaultStringEncode; 84 | usdsType defaultEnumSubtype; 85 | bool defaultEnumSubtypeBigendian; 86 | 87 | DictionaryBaseType* firstTag; 88 | DictionaryBaseType* lastTag; 89 | void connectTagToDictionary(DictionaryBaseType* tag); 90 | 91 | // tag index 92 | int32_t tagMaxID; 93 | int32_t tagNumber; 94 | std::vector tagIndex; 95 | bool finalized; 96 | bool indexed; 97 | 98 | DictionaryObjectPool objectPool; 99 | 100 | // TODO kill it 101 | BinaryOutput binary; 102 | 103 | }; 104 | }; 105 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/usdsBasicParser.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_BASIC_PARSER_H 2 | #define USDS_BASIC_PARSER_H 3 | 4 | #include "usdsErrors.h" 5 | #include "usdsTypes.h" 6 | 7 | #include "dictionary\usdsDictionary.h" 8 | #include "common\objectPool.h" 9 | #include "binary\usdsBinaryOutput.h" 10 | #include "body\usdsBody.h" 11 | 12 | #include "converters\usdsBinaryCreator.h" 13 | #include "converters\usdsBinaryParser.h" 14 | #include "converters\usdsDictionaryTextCreator.h" 15 | #include "converters\usdsDictionaryTextParser.h" 16 | #include "converters\usdsBodyJsonCreator.h" 17 | 18 | #include 19 | 20 | namespace usds 21 | { 22 | class BasicParser 23 | { 24 | public: 25 | BasicParser(); 26 | virtual ~BasicParser(); 27 | 28 | // Settings 29 | const uint8_t usdsMajor; 30 | const uint8_t usdsMinor; 31 | 32 | // Dictionary constructors 33 | void addDictionaryFromText(const char* text_dictionary, size_t size, usdsEncode encode) throw(...); 34 | void CurrentDictionaryToText(usdsEncode encode, std::string* text) throw(...); 35 | 36 | // Working with several dictionaries 37 | Dictionary* selectDictionary(int32_t id, uint8_t major, uint8_t minor) throw(...); 38 | Dictionary* selectFirstDictionary() throw(...); 39 | Dictionary* selectNextDictionary() throw(...); 40 | 41 | // Return parameters for current dictionary 42 | int32_t getDictionaryID() throw(...); 43 | uint8_t getDictionaryMajor() throw(...); 44 | uint8_t getDictionaryMinor() throw(...); 45 | const char* getDictionaryName() throw(...); 46 | 47 | // Find id by names 48 | int32_t getTagID(const char* name) throw(...); 49 | int32_t getFieldID(int32_t tag_id, const char* name) throw(...); 50 | UsdsBaseType* getFirstTag(const char* name) throw(...); 51 | UsdsStruct* getFirstStructTag(const char* name) throw(...); 52 | 53 | // Body constructions 54 | UsdsBaseType* addTag(int32_t id) throw(...); 55 | UsdsStruct* addStruct(const char* name) throw(...); 56 | UsdsStruct* addStruct(int32_t id) throw(...); 57 | 58 | // encode 59 | void encode(BinaryOutput* buff, bool with_head, bool with_dictionary, bool with_body) throw(...); 60 | void getJSON(usdsEncode encode, std::string* text) throw(...); 61 | 62 | // decode 63 | void decode(const uint8_t* data, size_t data_size) throw(...); 64 | 65 | // clear 66 | void clear(); // it does not release memory in buffers 67 | void clearBody(); 68 | 69 | private: 70 | 71 | Dictionary* findDictionary(int32_t id, uint8_t major, uint8_t minor) throw(...); 72 | 73 | // Object pool of Dictionaries 74 | TemplateObjectPool dictionaryPool; 75 | // All existing dictionary 76 | std::list dictionaries; 77 | Dictionary* currentDictionary; 78 | 79 | Body body; 80 | 81 | BinaryCreator binaryCreator; 82 | BinaryParser binaryParser; 83 | DictionaryTextCreator dictionaryTextcreator; 84 | DictionaryTextParser dictionaryTextParser; 85 | BodyJsonCreator jsonCreator; 86 | 87 | }; 88 | 89 | }; 90 | 91 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Include/usdsTypes.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_TYPES_H 2 | #define USDS_TYPES_H 3 | 4 | #include "common\errorMessage.h" 5 | 6 | namespace usds 7 | { 8 | enum usdsType 9 | { 10 | USDS_TAG = 0, 11 | USDS_BOOLEAN = 1, 12 | USDS_BYTE = 2, 13 | USDS_UBYTE = 3, 14 | USDS_SHORT = 4, 15 | USDS_USHORT = 5, 16 | USDS_INT = 6, 17 | USDS_UINT = 7, 18 | USDS_LONG = 8, 19 | USDS_ULONG = 9, 20 | USDS_INT128 = 10, 21 | USDS_UINT128 = 11, 22 | USDS_FLOAT = 12, 23 | USDS_DOUBLE = 13, 24 | USDS_VARINT = 14, 25 | USDS_UVARINT = 15, 26 | USDS_STRING = 16, 27 | USDS_ARRAY = 17, 28 | USDS_STRUCT = 18, 29 | USDS_ENUM = 19, 30 | USDS_POLYMORPH = 20, 31 | USDS_LAST_TYPE = 21 32 | }; 33 | 34 | enum usdsTypeSize 35 | { 36 | USDS_TAG_SIZE = 0, 37 | USDS_BOOLEAN_SIZE = 1, 38 | USDS_BYTE_SIZE = 1, 39 | USDS_UBYTE_SIZE = 1, 40 | USDS_SHORT_SIZE = 2, 41 | USDS_USHORT_SIZE = 2, 42 | USDS_INT_SIZE = 4, 43 | USDS_UINT_SIZE = 4, 44 | USDS_LONG_SIZE = 8, 45 | USDS_ULONG_SIZE = 8, 46 | USDS_INT128_SIZE = 16, 47 | USDS_UINT128_SIZE = 16, 48 | USDS_FLOAT_SIZE = 4, 49 | USDS_DOUBLE_SIZE = 8, 50 | USDS_VARINT_SIZE = 0, 51 | USDS_UVARINT_SIZE = 0, 52 | USDS_STRING_SIZE = 0, 53 | USDS_ARRAY_SIZE = 0, 54 | USDS_STRUCT_SIZE = 0, 55 | USDS_ENUM_SIZE = 0, 56 | USDS_POLYMORPH_SIZE = 0 57 | }; 58 | 59 | enum usdsEncode 60 | { 61 | USDS_NO_DEFAULT_ENCODE = 0, 62 | USDS_UTF8 = 1, 63 | USDS_UTF16LE = 2, 64 | USDS_UTF16BE = 3, 65 | USDS_UTF32LE = 4, 66 | USDS_UTF32BE = 5, 67 | USDS_LAST_ENCODE = 6 68 | }; 69 | 70 | enum usdsSignature 71 | { 72 | USDS_MAJOR_SIGNATURE = '$', 73 | USDS_MINOR_SIGNATURE = 'S', 74 | USDS_MAJOR_VERSION = 1, 75 | USDS_MINOR_VERSION = 0, 76 | USDS_DICTIONARY_SIGNATURE = 'd', 77 | USDS_DICTIONARY_SIGNATURE_WITH_SIZE = 'D', 78 | USDS_TAG_SIGNATURE = 't', 79 | USDS_FIELD_SIGNATURE = 'f', 80 | USDS_TAG_RESTRICTION_SIGNATURE = 'R', 81 | USDS_TAG_RESTRICTION_NOT_ROOT_SIGNATURE = 'r', 82 | USDS_BODY_SIGNATURE = 'b', 83 | USDS_BODY_SIGNATURE_WITH_SIZE = 'B' 84 | }; 85 | 86 | class UsdsTypes 87 | { 88 | public: 89 | // abstract class 90 | virtual void f() = 0; 91 | 92 | 93 | static const char* typeName(usdsType code) throw(...); 94 | 95 | // returns 0 if unfixed 96 | static int32_t typeSize(usdsType code) throw(...); 97 | 98 | static const char* encodeName(usdsEncode code) throw(...); 99 | }; 100 | 101 | }; 102 | 103 | 104 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Binary/usdsTypeConverter.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zashibis/USDS/d6544310e613a191946305924d5b645a962267a4/BasicParserCPP/BasicParser/Source/Binary/usdsTypeConverter.cpp -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Body/DataTypes/usdsBoolean.cpp: -------------------------------------------------------------------------------- 1 | #include "body\dataTypes\usdsBoolean.h" 2 | 3 | #include "dictionary/dataTypes/dictionaryBoolean.h" 4 | 5 | using namespace usds; 6 | 7 | UsdsBoolean::UsdsBoolean(Body* parent_body) : UsdsBaseType(parent_body) 8 | { 9 | 10 | } 11 | 12 | UsdsBoolean::~UsdsBoolean() 13 | { 14 | } 15 | 16 | void UsdsBoolean::setValue(bool value) throw (...) 17 | { 18 | objectValue = value; 19 | }; 20 | 21 | void UsdsBoolean::getValue(bool* value) throw (...) 22 | { 23 | *value = objectValue; 24 | }; 25 | 26 | void UsdsBoolean::set(bool value) throw (...) 27 | { 28 | objectValue = value; 29 | }; 30 | 31 | bool UsdsBoolean::get() throw (...) 32 | { 33 | return objectValue; 34 | }; 35 | 36 | void UsdsBoolean::additionalInitObject() 37 | { 38 | if (((DictionaryBoolean*)parentDictionaryObject)->hasDefaultValue()) 39 | objectValue = ((DictionaryBoolean*)parentDictionaryObject)->getDefaultValue(); 40 | }; -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Body/DataTypes/usdsDouble.cpp: -------------------------------------------------------------------------------- 1 | #include "body\dataTypes\usdsDouble.h" 2 | 3 | #include "dictionary\dataTypes\dictionaryDouble.h" 4 | 5 | using namespace usds; 6 | 7 | UsdsDouble::UsdsDouble(Body* parent_body) : UsdsBaseType(parent_body) 8 | { 9 | 10 | } 11 | 12 | UsdsDouble::~UsdsDouble() 13 | { 14 | } 15 | 16 | 17 | void UsdsDouble::additionalInitObject() 18 | { 19 | if (((DictionaryDouble*)parentDictionaryObject)->hasDefaultValue()) 20 | objectValue = ((DictionaryDouble*)parentDictionaryObject)->getDefaultValue(); 21 | }; 22 | 23 | void UsdsDouble::setValue(float value) throw (...) 24 | { 25 | objectValue = value; 26 | }; 27 | 28 | void UsdsDouble::setValue(double value) throw (...) 29 | { 30 | objectValue = value; 31 | }; 32 | 33 | void UsdsDouble::getValue(double* value) throw (...) 34 | { 35 | 36 | *value = objectValue; 37 | }; 38 | 39 | void UsdsDouble::set(double value) throw (...) 40 | { 41 | objectValue = value; 42 | }; 43 | 44 | double UsdsDouble::get() 45 | { 46 | return objectValue; 47 | } 48 | 49 | bool UsdsDouble::isBigendian() 50 | { 51 | return ((DictionaryDouble*)parentDictionaryObject)->getBigendian(); 52 | } 53 | 54 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Body/DataTypes/usdsFloat.cpp: -------------------------------------------------------------------------------- 1 | #include "body\dataTypes\usdsFloat.h" 2 | 3 | #include "dictionary\dataTypes\dictionaryFloat.h" 4 | 5 | using namespace usds; 6 | 7 | UsdsFloat::UsdsFloat(Body* parent_body) : UsdsBaseType(parent_body) 8 | { 9 | 10 | } 11 | 12 | UsdsFloat::~UsdsFloat() 13 | { 14 | } 15 | 16 | void UsdsFloat::additionalInitObject() 17 | { 18 | if (((DictionaryFloat*)parentDictionaryObject)->hasDefaultValue()) 19 | objectValue = ((DictionaryFloat*)parentDictionaryObject)->getDefaultValue(); 20 | }; 21 | 22 | void UsdsFloat::setValue(float value) throw (...) 23 | { 24 | objectValue = value; 25 | }; 26 | 27 | void UsdsFloat::getValue(double* value) throw (...) 28 | { 29 | 30 | *value = objectValue; 31 | }; 32 | 33 | void UsdsFloat::getValue(float* value) throw (...) 34 | { 35 | 36 | *value = objectValue; 37 | }; 38 | 39 | void UsdsFloat::set(float value) throw (...) 40 | { 41 | objectValue = value; 42 | }; 43 | 44 | float UsdsFloat::get() 45 | { 46 | return objectValue; 47 | } 48 | 49 | bool UsdsFloat::isBigendian() 50 | { 51 | return ((DictionaryFloat*)parentDictionaryObject)->getBigendian(); 52 | } 53 | 54 | 55 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Body/DataTypes/usdsInt.cpp: -------------------------------------------------------------------------------- 1 | #include "body\dataTypes\usdsInt.h" 2 | 3 | #include "dictionary\dataTypes\dictionaryInt.h" 4 | 5 | using namespace usds; 6 | 7 | UsdsInt::UsdsInt(Body* parent_body) : UsdsBaseType(parent_body) 8 | { 9 | 10 | } 11 | 12 | UsdsInt::~UsdsInt() 13 | { 14 | } 15 | 16 | void UsdsInt::additionalInitObject() 17 | { 18 | if (((DictionaryInt*)parentDictionaryObject)->hasDefaultValue()) 19 | objectValue = ((DictionaryInt*)parentDictionaryObject)->getDefaultValue(); 20 | }; 21 | 22 | void UsdsInt::setValue(int8_t value) throw (...) 23 | { 24 | 25 | objectValue = value; 26 | }; 27 | 28 | void UsdsInt::setValue(uint8_t value) throw (...) 29 | { 30 | 31 | objectValue = value; 32 | }; 33 | 34 | void UsdsInt::setValue(int16_t value) throw (...) 35 | { 36 | 37 | objectValue = value; 38 | }; 39 | 40 | void UsdsInt::setValue(uint16_t value) throw (...) 41 | { 42 | 43 | objectValue = value; 44 | }; 45 | 46 | void UsdsInt::setValue(int32_t value) throw (...) 47 | { 48 | 49 | objectValue = value; 50 | }; 51 | 52 | void UsdsInt::setValue(uint32_t value) throw (...) 53 | try 54 | { 55 | usdsTypeWrite(value, USDS_INT,(uint8_t*)(&objectValue)); 56 | } 57 | catch (ErrorStack& err) 58 | { 59 | err.addLevel("UsdsInt::setValue") << value; 60 | throw; 61 | }; 62 | 63 | void UsdsInt::setValue(int64_t value) throw (...) 64 | try 65 | { 66 | usdsTypeWrite(value, USDS_INT, (uint8_t*)(&objectValue)); 67 | } 68 | catch (ErrorStack& err) 69 | { 70 | err.addLevel("UsdsInt::setValue") << value; 71 | throw; 72 | }; 73 | 74 | void UsdsInt::setValue(uint64_t value) throw (...) 75 | try 76 | { 77 | usdsTypeWrite(value, USDS_INT, (uint8_t*)(&objectValue)); 78 | } 79 | catch (ErrorStack& err) 80 | { 81 | err.addLevel("UsdsInt::setValue") << value; 82 | throw; 83 | }; 84 | 85 | int32_t UsdsInt::get() 86 | { 87 | return objectValue; 88 | }; 89 | 90 | void UsdsInt::set(int32_t value) 91 | { 92 | objectValue = value; 93 | }; 94 | 95 | 96 | void UsdsInt::getValue(int8_t* value) throw (...) 97 | try 98 | { 99 | usdsTypeRead((uint8_t*)&objectValue, USDS_INT, value); 100 | } 101 | catch (ErrorStack& err) 102 | { 103 | err.addLevel("UsdsInt::getValue") << value; 104 | throw; 105 | }; 106 | 107 | void UsdsInt::getValue(uint8_t* value) throw (...) 108 | try 109 | { 110 | usdsTypeRead((uint8_t*)&objectValue, USDS_INT, value); 111 | } 112 | catch (ErrorStack& err) 113 | { 114 | err.addLevel("UsdsInt::getValue") << value; 115 | throw; 116 | }; 117 | 118 | void UsdsInt::getValue(int16_t* value) throw (...) 119 | try 120 | { 121 | usdsTypeRead((uint8_t*)&objectValue, USDS_INT, value); 122 | } 123 | catch (ErrorStack& err) 124 | { 125 | err.addLevel("UsdsInt::getValue") << value; 126 | throw; 127 | }; 128 | 129 | void UsdsInt::getValue(uint16_t* value) throw (...) 130 | try 131 | { 132 | usdsTypeRead((uint8_t*)&objectValue, USDS_INT, value); 133 | } 134 | catch (ErrorStack& err) 135 | { 136 | err.addLevel("UsdsInt::getValue") << value; 137 | throw; 138 | }; 139 | 140 | void UsdsInt::getValue(int32_t* value) throw (...) 141 | { 142 | *value = objectValue; 143 | }; 144 | 145 | void UsdsInt::getValue(uint32_t* value) throw (...) 146 | try 147 | { 148 | usdsTypeRead((uint8_t*)&objectValue, USDS_INT, value); 149 | } 150 | catch (ErrorStack& err) 151 | { 152 | err.addLevel("UsdsInt::getValue") << value; 153 | throw; 154 | }; 155 | 156 | void UsdsInt::getValue(int64_t* value) throw (...) 157 | { 158 | *value = objectValue; 159 | }; 160 | 161 | void UsdsInt::getValue(uint64_t* value) throw (...) 162 | try 163 | { 164 | usdsTypeRead((uint8_t*)&objectValue, USDS_INT, value); 165 | } 166 | catch (ErrorStack& err) 167 | { 168 | err.addLevel("UsdsInt::getValue") << value; 169 | throw; 170 | }; 171 | 172 | bool UsdsInt::isBigendian() 173 | { 174 | return ((DictionaryInt*)parentDictionaryObject)->getBigendian(); 175 | } 176 | 177 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Body/DataTypes/usdsLong.cpp: -------------------------------------------------------------------------------- 1 | #include "body\dataTypes\usdsLong.h" 2 | 3 | #include "dictionary\dataTypes\dictionaryLong.h" 4 | 5 | using namespace usds; 6 | 7 | UsdsLong::UsdsLong(Body* parent_body) : UsdsBaseType(parent_body) 8 | { 9 | 10 | } 11 | 12 | UsdsLong::~UsdsLong() 13 | { 14 | 15 | } 16 | 17 | void UsdsLong::additionalInitObject() 18 | { 19 | if (((DictionaryLong*)parentDictionaryObject)->hasDefaultValue()) 20 | objectValue = ((DictionaryLong*)parentDictionaryObject)->getDefaultValue(); 21 | }; 22 | 23 | void UsdsLong::setValue(int8_t value) throw (...) 24 | { 25 | 26 | objectValue = value; 27 | }; 28 | 29 | void UsdsLong::setValue(uint8_t value) throw (...) 30 | { 31 | 32 | objectValue = value; 33 | }; 34 | 35 | void UsdsLong::setValue(int16_t value) throw (...) 36 | { 37 | 38 | objectValue = value; 39 | }; 40 | 41 | void UsdsLong::setValue(uint16_t value) throw (...) 42 | { 43 | 44 | objectValue = value; 45 | }; 46 | 47 | void UsdsLong::setValue(int32_t value) throw (...) 48 | { 49 | 50 | objectValue = value; 51 | }; 52 | 53 | void UsdsLong::setValue(uint32_t value) throw (...) 54 | { 55 | 56 | objectValue = value; 57 | }; 58 | 59 | void UsdsLong::setValue(int64_t value) throw (...) 60 | { 61 | objectValue = value; 62 | }; 63 | 64 | void UsdsLong::setValue(uint64_t value) throw (...) 65 | try 66 | { 67 | usdsTypeWrite(value, USDS_LONG, (uint8_t*)(&objectValue)); 68 | } 69 | catch (ErrorStack& err) 70 | { 71 | err.addLevel("UsdsLong::setValue") << value; 72 | throw; 73 | }; 74 | 75 | int64_t UsdsLong::get() 76 | { 77 | return objectValue; 78 | }; 79 | 80 | void UsdsLong::set(int64_t value) 81 | { 82 | objectValue = value; 83 | }; 84 | 85 | 86 | void UsdsLong::getValue(int8_t* value) throw (...) 87 | try 88 | { 89 | usdsTypeRead((uint8_t*)&objectValue, USDS_LONG, value); 90 | } 91 | catch (ErrorStack& err) 92 | { 93 | err.addLevel("UsdsLong::getValue") << value; 94 | throw; 95 | }; 96 | 97 | void UsdsLong::getValue(uint8_t* value) throw (...) 98 | try 99 | { 100 | usdsTypeRead((uint8_t*)&objectValue, USDS_LONG, value); 101 | } 102 | catch (ErrorStack& err) 103 | { 104 | err.addLevel("UsdsLong::getValue") << value; 105 | throw; 106 | }; 107 | 108 | void UsdsLong::getValue(int16_t* value) throw (...) 109 | try 110 | { 111 | usdsTypeRead((uint8_t*)&objectValue, USDS_LONG, value); 112 | } 113 | catch (ErrorStack& err) 114 | { 115 | err.addLevel("UsdsLong::getValue") << value; 116 | throw; 117 | }; 118 | 119 | void UsdsLong::getValue(uint16_t* value) throw (...) 120 | try 121 | { 122 | usdsTypeRead((uint8_t*)&objectValue, USDS_LONG, value); 123 | } 124 | catch (ErrorStack& err) 125 | { 126 | err.addLevel("UsdsLong::getValue") << value; 127 | throw; 128 | }; 129 | 130 | void UsdsLong::getValue(int32_t* value) throw (...) 131 | try 132 | { 133 | usdsTypeRead((uint8_t*)&objectValue, USDS_LONG, value); 134 | } 135 | catch (ErrorStack& err) 136 | { 137 | err.addLevel("UsdsLong::getValue") << value; 138 | throw; 139 | }; 140 | 141 | void UsdsLong::getValue(uint32_t* value) throw (...) 142 | try 143 | { 144 | usdsTypeRead((uint8_t*)&objectValue, USDS_LONG, value); 145 | } 146 | catch (ErrorStack& err) 147 | { 148 | err.addLevel("UsdsLong::getValue") << value; 149 | throw; 150 | }; 151 | 152 | void UsdsLong::getValue(int64_t* value) throw (...) 153 | { 154 | *value = objectValue; 155 | }; 156 | 157 | void UsdsLong::getValue(uint64_t* value) throw (...) 158 | try 159 | { 160 | usdsTypeRead((uint8_t*)&objectValue, USDS_LONG, value); 161 | } 162 | catch (ErrorStack& err) 163 | { 164 | err.addLevel("UsdsLong::getValue") << value; 165 | throw; 166 | }; 167 | 168 | bool UsdsLong::isBigendian() 169 | { 170 | return ((DictionaryLong*)parentDictionaryObject)->getBigendian(); 171 | } 172 | 173 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Body/DataTypes/usdsUByte.cpp: -------------------------------------------------------------------------------- 1 | #include "body\dataTypes\usdsUByte.h" 2 | 3 | #include "dictionary/dataTypes/dictionaryUByte.h" 4 | 5 | using namespace usds; 6 | 7 | UsdsUByte::UsdsUByte(Body* parent_body) : UsdsBaseType(parent_body) 8 | { 9 | 10 | } 11 | 12 | UsdsUByte::~UsdsUByte() 13 | { 14 | } 15 | 16 | void UsdsUByte::additionalInitObject() 17 | { 18 | if (((DictionaryUByte*)parentDictionaryObject)->hasDefaultValue()) 19 | objectValue = ((DictionaryUByte*)parentDictionaryObject)->getDefaultValue(); 20 | }; 21 | 22 | void UsdsUByte::setValue(int8_t value) throw (...) 23 | try 24 | { 25 | usdsTypeWrite(value, USDS_UBYTE, (uint8_t*)(&objectValue)); 26 | } 27 | catch (ErrorStack& err) 28 | { 29 | err.addLevel("UsdsUByte::setValue") << value; 30 | throw; 31 | }; 32 | 33 | void UsdsUByte::setValue(uint8_t value) throw (...) 34 | { 35 | objectValue = value; 36 | } 37 | 38 | void UsdsUByte::setValue(int16_t value) throw (...) 39 | try 40 | { 41 | usdsTypeWrite(value, USDS_UBYTE, (uint8_t*)(&objectValue)); 42 | } 43 | catch (ErrorStack& err) 44 | { 45 | err.addLevel("UsdsUByte::setValue") << value; 46 | throw; 47 | }; 48 | 49 | void UsdsUByte::setValue(uint16_t value) throw (...) 50 | try 51 | { 52 | usdsTypeWrite(value, USDS_UBYTE, (uint8_t*)(&objectValue)); 53 | } 54 | catch (ErrorStack& err) 55 | { 56 | err.addLevel("UsdsUByte::setValue") << value; 57 | throw; 58 | }; 59 | 60 | void UsdsUByte::setValue(int32_t value) throw (...) 61 | try 62 | { 63 | usdsTypeWrite(value, USDS_UBYTE, (uint8_t*)(&objectValue)); 64 | } 65 | catch (ErrorStack& err) 66 | { 67 | err.addLevel("UsdsUByte::setValue") << value; 68 | throw; 69 | }; 70 | 71 | void UsdsUByte::setValue(uint32_t value) throw (...) 72 | try 73 | { 74 | usdsTypeWrite(value, USDS_UBYTE, (uint8_t*)(&objectValue)); 75 | } 76 | catch (ErrorStack& err) 77 | { 78 | err.addLevel("UsdsUByte::setValue") << value; 79 | throw; 80 | }; 81 | 82 | void UsdsUByte::setValue(int64_t value) throw (...) 83 | try 84 | { 85 | usdsTypeWrite(value, USDS_UBYTE, (uint8_t*)(&objectValue)); 86 | } 87 | catch (ErrorStack& err) 88 | { 89 | err.addLevel("UsdsUByte::setValue") << value; 90 | throw; 91 | }; 92 | 93 | void UsdsUByte::setValue(uint64_t value) throw (...) 94 | try 95 | { 96 | usdsTypeWrite(value, USDS_UBYTE, (uint8_t*)(&objectValue)); 97 | } 98 | catch (ErrorStack& err) 99 | { 100 | err.addLevel("UsdsUByte::setValue") << value; 101 | throw; 102 | }; 103 | 104 | uint8_t UsdsUByte::get() 105 | { 106 | return objectValue; 107 | }; 108 | 109 | void UsdsUByte::set(uint8_t value) 110 | { 111 | objectValue = value; 112 | }; 113 | 114 | 115 | void UsdsUByte::getValue(int8_t* value) throw (...) 116 | try 117 | { 118 | usdsTypeRead((uint8_t*)&objectValue, USDS_UBYTE, value); 119 | } 120 | catch (ErrorStack& err) 121 | { 122 | err.addLevel("UsdsUByte::getValue") << value; 123 | throw; 124 | }; 125 | 126 | void UsdsUByte::getValue(uint8_t* value) throw (...) 127 | { 128 | *value = objectValue; 129 | }; 130 | 131 | void UsdsUByte::getValue(int16_t* value) throw (...) 132 | { 133 | *value = objectValue; 134 | }; 135 | 136 | void UsdsUByte::getValue(uint16_t* value) throw (...) 137 | { 138 | *value = objectValue; 139 | }; 140 | 141 | void UsdsUByte::getValue(int32_t* value) throw (...) 142 | { 143 | *value = objectValue; 144 | }; 145 | 146 | void UsdsUByte::getValue(uint32_t* value) throw (...) 147 | { 148 | *value = objectValue; 149 | }; 150 | 151 | void UsdsUByte::getValue(int64_t* value) throw (...) 152 | { 153 | *value = objectValue; 154 | }; 155 | 156 | void UsdsUByte::getValue(uint64_t* value) throw (...) 157 | { 158 | *value = objectValue; 159 | }; 160 | 161 | 162 | 163 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Body/DataTypes/usdsVarint.cpp: -------------------------------------------------------------------------------- 1 | #include "body\dataTypes\usdsVarint.h" 2 | 3 | #include "dictionary/dataTypes/dictionaryVarint.h" 4 | 5 | using namespace usds; 6 | 7 | UsdsVarint::UsdsVarint(Body* parent_body) : UsdsBaseType(parent_body) 8 | { 9 | 10 | } 11 | 12 | UsdsVarint::~UsdsVarint() 13 | { 14 | } 15 | 16 | void UsdsVarint::additionalInitObject() 17 | { 18 | if (((DictionaryVarint*)parentDictionaryObject)->hasDefaultValue()) 19 | objectValue = ((DictionaryVarint*)parentDictionaryObject)->getDefaultValue(); 20 | }; 21 | 22 | void UsdsVarint::setValue(int8_t value) throw (...) 23 | { 24 | 25 | objectValue = value; 26 | }; 27 | 28 | void UsdsVarint::setValue(uint8_t value) throw (...) 29 | { 30 | 31 | objectValue = value; 32 | }; 33 | 34 | void UsdsVarint::setValue(int16_t value) throw (...) 35 | { 36 | 37 | objectValue = value; 38 | }; 39 | 40 | void UsdsVarint::setValue(uint16_t value) throw (...) 41 | { 42 | 43 | objectValue = value; 44 | }; 45 | 46 | void UsdsVarint::setValue(int32_t value) throw (...) 47 | { 48 | 49 | objectValue = value; 50 | }; 51 | 52 | void UsdsVarint::setValue(uint32_t value) throw (...) 53 | { 54 | 55 | objectValue = value; 56 | }; 57 | 58 | void UsdsVarint::setValue(int64_t value) throw (...) 59 | { 60 | objectValue = value; 61 | }; 62 | 63 | void UsdsVarint::setValue(uint64_t value) throw (...) 64 | try 65 | { 66 | usdsTypeWrite(value, USDS_LONG, (uint8_t*)(&objectValue)); 67 | } 68 | catch (ErrorStack& err) 69 | { 70 | err.addLevel("UsdsVarint::setValue") << value; 71 | throw; 72 | }; 73 | 74 | int64_t UsdsVarint::get() 75 | { 76 | return objectValue; 77 | }; 78 | 79 | void UsdsVarint::set(int64_t value) 80 | { 81 | objectValue = value; 82 | }; 83 | 84 | 85 | void UsdsVarint::getValue(int8_t* value) throw (...) 86 | try 87 | { 88 | usdsTypeRead((uint8_t*)&objectValue, USDS_LONG, value); 89 | } 90 | catch (ErrorStack& err) 91 | { 92 | err.addLevel("UsdsVarint::getValue") << value; 93 | throw; 94 | }; 95 | 96 | void UsdsVarint::getValue(uint8_t* value) throw (...) 97 | try 98 | { 99 | usdsTypeRead((uint8_t*)&objectValue, USDS_LONG, value); 100 | } 101 | catch (ErrorStack& err) 102 | { 103 | err.addLevel("UsdsVarint::getValue") << value; 104 | throw; 105 | }; 106 | 107 | void UsdsVarint::getValue(int16_t* value) throw (...) 108 | try 109 | { 110 | usdsTypeRead((uint8_t*)&objectValue, USDS_LONG, value); 111 | } 112 | catch (ErrorStack& err) 113 | { 114 | err.addLevel("UsdsVarint::getValue") << value; 115 | throw; 116 | }; 117 | 118 | void UsdsVarint::getValue(uint16_t* value) throw (...) 119 | try 120 | { 121 | usdsTypeRead((uint8_t*)&objectValue, USDS_LONG, value); 122 | } 123 | catch (ErrorStack& err) 124 | { 125 | err.addLevel("UsdsVarint::getValue") << value; 126 | throw; 127 | }; 128 | 129 | void UsdsVarint::getValue(int32_t* value) throw (...) 130 | try 131 | { 132 | usdsTypeRead((uint8_t*)&objectValue, USDS_LONG, value); 133 | } 134 | catch (ErrorStack& err) 135 | { 136 | err.addLevel("UsdsVarint::getValue") << value; 137 | throw; 138 | }; 139 | 140 | void UsdsVarint::getValue(uint32_t* value) throw (...) 141 | try 142 | { 143 | usdsTypeRead((uint8_t*)&objectValue, USDS_LONG, value); 144 | } 145 | catch (ErrorStack& err) 146 | { 147 | err.addLevel("UsdsVarint::getValue") << value; 148 | throw; 149 | }; 150 | 151 | void UsdsVarint::getValue(int64_t* value) throw (...) 152 | { 153 | *value = objectValue; 154 | }; 155 | 156 | void UsdsVarint::getValue(uint64_t* value) throw (...) 157 | try 158 | { 159 | usdsTypeRead((uint8_t*)&objectValue, USDS_LONG, value); 160 | } 161 | catch (ErrorStack& err) 162 | { 163 | err.addLevel("UsdsVarint::getValue") << value; 164 | throw; 165 | }; 166 | 167 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Body/usdsBody.cpp: -------------------------------------------------------------------------------- 1 | #include "body\usdsBody.h" 2 | 3 | #include "dictionary\usdsDictionary.h" 4 | 5 | #include "dictionary\dataTypes\dictionaryArray.h" 6 | #include "dictionary\dataTypes\dictionaryBoolean.h" 7 | #include "dictionary\dataTypes\dictionaryDouble.h" 8 | #include "dictionary\dataTypes\dictionaryInt.h" 9 | #include "dictionary\dataTypes\dictionaryLong.h" 10 | #include "dictionary\dataTypes\dictionaryString.h" 11 | #include "dictionary\dataTypes\dictionaryUVarint.h" 12 | #include "dictionary\dataTypes\dictionaryStruct.h" 13 | 14 | using namespace usds; 15 | 16 | Body::Body() : objectPool(this) 17 | { 18 | firstTag = 0; 19 | lastTag = 0; 20 | }; 21 | 22 | Body::~Body() 23 | { 24 | 25 | 26 | }; 27 | 28 | //============================================================================================ 29 | // Body construction 30 | 31 | UsdsBaseType* Body::addTag(DictionaryBaseType* dict_tag) throw(...) 32 | try 33 | { 34 | if (dict_tag == 0) 35 | throw ErrorMessage(BODY__NULL_DICTIONARY_TAG, "Tag can not be NULL"); 36 | 37 | if (dict_tag->getRootStatus() == false ) 38 | throw ErrorMessage(BODY__NOT_ROOT_TAG, "Tag '") << dict_tag->getName() << "' is not root"; 39 | 40 | UsdsBaseType* tag = objectPool.addObject(dict_tag, 0); 41 | connectTagToBody(tag); 42 | 43 | return tag; 44 | } 45 | catch (ErrorMessage& msg) 46 | { 47 | throw ErrorStack("Body::addTag") << (void*)dict_tag << msg; 48 | } 49 | catch (ErrorStack& err) 50 | { 51 | err.addLevel("Body::addTag") << (void*)dict_tag; 52 | throw; 53 | }; 54 | 55 | UsdsBaseType* Body::addField(DictionaryBaseType* dict_field, UsdsBaseType* parent_tag) throw(...) 56 | try 57 | { 58 | if (parent_tag == 0) 59 | throw ErrorMessage(BODY__NULL_PARENT_TAG, "Parent tag can not be NULL"); 60 | 61 | return objectPool.addObject(dict_field, parent_tag); 62 | } 63 | catch (ErrorMessage& msg) 64 | { 65 | throw ErrorStack("Body::addField") << (void*)dict_field << (void*)parent_tag << msg; 66 | } 67 | catch (ErrorStack& err) 68 | { 69 | err.addLevel("Body::addField") << (void*)dict_field << (void*)parent_tag; 70 | throw; 71 | }; 72 | 73 | 74 | //============================================================================================ 75 | 76 | UsdsBaseType* Body::getFirstTag() throw(...) 77 | { 78 | return firstTag; 79 | 80 | }; 81 | 82 | UsdsBaseType* Body::getFirstTag(int32_t tag_id) throw(...) 83 | try 84 | { 85 | UsdsBaseType* tag = firstTag; 86 | while (tag != 0) 87 | { 88 | if (tag->getID() == tag_id) 89 | return tag; 90 | tag = tag->getNext(); 91 | } 92 | 93 | throw ErrorMessage(BODY__TAG_NOT_FOUND) << "Tag id=" << tag_id << " not found in ROOT level"; 94 | 95 | return 0; 96 | } 97 | catch (ErrorMessage& msg) 98 | { 99 | throw ErrorStack("Body::getFirstTag") << tag_id << msg; 100 | } 101 | catch (ErrorStack& err) 102 | { 103 | err.addLevel("Body::getFirstTag") << tag_id; 104 | throw; 105 | }; 106 | 107 | //============================================================================================ 108 | void Body::clear() 109 | { 110 | objectPool.clear(); 111 | 112 | firstTag = 0; 113 | lastTag = 0; 114 | 115 | }; 116 | 117 | //==================================================================================================================== 118 | // private 119 | 120 | void Body::connectTagToBody(UsdsBaseType* tag) 121 | { 122 | if (firstTag == 0) 123 | firstTag = tag; 124 | tag->setPrevious(lastTag); 125 | tag->setNext(0); 126 | if (lastTag != 0) 127 | lastTag->setNext(tag); 128 | lastTag = tag; 129 | }; -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Common/objectPool.cpp: -------------------------------------------------------------------------------- 1 | #include "common\objectPool.h" 2 | 3 | using namespace usds; 4 | 5 | BasePoolObject::BasePoolObject() 6 | { 7 | 8 | } 9 | 10 | BasePoolObject::~BasePoolObject() 11 | { 12 | 13 | } 14 | 15 | void BasePoolObject::remove() 16 | { 17 | parentPool->removeObject(this); 18 | }; 19 | 20 | //==================================================================== 21 | 22 | BasePoolClass::BasePoolClass() 23 | { 24 | firstElement = 0; 25 | firstReservedElement = 0; 26 | lastElement = 0; 27 | } 28 | 29 | BasePoolClass::~BasePoolClass() 30 | { 31 | BasePoolObject* object = firstElement; 32 | BasePoolObject* next; 33 | while (object != 0) 34 | { 35 | next = object->nextInPool; 36 | delete object; 37 | object = next; 38 | } 39 | } 40 | 41 | BasePoolObject* BasePoolClass::addObject() throw(...) 42 | { 43 | BasePoolObject* object; 44 | // If pool is empty 45 | if (firstElement == 0) 46 | { 47 | object = createObject(); 48 | firstElement = object; 49 | lastElement = object; 50 | object->nextInPool = 0; 51 | object->previousInPool = 0; 52 | object->parentPool = this; 53 | 54 | return object; 55 | } 56 | // If all Pool is already used 57 | if (firstReservedElement == 0) 58 | { 59 | object = createObject(); 60 | lastElement->nextInPool = object; 61 | object->nextInPool = 0; 62 | object->previousInPool = lastElement; 63 | object->parentPool = this; 64 | lastElement = object; 65 | return object; 66 | } 67 | else 68 | { 69 | object = firstReservedElement; 70 | firstReservedElement = object->nextInPool; 71 | return object; 72 | } 73 | }; 74 | 75 | BasePoolObject* BasePoolClass::getFirstElement() 76 | { 77 | return firstElement; 78 | } 79 | 80 | BasePoolObject* BasePoolClass::getLastElement() 81 | { 82 | return lastElement; 83 | } 84 | 85 | BasePoolObject* BasePoolClass::getLastAllocatedElement() 86 | { 87 | if (firstReservedElement == 0) 88 | return lastElement; 89 | else 90 | return firstReservedElement->previousInPool; 91 | } 92 | 93 | BasePoolObject* BasePoolClass::getNextElement(BasePoolObject* object) 94 | { 95 | return object->nextInPool; 96 | 97 | }; 98 | 99 | BasePoolObject* BasePoolClass::getPreviousElement(BasePoolObject* object) 100 | { 101 | 102 | return object->previousInPool; 103 | }; 104 | 105 | void BasePoolClass::clearPool() 106 | { 107 | firstReservedElement = firstElement; 108 | }; 109 | 110 | size_t BasePoolClass::getFullSize() 111 | { 112 | size_t size = 0; 113 | BasePoolObject* object = firstElement; 114 | while (object != 0) 115 | { 116 | size++; 117 | object = object->nextInPool; 118 | } 119 | return size; 120 | } 121 | 122 | size_t BasePoolClass::getAllocatedSize() 123 | { 124 | size_t size = 0; 125 | BasePoolObject* object = firstElement; 126 | while (object != firstReservedElement) 127 | { 128 | size++; 129 | object = object->nextInPool; 130 | } 131 | return size; 132 | } 133 | 134 | void BasePoolClass::removeObject(BasePoolObject* object) 135 | { 136 | // If error - do nothing 137 | if (firstReservedElement == object) 138 | return; 139 | // If it's last element in pool 140 | if (object->nextInPool == 0) 141 | { 142 | // If there is no reserved elements in pool 143 | if (firstReservedElement == 0) 144 | firstReservedElement = object; 145 | // Else - Error, but do nothing 146 | return; 147 | } 148 | // Else - move object to the back 149 | // Step 1: remove from Pool 150 | if (object->previousInPool != 0) 151 | object->previousInPool->nextInPool = object->nextInPool; 152 | else 153 | firstElement = object->nextInPool; 154 | object->nextInPool->previousInPool = object->previousInPool; 155 | // Step 2: Put to the back 156 | lastElement->nextInPool = object; 157 | object->previousInPool = lastElement; 158 | object->nextInPool = 0; 159 | lastElement = object; 160 | 161 | } -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Converters/DictionaryTextParser/flexDictionaryTextScanner.h: -------------------------------------------------------------------------------- 1 | #ifndef FLEX_DICTIONARY_TEXT_SCANNER 2 | #define FLEX_DICTIONARY_TEXT_SCANNER 3 | 4 | #include "dictionary\usdsDictionary.h" 5 | 6 | #if ! defined(yyFlexLexerOnce) 7 | #include 8 | #endif 9 | #undef YY_DECL 10 | #define YY_DECL int FlexDictionaryTextScanner::scan(BisonDictionaryTextParser::semantic_type * yylval, BisonDictionaryTextParser::location_type* yylloc) 11 | #include "bisonDictionaryTextParser.hh" 12 | 13 | #include 14 | 15 | namespace usds 16 | { 17 | class FlexDictionaryTextScanner : public yyFlexLexer 18 | { 19 | public: 20 | FlexDictionaryTextScanner(std::stringstream* input, std::stringstream* output) : yyFlexLexer(input, output) { offset = 0; }; 21 | ~FlexDictionaryTextScanner() {}; 22 | 23 | virtual int scan(BisonDictionaryTextParser::semantic_type * yylval, BisonDictionaryTextParser::location_type* yylloc); 24 | 25 | }; 26 | 27 | 28 | }; 29 | #endif -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Converters/DictionaryTextParser/updateBisonOutput.py: -------------------------------------------------------------------------------- 1 | import io 2 | import re 3 | 4 | f = io.open("position.hh", 'r', encoding='utf8') 5 | lines = [] 6 | for line in f: 7 | lines.append(line) 8 | if line == " /// Compute max(min, lhs+rhs) (provided min <= lhs).\n": 9 | lines.append(u"#pragma warning(disable:4146)\n") 10 | 11 | f.close() 12 | 13 | f_out = io.open("position.hh", 'w', encoding='utf8') 14 | for line in lines: 15 | f_out.write(line) 16 | 17 | f_out.close() 18 | 19 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Converters/DictionaryTextParser/usdsDictionaryTextParser.cpp: -------------------------------------------------------------------------------- 1 | #include "converters\usdsDictionaryTextParser.h" 2 | #include "flexDictionaryTextScanner.h" 3 | 4 | #include "dictionary\usdsDictionary.h" 5 | 6 | #include 7 | 8 | 9 | using namespace usds; 10 | 11 | void DictionaryTextParser::parse(const char* text_dict, usdsEncode encode, Dictionary* dict) throw (...) 12 | try 13 | { 14 | if (encode != USDS_UTF8) 15 | throw ErrorMessage(DICTIONARY_TEXT_PARSER__UNSUPPORTABLE_ENCODE, "Unsupportable encode for text dictionary: ") << encode; 16 | 17 | // remove UTF-8 BOM 18 | if (text_dict[0] == '\xEF' && text_dict[1] == '\xBB' && text_dict[2] == '\xBF') 19 | text_dict = text_dict + 3; 20 | 21 | // Creating scanner and parser 22 | std::stringstream input; 23 | std::stringstream output; 24 | input << text_dict; 25 | FlexDictionaryTextScanner scanner(&input, &output); 26 | 27 | BisonDictionaryTextParser textParser(text_dict, dict, &scanner, 0, 0); 28 | // Parse! 29 | textParser.parse(); 30 | } 31 | catch (ErrorMessage& msg) 32 | { 33 | throw ErrorStack("DictionaryTextParser::parse") << (void*)text_dict << encode << (void*)dict << msg; 34 | } 35 | catch (ErrorStack& err) 36 | { 37 | err.addLevel("DictionaryTextParser::parse") << (void*)text_dict << encode << (void*)dict; 38 | throw; 39 | } -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Converters/DictionaryTextParser/win_create_parser.bat: -------------------------------------------------------------------------------- 1 | echo off 2 | win_bison.exe -d -o bisonDictionaryTextParser.cc bisonDictionaryTextParser.y 3 | python updateBisonOutput.py 4 | win_flex.exe -o flexDictionaryTextScanner.cpp flexDictionaryTextScanner.l -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Converters/usdsBinaryCreator.cpp: -------------------------------------------------------------------------------- 1 | #include "converters\usdsBinaryCreator.h" 2 | #include "binary\usdsBinaryOutput.h" 3 | #include "dictionary\usdsDictionary.h" 4 | 5 | #include "usdsTypes.h" 6 | #include "usdsErrors.h" 7 | 8 | using namespace usds; 9 | 10 | BinaryCreator::BinaryCreator() 11 | { 12 | 13 | }; 14 | 15 | BinaryCreator::~BinaryCreator() 16 | { 17 | 18 | }; 19 | 20 | void BinaryCreator::generate(BinaryOutput* buff, Dictionary* dict, Body* body) throw(...) 21 | try 22 | { 23 | binary = buff; 24 | dictionary = dict; 25 | 26 | size_t dict_size = 0; 27 | const uint8_t* dict_binary = dict->getBinary(&dict_size); 28 | binary->writeSignature(USDS_DICTIONARY_SIGNATURE_WITH_SIZE); 29 | binary->writeUVarint(dict_size); 30 | binary->writeByteArray(dict_binary, dict_size); 31 | 32 | binary->writeSignature(USDS_BODY_SIGNATURE); 33 | bodyBinaryCreator.generate(binary, body); 34 | 35 | addHeadToBinary(); 36 | } 37 | catch (ErrorStack& err) 38 | { 39 | err.addLevel("BinaryCreator::generate") << (void*)buff << (void*)dict << (void*)body; 40 | throw; 41 | }; 42 | 43 | void BinaryCreator::addHeadToBinary() throw(...) 44 | try 45 | { 46 | // add document size 47 | binary->pushFrontSize(); 48 | 49 | // add head 50 | binary->pushFrontUByte(dictionary->getMinorVersion()); 51 | binary->pushFrontUByte(dictionary->getMajorVersion()); 52 | binary->pushFrontUInt(dictionary->getDictionaryID()); 53 | binary->pushFrontSignature(USDS_MINOR_VERSION); 54 | binary->pushFrontSignature(USDS_MAJOR_VERSION); 55 | binary->pushFrontSignature(USDS_MINOR_SIGNATURE); 56 | binary->pushFrontSignature(USDS_MAJOR_SIGNATURE); 57 | } 58 | catch (ErrorStack& err) 59 | { 60 | err.addLevel("BinaryCreator::addHeadToBinary"); 61 | throw; 62 | }; -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Dictionary/DataTypes/dictionaryArray.cpp: -------------------------------------------------------------------------------- 1 | #include "dictionary\dataTypes\dictionaryArray.h" 2 | #include "dictionary\dataTypes\dictionaryTagLink.h" 3 | #include "dictionary\usdsDictionary.h" 4 | 5 | using namespace usds; 6 | 7 | DictionaryArray::DictionaryArray(Dictionary* dict) : DictionaryBaseType(dict) 8 | { 9 | 10 | }; 11 | 12 | void DictionaryArray::additionalInitType() 13 | { 14 | element = 0; 15 | 16 | }; 17 | 18 | DictionaryBaseType* DictionaryArray::setElementType(usdsType type_id) throw (...) 19 | try 20 | { 21 | if (element != 0) 22 | throw ErrorMessage(DIC_ARRAY__ALREADY_INITIALIZED, "Element's type is already initialized"); 23 | if (type_id < usds::USDS_TAG || type_id >= usds::USDS_LAST_TYPE) 24 | throw ErrorMessage(DIC_ARRAY__ERROR_ELEMENT_TYPE, "Unsupported type for array's element: '") << type_id << "'. Use [USDS_TAG, USDS_FUNCTION]."; 25 | 26 | element = dictionary->addField(type_id, this, 1, "_array_element", 0); 27 | return element; 28 | } 29 | catch (ErrorMessage& msg) 30 | { 31 | throw ErrorStack("DictionaryArray::setElementType") << type_id << msg; 32 | } 33 | catch (ErrorStack& err) 34 | { 35 | err.addLevel("DictionaryArray::setElementType") << type_id; 36 | throw; 37 | }; 38 | 39 | usdsType DictionaryArray::getElementType() throw (...) 40 | { 41 | if (element == 0) 42 | throw ErrorStack("DictionaryArray::getElementType") << ErrorMessage(DIC_ARRAY__NOT_INITIALIZED, "Dictionary Array field not initialized"); 43 | 44 | return element->getType(); 45 | }; 46 | 47 | DictionaryBaseType* DictionaryArray::getElement() throw (...) 48 | try 49 | { 50 | if (element == 0) 51 | throw ErrorMessage(DIC_ARRAY__NOT_INITIALIZED, "Dictionary Array field isn't initialized"); 52 | 53 | return element; 54 | } 55 | catch (ErrorMessage& msg) 56 | { 57 | throw ErrorStack("DictionaryArray::getElementTagID") << msg; 58 | }; 59 | 60 | void DictionaryArray::finalize() throw (...) 61 | try 62 | { 63 | if (element == 0) 64 | throw ErrorMessage(DIC_ARRAY__NOT_INITIALIZED, "Array element is NULL"); 65 | element->finalize(); 66 | 67 | if (getParent() == 0 && element->getType() == USDS_TAG) 68 | { 69 | if (((DictionaryTagLink*)element)->getTag()->getID() == objectID) 70 | throw ErrorMessage(DIC_ARRAY__RECURSION_ERROR, "Array's element 'TAG' can not be itself."); 71 | } 72 | } 73 | catch (ErrorMessage& msg) 74 | { 75 | throw ErrorStack("DictionaryArray::finalize") << msg; 76 | } 77 | catch (ErrorStack& err) 78 | { 79 | err.addLevel("DictionaryArray::finalize"); 80 | throw; 81 | }; -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Dictionary/DataTypes/dictionaryBoolean.cpp: -------------------------------------------------------------------------------- 1 | #include "dictionary\dataTypes\dictionaryBoolean.h" 2 | 3 | using namespace usds; 4 | 5 | DictionaryBoolean::DictionaryBoolean(Dictionary* dict) : DictionaryBaseType(dict) 6 | { 7 | 8 | }; 9 | 10 | void DictionaryBoolean::additionalInitType() 11 | { 12 | isDefault = false; 13 | 14 | }; 15 | 16 | void DictionaryBoolean::setDefaultValue(bool value) 17 | { 18 | isDefault = true; 19 | defaultValue = value; 20 | }; 21 | 22 | bool DictionaryBoolean::getDefaultValue() 23 | { 24 | return defaultValue; 25 | } 26 | 27 | bool DictionaryBoolean::hasDefaultValue() 28 | { 29 | return isDefault; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Dictionary/DataTypes/dictionaryByte.cpp: -------------------------------------------------------------------------------- 1 | #include "dictionary\dataTypes\dictionaryByte.h" 2 | 3 | using namespace usds; 4 | 5 | DictionaryByte::DictionaryByte(Dictionary* dict) : DictionaryBaseType(dict) 6 | { 7 | 8 | }; 9 | 10 | void DictionaryByte::additionalInitType() 11 | { 12 | isDefault = false; 13 | }; 14 | 15 | void DictionaryByte::setDefaultValue(int8_t value) 16 | { 17 | isDefault = true; 18 | defaultValue = value; 19 | }; 20 | 21 | int8_t DictionaryByte::getDefaultValue() 22 | { 23 | return defaultValue; 24 | } 25 | 26 | bool DictionaryByte::hasDefaultValue() 27 | { 28 | return isDefault; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Dictionary/DataTypes/dictionaryDouble.cpp: -------------------------------------------------------------------------------- 1 | #include "dictionary\dataTypes\dictionaryDouble.h" 2 | 3 | using namespace usds; 4 | 5 | DictionaryDouble::DictionaryDouble(Dictionary* dict) : DictionaryBaseType(dict) 6 | { 7 | 8 | }; 9 | 10 | void DictionaryDouble::additionalInitType() 11 | { 12 | isBigendian = false; 13 | isDefault = false; 14 | }; 15 | 16 | void DictionaryDouble::setDefaultValue(double value) 17 | { 18 | isDefault = true; 19 | defaultValue = value; 20 | }; 21 | 22 | double DictionaryDouble::getDefaultValue() 23 | { 24 | return defaultValue; 25 | } 26 | 27 | bool DictionaryDouble::hasDefaultValue() 28 | { 29 | return isDefault; 30 | } 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Dictionary/DataTypes/dictionaryFloat.cpp: -------------------------------------------------------------------------------- 1 | #include "dictionary\dataTypes\dictionaryFloat.h" 2 | 3 | using namespace usds; 4 | 5 | DictionaryFloat::DictionaryFloat(Dictionary* dict) : DictionaryBaseType(dict) 6 | { 7 | 8 | }; 9 | 10 | void DictionaryFloat::additionalInitType() 11 | { 12 | isBigendian = false; 13 | isDefault = false; 14 | }; 15 | 16 | void DictionaryFloat::setDefaultValue(float value) 17 | { 18 | isDefault = true; 19 | defaultValue = value; 20 | }; 21 | 22 | float DictionaryFloat::getDefaultValue() 23 | { 24 | return defaultValue; 25 | } 26 | 27 | bool DictionaryFloat::hasDefaultValue() 28 | { 29 | return isDefault; 30 | } 31 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Dictionary/DataTypes/dictionaryInt.cpp: -------------------------------------------------------------------------------- 1 | #include "dictionary\dataTypes\dictionaryInt.h" 2 | 3 | using namespace usds; 4 | 5 | DictionaryInt::DictionaryInt(Dictionary* dict) : DictionaryBaseType(dict) 6 | { 7 | 8 | }; 9 | 10 | void DictionaryInt::additionalInitType() 11 | { 12 | isBigendian = false; 13 | isDefault = false; 14 | }; 15 | 16 | void DictionaryInt::setDefaultValue(int32_t value) 17 | { 18 | isDefault = true; 19 | defaultValue = value; 20 | }; 21 | 22 | int32_t DictionaryInt::getDefaultValue() 23 | { 24 | return defaultValue; 25 | } 26 | 27 | bool DictionaryInt::hasDefaultValue() 28 | { 29 | return isDefault; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Dictionary/DataTypes/dictionaryLong.cpp: -------------------------------------------------------------------------------- 1 | #include "dictionary\dataTypes\dictionaryLong.h" 2 | 3 | using namespace usds; 4 | 5 | DictionaryLong::DictionaryLong(Dictionary* dict) : DictionaryBaseType(dict) 6 | { 7 | 8 | }; 9 | 10 | void DictionaryLong::additionalInitType() 11 | { 12 | isBigendian = false; 13 | isDefault = false; 14 | }; 15 | 16 | void DictionaryLong::setDefaultValue(int64_t value) 17 | { 18 | isDefault = true; 19 | defaultValue = value; 20 | }; 21 | 22 | int64_t DictionaryLong::getDefaultValue() 23 | { 24 | return defaultValue; 25 | } 26 | 27 | bool DictionaryLong::hasDefaultValue() 28 | { 29 | return isDefault; 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Dictionary/DataTypes/dictionaryShort.cpp: -------------------------------------------------------------------------------- 1 | #include "dictionary\dataTypes\dictionaryShort.h" 2 | 3 | using namespace usds; 4 | 5 | DictionaryShort::DictionaryShort(Dictionary* dict) : DictionaryBaseType(dict) 6 | { 7 | 8 | }; 9 | 10 | void DictionaryShort::additionalInitType() 11 | { 12 | isBigendian = false; 13 | isDefault = false; 14 | }; 15 | 16 | void DictionaryShort::setDefaultValue(int16_t value) 17 | { 18 | isDefault = true; 19 | defaultValue = value; 20 | }; 21 | 22 | int16_t DictionaryShort::getDefaultValue() 23 | { 24 | return defaultValue; 25 | } 26 | 27 | bool DictionaryShort::hasDefaultValue() 28 | { 29 | return isDefault; 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Dictionary/DataTypes/dictionaryString.cpp: -------------------------------------------------------------------------------- 1 | #include "dictionary\dataTypes\dictionaryString.h" 2 | #include "dictionary/usdsDictionary.h" 3 | 4 | #pragma warning (disable : 4996) 5 | 6 | using namespace usds; 7 | 8 | DictionaryString::DictionaryString(Dictionary* dict) : DictionaryBaseType(dict) 9 | { 10 | defaultValue = 0; 11 | }; 12 | 13 | DictionaryString::~DictionaryString() 14 | { 15 | if (defaultValue != 0) 16 | delete[] defaultValue; 17 | }; 18 | 19 | 20 | void DictionaryString::additionalInitType() 21 | { 22 | if (dictionary != 0) 23 | defaultEncode = dictionary->getDefaultStringEncode(); 24 | else 25 | defaultEncode = USDS_NO_DEFAULT_ENCODE; 26 | isDefault = false; 27 | }; 28 | 29 | void DictionaryString::setDefaultEncode(usdsEncode value) throw(...) 30 | { 31 | defaultEncode = value; 32 | }; 33 | 34 | usdsEncode DictionaryString::getDefaultEncode() throw(...) 35 | { 36 | return defaultEncode; 37 | }; 38 | 39 | void DictionaryString::setDefaultValueFromUTF8(const char* value) 40 | { 41 | isDefault = true; 42 | size_t size = strlen(value) + 1; 43 | if (defaultValue == 0) 44 | { 45 | defaultValueBufferSize = size; 46 | defaultValue = new char[defaultValueBufferSize]; 47 | } 48 | else 49 | { 50 | if (size > defaultValueBufferSize) 51 | { 52 | delete[] defaultValue; 53 | defaultValueBufferSize = size; 54 | defaultValue = new char[defaultValueBufferSize]; 55 | } 56 | } 57 | strcpy(defaultValue, value); 58 | }; 59 | 60 | void DictionaryString::setDefaultValueFromUTF8(const char* value, size_t byte_size) 61 | { 62 | isDefault = true; 63 | 64 | if (byte_size == 0) 65 | { 66 | byte_size = 1; 67 | } 68 | else 69 | { 70 | if (value[byte_size - 1] != 0) 71 | byte_size++; 72 | } 73 | if (defaultValue == 0) 74 | { 75 | defaultValueBufferSize = byte_size; 76 | defaultValue = new char[defaultValueBufferSize]; 77 | } 78 | else 79 | { 80 | if (byte_size > defaultValueBufferSize) 81 | { 82 | delete[] defaultValue; 83 | defaultValueBufferSize = byte_size; 84 | defaultValue = new char[defaultValueBufferSize]; 85 | } 86 | } 87 | 88 | memcpy(defaultValue, value, byte_size - 1); 89 | defaultValue[byte_size - 1] = 0; 90 | }; 91 | 92 | const char* DictionaryString::getUTF8DefaultValue() 93 | { 94 | return defaultValue; 95 | }; 96 | 97 | bool DictionaryString::hasDefaultValue() 98 | { 99 | return isDefault; 100 | }; 101 | 102 | void DictionaryString::finalize() throw (...) 103 | { 104 | 105 | } -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Dictionary/DataTypes/dictionaryTagLink.cpp: -------------------------------------------------------------------------------- 1 | #include "dictionary\dataTypes\dictionaryTagLink.h" 2 | #include "dictionary\usdsDictionary.h" 3 | 4 | using namespace usds; 5 | 6 | DictionaryTagLink::DictionaryTagLink(Dictionary* dict) : DictionaryBaseType(dict) 7 | { 8 | 9 | } 10 | 11 | void DictionaryTagLink::additionalInitType() 12 | { 13 | isRoot = false; 14 | 15 | tag = 0; 16 | tagID = -1; 17 | tagName.clear(); 18 | 19 | }; 20 | 21 | void DictionaryTagLink::finalize() throw (...) 22 | try 23 | { 24 | if (tag != 0) 25 | throw ErrorMessage(DIC_TAG__ALREADY_FINALIZED, "Tag is finalized already"); 26 | 27 | if (!tagName.empty()) 28 | { 29 | tag = dictionary->findTag(tagName.c_str()); 30 | if (tag == 0) 31 | throw ErrorMessage(DIC_TAG_LINK__TAG_NOT_FOUND) << "Tag with name '" << tagName << "' not found in dictionary ID=" << dictionary->getDictionaryID() << " v." << int(dictionary->getMajorVersion()) << "." << int(dictionary->getMinorVersion()); 32 | } 33 | else if (tagID != -1) 34 | { 35 | tag = dictionary->getTag(tagID); 36 | } 37 | else 38 | throw ErrorMessage(DIC_TAG_LINK__NOT_INITIALIZED, "Tag's link isn't initialized"); 39 | 40 | if (tag->getType() == USDS_TAG) 41 | throw ErrorMessage(DIC_TAG_LINK__TAG_OF_TAG, "Tag of Tag is not supported"); 42 | } 43 | catch (ErrorMessage& msg) 44 | { 45 | throw ErrorStack("DictionaryTagLink::finalize") << msg; 46 | } 47 | catch (ErrorStack& err) 48 | { 49 | err.addLevel("DictionaryTagLink::finalize"); 50 | throw; 51 | }; 52 | 53 | void DictionaryTagLink::setTag(const char* tag_name, size_t name_size) throw (...) 54 | try 55 | { 56 | if (tag_name == 0) 57 | throw ErrorMessage(DIC_TAG_LINK__ERROR_ELEMENT_NAME, "Tag name for the element can not be NULL"); 58 | 59 | if (name_size == 0) 60 | tagName = tag_name; 61 | else 62 | tagName.assign(tag_name, name_size); 63 | } 64 | catch (ErrorMessage& msg) 65 | { 66 | throw ErrorStack("DictionaryTagLink::setTag") << tag_name << name_size << msg; 67 | } 68 | catch (ErrorStack& err) 69 | { 70 | err.addLevel("DictionaryTagLink::setTag") << tag_name << name_size; 71 | throw; 72 | }; 73 | 74 | void DictionaryTagLink::setTag(int32_t tag_id) throw (...) 75 | try 76 | { 77 | if (tag_id <= 0) 78 | throw ErrorMessage(DIC_TAG_LINK__ERROR_ELEMENT_ID, "Tag ID for the element must be > 1. Current value = ") << tag_id; 79 | 80 | tagID = tag_id; 81 | 82 | } 83 | catch (ErrorMessage& msg) 84 | { 85 | throw ErrorStack("DictionaryTagLink::setTag") << tag_id << msg; 86 | } 87 | catch (ErrorStack& err) 88 | { 89 | err.addLevel("DictionaryTagLink::setTag") << tag_id; 90 | throw; 91 | }; 92 | 93 | DictionaryBaseType* DictionaryTagLink::getTag() throw (...) 94 | try 95 | { 96 | if (tag == 0) 97 | throw ErrorMessage(DIC_TAG_LINK__NOT_INITIALIZED, "Tag's link isn't initialized"); 98 | 99 | return tag; 100 | } 101 | catch (ErrorMessage& msg) 102 | { 103 | throw ErrorStack("DictionaryTagLink::getTag") << msg; 104 | } 105 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Dictionary/DataTypes/dictionaryUByte.cpp: -------------------------------------------------------------------------------- 1 | #include "dictionary\dataTypes\dictionaryUByte.h" 2 | 3 | using namespace usds; 4 | 5 | DictionaryUByte::DictionaryUByte(Dictionary* dict) : DictionaryBaseType(dict) 6 | { 7 | 8 | }; 9 | 10 | void DictionaryUByte::additionalInitType() 11 | { 12 | isDefault = false; 13 | }; 14 | 15 | void DictionaryUByte::setDefaultValue(uint8_t value) 16 | { 17 | isDefault = true; 18 | defaultValue = value; 19 | }; 20 | 21 | uint8_t DictionaryUByte::getDefaultValue() 22 | { 23 | return defaultValue; 24 | } 25 | 26 | bool DictionaryUByte::hasDefaultValue() 27 | { 28 | return isDefault; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Dictionary/DataTypes/dictionaryUInt.cpp: -------------------------------------------------------------------------------- 1 | #include "dictionary\dataTypes\dictionaryUInt.h" 2 | 3 | using namespace usds; 4 | 5 | DictionaryUInt::DictionaryUInt(Dictionary* dict) : DictionaryBaseType(dict) 6 | { 7 | 8 | }; 9 | 10 | void DictionaryUInt::additionalInitType() 11 | { 12 | isBigendian = false; 13 | isDefault = false; 14 | }; 15 | 16 | void DictionaryUInt::setDefaultValue(uint32_t value) 17 | { 18 | isDefault = true; 19 | defaultValue = value; 20 | }; 21 | 22 | uint32_t DictionaryUInt::getDefaultValue() 23 | { 24 | return defaultValue; 25 | } 26 | 27 | bool DictionaryUInt::hasDefaultValue() 28 | { 29 | return isDefault; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Dictionary/DataTypes/dictionaryULong.cpp: -------------------------------------------------------------------------------- 1 | #include "dictionary\dataTypes\dictionaryULong.h" 2 | 3 | using namespace usds; 4 | 5 | DictionaryULong::DictionaryULong(Dictionary* dict) : DictionaryBaseType(dict) 6 | { 7 | 8 | }; 9 | 10 | void DictionaryULong::additionalInitType() 11 | { 12 | isBigendian = false; 13 | isDefault = false; 14 | }; 15 | 16 | void DictionaryULong::setDefaultValue(uint64_t value) 17 | { 18 | isDefault = true; 19 | defaultValue = value; 20 | }; 21 | 22 | uint64_t DictionaryULong::getDefaultValue() 23 | { 24 | return defaultValue; 25 | } 26 | 27 | bool DictionaryULong::hasDefaultValue() 28 | { 29 | return isDefault; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Dictionary/DataTypes/dictionaryUShort.cpp: -------------------------------------------------------------------------------- 1 | #include "dictionary\dataTypes\dictionaryUShort.h" 2 | 3 | using namespace usds; 4 | 5 | DictionaryUShort::DictionaryUShort(Dictionary* dict) : DictionaryBaseType(dict) 6 | { 7 | 8 | }; 9 | 10 | void DictionaryUShort::additionalInitType() 11 | { 12 | isBigendian = false; 13 | isDefault = false; 14 | }; 15 | 16 | void DictionaryUShort::setDefaultValue(uint16_t value) 17 | { 18 | isDefault = true; 19 | defaultValue = value; 20 | }; 21 | 22 | uint16_t DictionaryUShort::getDefaultValue() 23 | { 24 | return defaultValue; 25 | } 26 | 27 | bool DictionaryUShort::hasDefaultValue() 28 | { 29 | return isDefault; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Dictionary/DataTypes/dictionaryUVarint.cpp: -------------------------------------------------------------------------------- 1 | #include "dictionary\dataTypes\dictionaryUVarint.h" 2 | 3 | using namespace usds; 4 | 5 | DictionaryUVarint::DictionaryUVarint(Dictionary* dict) : DictionaryBaseType(dict) 6 | { 7 | 8 | }; 9 | 10 | void DictionaryUVarint::additionalInitType() 11 | { 12 | isDefault = false; 13 | }; 14 | 15 | void DictionaryUVarint::setDefaultValue(uint64_t value) 16 | { 17 | isDefault = true; 18 | defaultValue = value; 19 | }; 20 | 21 | uint64_t DictionaryUVarint::getDefaultValue() 22 | { 23 | return defaultValue; 24 | } 25 | 26 | bool DictionaryUVarint::hasDefaultValue() 27 | { 28 | return isDefault; 29 | } 30 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Dictionary/DataTypes/dictionaryVarint.cpp: -------------------------------------------------------------------------------- 1 | #include "dictionary\dataTypes\dictionaryVarint.h" 2 | 3 | using namespace usds; 4 | 5 | DictionaryVarint::DictionaryVarint(Dictionary* dict) : DictionaryBaseType(dict) 6 | { 7 | 8 | }; 9 | 10 | void DictionaryVarint::additionalInitType() 11 | { 12 | isDefault = false; 13 | }; 14 | 15 | void DictionaryVarint::setDefaultValue(int64_t value) 16 | { 17 | isDefault = true; 18 | defaultValue = value; 19 | }; 20 | 21 | int64_t DictionaryVarint::getDefaultValue() 22 | { 23 | return defaultValue; 24 | } 25 | 26 | bool DictionaryVarint::hasDefaultValue() 27 | { 28 | return isDefault; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/Dictionary/dictionaryBaseType.cpp: -------------------------------------------------------------------------------- 1 | #include "dictionary\dictionaryBaseType.h" 2 | 3 | using namespace usds; 4 | 5 | void DictionaryBaseType::initType(DictionaryBaseType* parent, int32_t id, const char* name, size_t name_size) throw(...) 6 | try 7 | { 8 | if (name == 0) 9 | throw ErrorMessage(DIC_BASE_TYPE__NULL_NAME, "Name can not be NULL"); 10 | 11 | if (id <= 0) 12 | throw ErrorMessage(DIC_BASE_TYPE__TAG_ID_ERROR_VALUE) << "ID must be in range [1; 2,147,483,647]. Current value: " << id; 13 | 14 | // TODO check name by regular expression 15 | 16 | nextObject = 0; 17 | previousObject = 0; 18 | 19 | parentObject = parent; 20 | 21 | if (name_size == 0) 22 | objectName = name; 23 | else 24 | objectName.assign(name, name_size); 25 | objectID = id; 26 | 27 | isRoot = (parent == 0); 28 | 29 | nullableValue = false; 30 | 31 | additionalInitType(); 32 | 33 | } 34 | catch (ErrorMessage& msg) 35 | { 36 | throw ErrorStack("DictionaryBaseType::initType") << (void*)parent << id << name << name_size << msg; 37 | } 38 | catch (ErrorStack& err) 39 | { 40 | err.addLevel("DictionaryBaseType::initType") << (void*)parent << id << name << name_size; 41 | throw; 42 | }; 43 | 44 | const char* DictionaryBaseType::getName() throw(...) 45 | { 46 | 47 | return objectName.c_str(); 48 | }; 49 | 50 | size_t DictionaryBaseType::getNameSize() throw(...) 51 | { 52 | 53 | return objectName.size(); 54 | }; 55 | 56 | int32_t DictionaryBaseType::getID() throw(...) 57 | { 58 | 59 | return objectID; 60 | }; 61 | 62 | DictionaryBaseType* DictionaryBaseType::getNext() throw (...) 63 | { 64 | 65 | return nextObject; 66 | }; 67 | 68 | DictionaryBaseType* DictionaryBaseType::getPrevious() throw (...) 69 | { 70 | 71 | return previousObject; 72 | }; 73 | 74 | DictionaryBaseType* DictionaryBaseType::getParent() throw (...) 75 | { 76 | 77 | return parentObject; 78 | }; 79 | 80 | void DictionaryBaseType::setNext(DictionaryBaseType* next) 81 | { 82 | 83 | nextObject = next; 84 | }; 85 | 86 | void DictionaryBaseType::setPrevious(DictionaryBaseType* previous) 87 | { 88 | 89 | previousObject = previous; 90 | }; 91 | 92 | void DictionaryBaseType::setParent(DictionaryBaseType* parent) 93 | { 94 | 95 | parentObject = parent; 96 | }; 97 | 98 | void DictionaryBaseType::setRoot(bool is_root) throw(...) 99 | { 100 | 101 | isRoot = is_root; 102 | }; 103 | 104 | 105 | DictionaryBaseType* DictionaryBaseType::setNullable(bool is_nullable) 106 | { 107 | nullableValue = is_nullable; 108 | return this; 109 | } 110 | 111 | bool DictionaryBaseType::isNullable() 112 | { 113 | return nullableValue; 114 | } 115 | 116 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParser/Source/usdsTypes.cpp: -------------------------------------------------------------------------------- 1 | #include "usdsTypes.h" 2 | 3 | #include "usdsErrors.h" 4 | 5 | using namespace usds; 6 | 7 | const char* UsdsTypes::typeName(usdsType code) throw(...) 8 | { 9 | switch(code) 10 | { 11 | case USDS_TAG: return "TAG"; 12 | case USDS_BOOLEAN: return "BOOLEAN"; 13 | case USDS_BYTE: return "BYTE"; 14 | case USDS_UBYTE: return "UBYTE"; 15 | case USDS_SHORT: return "SHORT"; 16 | case USDS_USHORT: return "USHORT"; 17 | case USDS_INT: return "INT"; 18 | case USDS_UINT: return "UINT"; 19 | case USDS_LONG: return "LONG"; 20 | case USDS_ULONG: return "ULONG"; 21 | case USDS_INT128: return "INT128"; 22 | case USDS_UINT128: return "UINT128"; 23 | case USDS_FLOAT: return "FLOAT"; 24 | case USDS_DOUBLE: return "DOUBLE"; 25 | case USDS_VARINT: return "VARINT"; 26 | case USDS_UVARINT: return "UVARINT"; 27 | case USDS_STRING: return "STRING"; 28 | case USDS_ARRAY: return "ARRAY"; 29 | case USDS_STRUCT: return "STRUCT"; 30 | case USDS_ENUM: return "ENUM"; 31 | case USDS_POLYMORPH: return "POLYMORPH"; 32 | case USDS_LAST_TYPE: return "NO TYPE"; 33 | 34 | default: 35 | throw ErrorStack("UsdsTypes::typeName") << code << (ErrorMessage(USDS_TYPES__ERROR_TYPE_CODE) << "Unknown type code " << code); 36 | } 37 | 38 | }; 39 | 40 | int32_t UsdsTypes::typeSize(usdsType code) throw(...) 41 | { 42 | switch (code) 43 | { 44 | case USDS_TAG: return USDS_TAG_SIZE; 45 | case USDS_BOOLEAN: return USDS_BOOLEAN_SIZE; 46 | case USDS_BYTE: return USDS_BYTE_SIZE; 47 | case USDS_UBYTE: return USDS_UBYTE_SIZE; 48 | case USDS_SHORT: return USDS_SHORT_SIZE; 49 | case USDS_USHORT: return USDS_USHORT_SIZE; 50 | case USDS_INT: return USDS_INT_SIZE; 51 | case USDS_UINT: return USDS_UINT_SIZE; 52 | case USDS_LONG: return USDS_LONG_SIZE; 53 | case USDS_ULONG: return USDS_ULONG_SIZE; 54 | case USDS_INT128: return USDS_INT128_SIZE; 55 | case USDS_UINT128: return USDS_UINT128_SIZE; 56 | case USDS_FLOAT: return USDS_FLOAT_SIZE; 57 | case USDS_DOUBLE: return USDS_DOUBLE_SIZE; 58 | case USDS_VARINT: return USDS_VARINT_SIZE; 59 | case USDS_UVARINT: return USDS_UVARINT_SIZE; 60 | case USDS_STRING: return USDS_STRING_SIZE; 61 | case USDS_ARRAY: return USDS_ARRAY_SIZE; 62 | case USDS_STRUCT: return USDS_STRUCT_SIZE; 63 | case USDS_ENUM: return USDS_ENUM_SIZE; 64 | case USDS_POLYMORPH: return USDS_POLYMORPH_SIZE; 65 | default: 66 | throw ErrorStack("UsdsTypes::typeSize") << code << (ErrorMessage(USDS_TYPES__ERROR_TYPE_CODE) << "Unknown type code " << code); 67 | } 68 | }; 69 | 70 | const char* UsdsTypes::encodeName(usdsEncode code) throw(...) 71 | { 72 | switch (code) 73 | { 74 | case USDS_UTF8: return "UTF-8"; 75 | case USDS_UTF16LE: return "UTF-16LE"; 76 | case USDS_UTF16BE: return "UTF-16BE"; 77 | case USDS_UTF32LE: return "UTF-32LE"; 78 | case USDS_UTF32BE: return "UTF-32BE"; 79 | default: 80 | throw ErrorStack("UsdsTypes::encodeName") << code << (ErrorMessage(USDS_TYPES__ERROR_ENCODE) << "Unknown encode " << code); 81 | } 82 | }; 83 | 84 | -------------------------------------------------------------------------------- /BasicParserCPP/BasicParserCPP.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BasicParser", "BasicParser\BasicParser.vcxproj", "{C76E2685-841D-4035-B689-10ADE30AB060}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{AB82DEC1-1A6A-493E-91D8-714EBA65AA59}" 9 | ProjectSection(SolutionItems) = preProject 10 | Performance.psess = Performance.psess 11 | EndProjectSection 12 | EndProject 13 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Autotest", "Autotest\Autotest.vcxproj", "{224971DD-8578-4096-A116-C5E5DBDAD3A7}" 14 | ProjectSection(ProjectDependencies) = postProject 15 | {C76E2685-841D-4035-B689-10ADE30AB060} = {C76E2685-841D-4035-B689-10ADE30AB060} 16 | EndProjectSection 17 | EndProject 18 | Global 19 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 20 | Debug|Win32 = Debug|Win32 21 | Debug|x64 = Debug|x64 22 | Release|Win32 = Release|Win32 23 | Release|x64 = Release|x64 24 | EndGlobalSection 25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 26 | {C76E2685-841D-4035-B689-10ADE30AB060}.Debug|Win32.ActiveCfg = Debug|Win32 27 | {C76E2685-841D-4035-B689-10ADE30AB060}.Debug|Win32.Build.0 = Debug|Win32 28 | {C76E2685-841D-4035-B689-10ADE30AB060}.Debug|x64.ActiveCfg = Debug|Win32 29 | {C76E2685-841D-4035-B689-10ADE30AB060}.Release|Win32.ActiveCfg = Release|Win32 30 | {C76E2685-841D-4035-B689-10ADE30AB060}.Release|Win32.Build.0 = Release|Win32 31 | {C76E2685-841D-4035-B689-10ADE30AB060}.Release|x64.ActiveCfg = Release|Win32 32 | {224971DD-8578-4096-A116-C5E5DBDAD3A7}.Debug|Win32.ActiveCfg = Debug|Win32 33 | {224971DD-8578-4096-A116-C5E5DBDAD3A7}.Debug|Win32.Build.0 = Debug|Win32 34 | {224971DD-8578-4096-A116-C5E5DBDAD3A7}.Debug|x64.ActiveCfg = Debug|Win32 35 | {224971DD-8578-4096-A116-C5E5DBDAD3A7}.Release|Win32.ActiveCfg = Release|Win32 36 | {224971DD-8578-4096-A116-C5E5DBDAD3A7}.Release|Win32.Build.0 = Release|Win32 37 | {224971DD-8578-4096-A116-C5E5DBDAD3A7}.Release|x64.ActiveCfg = Release|Win32 38 | EndGlobalSection 39 | GlobalSection(SolutionProperties) = preSolution 40 | HideSolutionNode = FALSE 41 | EndGlobalSection 42 | EndGlobal 43 | -------------------------------------------------------------------------------- /BasicParserCPP/Example/UsdsExample.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UsdsExample", "UsdsExample.vcxproj", "{5633E662-131A-47F7-8A07-305B5EA8D06B}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {5633E662-131A-47F7-8A07-305B5EA8D06B}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {5633E662-131A-47F7-8A07-305B5EA8D06B}.Debug|Win32.Build.0 = Debug|Win32 16 | {5633E662-131A-47F7-8A07-305B5EA8D06B}.Release|Win32.ActiveCfg = Release|Win32 17 | {5633E662-131A-47F7-8A07-305B5EA8D06B}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /BasicParserCPP/Example/UsdsExample.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | -------------------------------------------------------------------------------- /BasicParserCPP/Performance.psess: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | usdsCPP.sln 5 | Sampling 6 | None 7 | true 8 | true 9 | Timestamp 10 | Cycles 11 | 10000000 12 | 10 13 | 10 14 | 15 | false 16 | 17 | 18 | 19 | false 20 | 500 21 | 22 | \Память\Обмен страниц/с 23 | \Процессор(_Total)\% загруженности процессора 24 | \Физический диск(_Total)\Средняя длина очереди диска 25 | 26 | 27 | 28 | true 29 | false 30 | false 31 | 32 | false 33 | 34 | 35 | false 36 | 37 | 38 | 39 | Benchmark\bin\Debug_Win32\Benchmark.exe 40 | 01/01/0001 00:00:00 41 | true 42 | true 43 | false 44 | false 45 | false 46 | false 47 | false 48 | true 49 | false 50 | Executable 51 | Benchmark\bin\Debug_Win32\Benchmark.exe 52 | IIS 53 | InternetExplorer 54 | true 55 | false 56 | 57 | false 58 | 59 | 60 | false 61 | 62 | 63 | 64 | 65 | 66 | Benchmark\bin\Debug_Win32\Benchmark.exe 67 | 68 | 69 | -------------------------------------------------------------------------------- /BenchmarkCPP/Benchmark.VC.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zashibis/USDS/d6544310e613a191946305924d5b645a962267a4/BenchmarkCPP/Benchmark.VC.db -------------------------------------------------------------------------------- /BenchmarkCPP/Benchmark.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Benchmark", "Benchmark.vcxproj", "{56EF51A6-42DB-4FE5-89DD-161093E22B52}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x86 = Debug|x86 11 | Release|x86 = Release|x86 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {56EF51A6-42DB-4FE5-89DD-161093E22B52}.Debug|x86.ActiveCfg = Debug|Win32 15 | {56EF51A6-42DB-4FE5-89DD-161093E22B52}.Debug|x86.Build.0 = Debug|Win32 16 | {56EF51A6-42DB-4FE5-89DD-161093E22B52}.Release|x86.ActiveCfg = Release|Win32 17 | {56EF51A6-42DB-4FE5-89DD-161093E22B52}.Release|x86.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /BenchmarkCPP/Include/ASN/asnTest.h: -------------------------------------------------------------------------------- 1 | #ifndef ASN_TEST 2 | #define ASN_TEST 3 | 4 | #include "baseTest.h" 5 | 6 | //#define USE_MD_LIB 7 | #include "asn_bench.h" 8 | 9 | #include 10 | 11 | class AsnTest : public BaseTest 12 | { 13 | public: 14 | AsnTest(int counts, int size); 15 | virtual ~AsnTest(); 16 | 17 | private: 18 | int serializationTest(); 19 | int deserializationTest(); 20 | 21 | char* asn_data; 22 | 23 | EncodedBuffer* asn_buff; 24 | AsnTicketSales_PDU* serializer; 25 | asn_bench_Control* ctl; 26 | 27 | }; 28 | 29 | 30 | 31 | 32 | #endif -------------------------------------------------------------------------------- /BenchmarkCPP/Include/BSON/bsonTest.h: -------------------------------------------------------------------------------- 1 | #ifndef BSON_TEST 2 | #define BSON_TEST 3 | 4 | #include "baseTest.h" 5 | 6 | #include 7 | #include "mongo\bson\bson.h" 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | class BsonTest : public BaseTest 14 | { 15 | public: 16 | BsonTest(int counts, int size); 17 | virtual ~BsonTest(); 18 | 19 | private: 20 | int serializationTest(); 21 | int deserializationTest(); 22 | 23 | char* bson_data; 24 | 25 | }; 26 | 27 | 28 | #endif -------------------------------------------------------------------------------- /BenchmarkCPP/Include/JSON/jsonTest.h: -------------------------------------------------------------------------------- 1 | #ifndef JSON_TEST 2 | #define JSON_TEST 3 | 4 | #include "baseTest.h" 5 | #include "rapidjson\writer.h" 6 | #include "rapidjson\stringbuffer.h" 7 | #include "rapidjson\reader.h" 8 | 9 | #include 10 | 11 | using namespace rapidjson; 12 | using namespace std; 13 | 14 | class Handler { 15 | 16 | public: 17 | 18 | Handler(TicketSales* out) { output_class = out; last_key = 0; arr_pos = -1; }; 19 | virtual ~Handler() {}; 20 | 21 | inline bool Null() { return false; }; 22 | inline bool Bool(bool b); 23 | inline bool Int(int i); 24 | inline bool Uint(unsigned i); 25 | inline bool Int64(int64_t i) { return false; }; 26 | inline bool Uint64(uint64_t i) { return false; }; 27 | inline bool Double(double d); 28 | inline bool String(const char* str, SizeType length, bool copy); 29 | inline bool StartObject(); 30 | inline bool Key(const char* str, SizeType length, bool copy); 31 | inline bool EndObject(SizeType memberCount); 32 | inline bool StartArray(); 33 | inline bool EndArray(SizeType elementCount); 34 | 35 | private: 36 | TicketSales* output_class; 37 | char last_key; 38 | int arr_pos; 39 | 40 | 41 | }; 42 | 43 | 44 | class JsonTest : public BaseTest 45 | { 46 | public: 47 | JsonTest(int counts, int size); 48 | ~JsonTest(); 49 | 50 | private: 51 | int serializationTest(); 52 | int deserializationTest(); 53 | 54 | char* json_data; 55 | 56 | Writer *serializer; 57 | Reader* deserializer; 58 | StringBuffer* json_buff; 59 | 60 | Handler* json_ticket_sales; 61 | 62 | }; 63 | 64 | 65 | #endif -------------------------------------------------------------------------------- /BenchmarkCPP/Include/Protobuf/protobufTest.h: -------------------------------------------------------------------------------- 1 | #ifndef PROTOBUF_TEST 2 | #define PROTOBUF_TEST 3 | 4 | #include "baseTest.h" 5 | #include "Protobuf\protobufTicketSales.h" 6 | 7 | class ProtobufTest : public BaseTest 8 | { 9 | public: 10 | ProtobufTest(int counts, int size); 11 | virtual ~ProtobufTest(); 12 | 13 | private: 14 | int serializationTest(); 15 | int deserializationTest(); 16 | 17 | ProtobufTicketSales* serializer; 18 | 19 | void* serialized_data; 20 | 21 | }; 22 | 23 | 24 | #endif -------------------------------------------------------------------------------- /BenchmarkCPP/Include/USDS Basic/usdsBasicTest.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_BASIC_TEST 2 | #define USDS_BASIC_TEST 3 | 4 | #include "baseTest.h" 5 | #include "usdsBasicParser.h" 6 | 7 | class UsdsBasicTest : public BaseTest 8 | { 9 | public: 10 | UsdsBasicTest(int counts, int size); 11 | virtual ~UsdsBasicTest(); 12 | 13 | private: 14 | int serializationTest(); 15 | int deserializationTest(); 16 | 17 | usds::BasicParser* parser; 18 | 19 | usds::BinaryOutput usds_data; 20 | 21 | }; 22 | 23 | 24 | 25 | 26 | #endif -------------------------------------------------------------------------------- /BenchmarkCPP/Include/USDS DOM/usdsDomTest.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_DOM_TEST 2 | #define USDS_DOM_TEST 3 | 4 | #include "baseTest.h" 5 | #include "USDS DOM\usdsDomParser.h" 6 | 7 | class UsdsDomTest : public BaseTest 8 | { 9 | public: 10 | UsdsDomTest(int counts, int size); 11 | virtual ~UsdsDomTest(); 12 | 13 | private: 14 | int serializationTest(); 15 | int deserializationTest(); 16 | 17 | UsdsDomParser* parser; 18 | 19 | unsigned char* usds_data; 20 | 21 | }; 22 | 23 | 24 | #endif -------------------------------------------------------------------------------- /BenchmarkCPP/Include/USDS/usdsDeserializer.h: -------------------------------------------------------------------------------- 1 | // This file must be autogenerated 2 | 3 | #ifndef USDS_DESERIALIZER 4 | #define USDS_DESERIALIZER 5 | 6 | #include 7 | 8 | #include "ticketSales.h" 9 | 10 | // All types for getCurentRecordType() 11 | #ifndef USDS_TYPE_TICKET_SALES 12 | #define USDS_TYPE_TICKET_SALES 1 13 | #endif 14 | 15 | class UsdsDeserializer 16 | { 17 | public: 18 | UsdsDeserializer(); 19 | ~UsdsDeserializer(); 20 | 21 | // Settings 22 | // Set for binary 23 | int setUsdsVersion(int major, int minor); 24 | int setDictionaryVersion(int major, int minor); 25 | // Get from binary (deserialization) 26 | int getUsdsVersion(int* major, int* minor); 27 | int getDictionaryVersion(int* major, int* minor); 28 | int getBinaryInfo(bool* head, bool* dictionary, bool* body, bool* index); 29 | 30 | // Deserialization 31 | int setBinary(unsigned char* data, int data_size); 32 | int findFirstAndInit(TicketSales* data); 33 | int findNextAndInit(TicketSales* data); 34 | int findFirstAndCreate(TicketSales** data); 35 | int findNextAndCreate(TicketSales** data); 36 | 37 | int clean(); 38 | 39 | private: 40 | // settings 41 | unsigned char usds_major; 42 | unsigned char usds_minor; 43 | unsigned char dictionary_major; 44 | unsigned char dictionary_minor; 45 | int full_dictionary_version; 46 | 47 | // Binary info 48 | bool head_included; 49 | bool dictionary_included; 50 | 51 | // for binary 52 | int binarySize; 53 | 54 | unsigned char* usds_buff; 55 | unsigned char* buff_last_pos; // It is a position after last valid position in the Buffer. The Buffer size is buff_last_pos - usds_buff 56 | unsigned char* buff_current_pos; // Last unread position in the Buffer. The document size is buff_current_pos - usds_buff 57 | unsigned char* buff_body_pos; // The first byte of body, after tag 'B' 58 | unsigned char* buff_body_last_pos; // The last body position - tag 0 59 | 60 | inline int getVarint(int* value); 61 | inline void getLEInt(int*value); 62 | inline void setLETimestamp64(time_t* value); 63 | inline void setLEDouble(double* value); 64 | inline int setStringUTF8NoConvert(char* value, int max_size); 65 | inline void setBool(bool* value); 66 | 67 | }; 68 | 69 | 70 | #endif -------------------------------------------------------------------------------- /BenchmarkCPP/Include/USDS/usdsSerializer.h: -------------------------------------------------------------------------------- 1 | // This file must be autogenerated 2 | 3 | #ifndef USDS_SERIALIZER 4 | #define USDS_SERIALIZER 5 | 6 | #include 7 | 8 | #include "ticketSales.h" 9 | 10 | class UsdsSerializer 11 | { 12 | public: 13 | UsdsSerializer(); 14 | UsdsSerializer(int doc_typical_size); 15 | ~UsdsSerializer(); 16 | 17 | // Settings 18 | int setUsdsVersion(unsigned char major, unsigned char minor); 19 | int setDictionaryVersion(unsigned char major, unsigned char minor); 20 | 21 | // Serialization 22 | int addHead(); 23 | int addDictionary(); 24 | int addToBody(TicketSales* data); 25 | int addControl(); 26 | int addIndex(); 27 | int getUSDS(unsigned char** data, int* size); 28 | int clean(); // it does not release memory in buffer 29 | int deleteUSDS(); // it release memory and create new buffer with the default size (binary_typical_size or 4 kb) 30 | 31 | private: 32 | // settings 33 | unsigned char usds_major; 34 | unsigned char usds_minor; 35 | unsigned char dictionary_major; 36 | unsigned char dictionary_minor; 37 | int full_dictionary_version; 38 | 39 | // Current status 40 | bool head_added; 41 | bool dictionary_added; 42 | bool body_added; 43 | bool body_finished; 44 | bool control_added; 45 | bool index_added; 46 | 47 | // Buffer for USDS document 48 | int default_doc_size; 49 | unsigned char* usds_buff; 50 | unsigned char* buff_last_pos; // It is a position after last valid position in the Buffer. The Buffer size is buff_last_pos - usds_buff 51 | unsigned char* buff_current_pos; // Last claen position in the Buffer. The document size is buff_current_pos - usds_buff 52 | 53 | inline int resizeArray(int minIncrease); 54 | inline int addVarint(int value); 55 | inline void addLEInt(int value); 56 | inline void addLETimestamp64(time_t value); 57 | inline void addLEDouble(double value); 58 | inline int addStringUTF8NoConvert(char* value, int max_size); 59 | inline void addBool(bool value); 60 | }; 61 | 62 | 63 | #endif -------------------------------------------------------------------------------- /BenchmarkCPP/Include/USDS/usdsTest.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_TEST 2 | #define USDS_TEST 3 | 4 | #include "baseTest.h" 5 | #include "USDS\usdsSerializer.h" 6 | #include "USDS\usdsDeserializer.h" 7 | 8 | class UsdsTest: public BaseTest 9 | { 10 | public: 11 | UsdsTest(int counts, int size); 12 | virtual ~UsdsTest(); 13 | 14 | private: 15 | int serializationTest(); 16 | int deserializationTest(); 17 | 18 | UsdsSerializer* Serializer; 19 | UsdsDeserializer* Deserializer; 20 | 21 | unsigned char* usds_data; 22 | 23 | }; 24 | 25 | 26 | #endif -------------------------------------------------------------------------------- /BenchmarkCPP/Include/XML/xmlTest.h: -------------------------------------------------------------------------------- 1 | #ifndef XML_TEST 2 | #define XML_TEST 3 | 4 | #include "baseTest.h" 5 | #include "XML\tinyxml2.h" 6 | 7 | class XmlTest : public BaseTest 8 | { 9 | public: 10 | XmlTest(int counts, int size); 11 | virtual ~XmlTest(); 12 | 13 | private: 14 | int serializationTest(); 15 | int deserializationTest(); 16 | 17 | char* xml_data; 18 | 19 | tinyxml2::XMLDocument* serializer; 20 | tinyxml2::XMLPrinter printer; 21 | 22 | }; 23 | 24 | 25 | #endif -------------------------------------------------------------------------------- /BenchmarkCPP/Include/baseTest.h: -------------------------------------------------------------------------------- 1 | // main functions for tests 2 | #ifndef BASE_TEST 3 | #define BASE_TEST 4 | 5 | #include 6 | #include 7 | #include "ticketSales.h" 8 | 9 | class BaseTest 10 | { 11 | public: 12 | BaseTest(); 13 | virtual ~BaseTest(); 14 | 15 | int beginTest(); 16 | 17 | clock_t getSerializationTime() { return serialization_time; }; 18 | clock_t getDeserializationTime() { return deserialization_time; }; 19 | int getSerializationDataSize() { return serialization_data_size; }; 20 | bool getCheckData() { return checkData; }; 21 | 22 | protected: 23 | virtual int serializationTest() = 0; 24 | virtual int deserializationTest() = 0; 25 | 26 | TicketSales* TestData; 27 | TicketSales* CleanData; 28 | int serialization_data_size; 29 | bool checkData; 30 | int test_counts; 31 | 32 | private: 33 | clock_t serialization_time; 34 | clock_t deserialization_time; 35 | 36 | bool checkDataTest(); 37 | }; 38 | 39 | 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /BenchmarkCPP/Include/ticketSales.h: -------------------------------------------------------------------------------- 1 | #ifndef TICKET_SALES 2 | #define TICKET_SALES 3 | 4 | #include 5 | 6 | struct voucher 7 | { 8 | int voucher_number; 9 | double summ; 10 | char goods_name[128]; 11 | time_t time_of_sell; 12 | bool status; 13 | }; 14 | 15 | // Your class with business logic, that needs to serialize/deserialize 16 | class TicketSales 17 | { 18 | public: 19 | TicketSales(int num_vouchers, bool clean); 20 | ~TicketSales(); 21 | 22 | private: 23 | int shiftNumber; 24 | int cashRegister; 25 | time_t startShift; 26 | time_t endShift; 27 | voucher* vouchers; 28 | int numVouchers; 29 | 30 | public: 31 | int getShiftNumber() { return shiftNumber; }; 32 | int getCashRegister() { return cashRegister; }; 33 | time_t getStartShift() { return startShift; }; 34 | time_t getEndShift() { return endShift; }; 35 | voucher* getVouchers() { return vouchers; }; 36 | int getNumVouchers() { return numVouchers; }; 37 | 38 | void setShiftNumber(int value) { shiftNumber = value; }; 39 | void setCashRegister(int value) { cashRegister = value; }; 40 | void setStartShift(time_t value) { startShift = value; }; 41 | void setEndShift(time_t value) { endShift = value; }; 42 | 43 | }; 44 | 45 | #endif -------------------------------------------------------------------------------- /BenchmarkCPP/Include/usdsBenchmark.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_BENCHMARK 2 | #define USDS_BENCHMARK 3 | 4 | #include 5 | 6 | #include "USDS\usdsTest.h" 7 | #include "Protobuf\protobufTest.h" 8 | #include "XML\xmlTest.h" 9 | #include "JSON\jsonTest.h" 10 | #include "bsonTest.h" 11 | #include "ASN\asnTest.h" 12 | #include "USDS DOM\usdsDomTest.h" 13 | #include "USDS Basic\usdsBasicTest.h" 14 | 15 | 16 | #endif -------------------------------------------------------------------------------- /BenchmarkCPP/Source/BSON/bsonTest.cpp: -------------------------------------------------------------------------------- 1 | #include "bsonTest.h" 2 | 3 | BsonTest::BsonTest(int counts, int size) 4 | { 5 | test_counts = counts; 6 | TestData = new TicketSales(size, true); 7 | CleanData = new TicketSales(size, false); 8 | bson_data = 0; 9 | 10 | }; 11 | 12 | BsonTest::~BsonTest() 13 | { 14 | if (bson_data != 0) 15 | delete[] bson_data; 16 | delete TestData; 17 | delete CleanData; 18 | 19 | }; 20 | 21 | int BsonTest::serializationTest() 22 | { 23 | //int start_test = clock(); 24 | 25 | mongo::BSONObjBuilder root; 26 | mongo::BSONObjBuilder T; 27 | 28 | T.append("n", TestData->getShiftNumber()); 29 | T.append("r", TestData->getCashRegister()); 30 | T.append("s", TestData->getStartShift()); 31 | T.append("e", TestData->getEndShift()); 32 | 33 | int num_vouchers = TestData->getNumVouchers(); 34 | voucher * vouchers = 0; 35 | vouchers = TestData->getVouchers(); 36 | if (vouchers == 0) 37 | return -1; 38 | 39 | mongo::BSONArrayBuilder V; 40 | for (int i = 0; i < num_vouchers; i++) 41 | { 42 | mongo::BSONObjBuilder I; 43 | I.append("u", vouchers[i].voucher_number); 44 | I.append("s", vouchers[i].summ); 45 | I.append("g", vouchers[i].goods_name); 46 | I.append("t", vouchers[i].time_of_sell); 47 | I.append("b", vouchers[i].status); 48 | V.append(I.obj()); 49 | 50 | } 51 | 52 | T.append("V", V.arr()); 53 | 54 | root.append("T", T.obj()); 55 | 56 | 57 | mongo::BSONObj p = root.obj(); 58 | //cout << p.jsonString() << endl; 59 | 60 | serialization_data_size = p.objsize(); 61 | if (bson_data == 0) 62 | bson_data = new char[serialization_data_size]; 63 | memcpy(bson_data, p.objdata(), serialization_data_size); 64 | 65 | //int end_test = clock(); 66 | //std::cout << "time: " << end_test - start_test << "\n"; 67 | 68 | return 0; 69 | }; 70 | 71 | 72 | int BsonTest::deserializationTest() 73 | { 74 | mongo::BSONObj root(bson_data); 75 | mongo::BSONObj T = root.getField("T").Obj(); 76 | int int_buff = 0; 77 | T.getField("n").Val(int_buff); 78 | CleanData->setShiftNumber(int_buff); 79 | T.getField("r").Val(int_buff); 80 | CleanData->setCashRegister(int_buff); 81 | 82 | time_t time_buff; 83 | T.getField("s").Val(time_buff); 84 | CleanData->setStartShift(time_buff); 85 | T.getField("e").Val(time_buff); 86 | CleanData->setEndShift(time_buff); 87 | 88 | vector V = T.getField("V").Array(); 89 | int size_array = V.size(); 90 | if (size_array != CleanData->getNumVouchers()) 91 | return -1; 92 | 93 | voucher * vouchers = CleanData->getVouchers(); 94 | if (vouchers == 0) 95 | return -2; 96 | 97 | int step = 0; 98 | for (vector::iterator it = V.begin(); it != V.end(); ++it) 99 | { 100 | it->Obj().getField("u").Val(vouchers[step].voucher_number); 101 | it->Obj().getField("s").Val(vouchers[step].summ); 102 | 103 | string str_buff; 104 | it->Obj().getField("g").Val(str_buff); 105 | strcpy(vouchers[step].goods_name, str_buff.c_str()); 106 | 107 | it->Obj().getField("t").Val(vouchers[step].time_of_sell); 108 | it->Obj().getField("b").Val(vouchers[step].status); 109 | 110 | step++; 111 | } 112 | 113 | return 0; 114 | }; 115 | -------------------------------------------------------------------------------- /BenchmarkCPP/Source/Protobuf/protobufTest.cpp: -------------------------------------------------------------------------------- 1 | #include "Protobuf\protobufTest.h" 2 | 3 | ProtobufTest::ProtobufTest(int counts, int size) 4 | { 5 | test_counts = counts; 6 | serializer = new ProtobufTicketSales(); 7 | TestData = new TicketSales(size, true); 8 | CleanData = new TicketSales(size, false); 9 | serialized_data = 0; 10 | 11 | 12 | }; 13 | 14 | ProtobufTest::~ProtobufTest() 15 | { 16 | if (serializer != 0) 17 | delete serializer; 18 | if (serialized_data != 0) 19 | delete[] serialized_data; 20 | delete TestData; 21 | delete CleanData; 22 | 23 | }; 24 | 25 | int ProtobufTest::serializationTest() 26 | { 27 | serializer->set_shiftnumber(TestData->getShiftNumber()); 28 | serializer->set_cashregister(TestData->getCashRegister()); 29 | serializer->set_start_shift(TestData->getStartShift()); 30 | serializer->set_end_shift(TestData->getEndShift()); 31 | int num_vouchers = TestData->getNumVouchers(); 32 | voucher * vouchers = 0; 33 | vouchers = TestData->getVouchers(); 34 | if (vouchers == 0) 35 | return -1; 36 | for (int i = 0; i < num_vouchers; i++) 37 | { 38 | ProtobufTicketSales_ProtobufVoucher* proto_voucher = 0; 39 | proto_voucher = serializer->add_vouchers(); 40 | if (proto_voucher == 0) 41 | return -2; 42 | proto_voucher->set_voucher_number(vouchers[i].voucher_number); 43 | proto_voucher->set_summ(vouchers[i].summ); 44 | proto_voucher->set_goods_name(vouchers[i].goods_name); 45 | proto_voucher->set_time_of_sell(vouchers[i].time_of_sell); 46 | proto_voucher->set_status(vouchers[i].status); 47 | } 48 | 49 | serialization_data_size = serializer->ByteSize(); 50 | 51 | if (serialized_data == 0) 52 | serialized_data = new unsigned char[serialization_data_size]; 53 | 54 | if(!serializer->SerializeToArray(serialized_data, serialization_data_size)) 55 | return -3; 56 | 57 | serializer->Clear(); 58 | 59 | return 0; 60 | }; 61 | 62 | 63 | int ProtobufTest::deserializationTest() 64 | { 65 | if(!serializer->ParseFromArray(serialized_data, serialization_data_size)) 66 | return -1; 67 | CleanData->setShiftNumber(serializer->shiftnumber()); 68 | CleanData->setCashRegister(serializer->cashregister()); 69 | CleanData->setStartShift(serializer->start_shift()); 70 | CleanData->setEndShift(serializer->end_shift()); 71 | 72 | voucher * vouchers = 0; 73 | vouchers = CleanData->getVouchers(); 74 | if (vouchers == 0) 75 | return -2; 76 | int size_array = serializer->vouchers_size(); 77 | if (size_array != CleanData->getNumVouchers()) 78 | return -3; 79 | 80 | for (int i = 0; i < size_array; i++) 81 | { 82 | ProtobufTicketSales_ProtobufVoucher proto_voucher = serializer->vouchers(i); 83 | vouchers[i].voucher_number = proto_voucher.voucher_number(); 84 | vouchers[i].summ = proto_voucher.summ(); 85 | strcpy(vouchers[i].goods_name, proto_voucher.goods_name().c_str()); 86 | vouchers[i].time_of_sell = proto_voucher.time_of_sell(); 87 | vouchers[i].status = proto_voucher.status(); 88 | } 89 | 90 | serializer->Clear(); 91 | 92 | return 0; 93 | }; -------------------------------------------------------------------------------- /BenchmarkCPP/Source/Protobuf/protobufTicketSales.proto: -------------------------------------------------------------------------------- 1 | message ProtobufTicketSales { 2 | required int32 ShiftNumber = 1; 3 | required fixed32 CashRegister = 2; 4 | required fixed64 start_Shift = 3; 5 | required fixed64 end_Shift = 4; 6 | 7 | message ProtobufVoucher { 8 | required int32 voucher_number = 1; 9 | required double summ = 2; 10 | required string goods_name = 3; 11 | required fixed64 time_of_sell = 4; 12 | required bool status = 5; 13 | } 14 | 15 | repeated ProtobufVoucher vouchers = 5; 16 | } -------------------------------------------------------------------------------- /BenchmarkCPP/Source/USDS DOM/usdsDomTest.cpp: -------------------------------------------------------------------------------- 1 | #include "USDS DOM\usdsDomTest.h" 2 | 3 | UsdsDomTest::UsdsDomTest(int counts, int size) 4 | { 5 | test_counts = counts; 6 | parser = new UsdsDomParser(); 7 | TestData = new TicketSales(size, true); 8 | CleanData = new TicketSales(size, false); 9 | 10 | usds_data = 0; 11 | 12 | }; 13 | 14 | UsdsDomTest::~UsdsDomTest() 15 | { 16 | delete parser; 17 | delete TestData; 18 | delete CleanData; 19 | }; 20 | 21 | int UsdsDomTest::serializationTest() 22 | { 23 | UsdsTicketSales* handle = parser->addUsdsTicketSales(); 24 | handle->shiftNumber = TestData->getShiftNumber(); 25 | handle->cashRegister = TestData->getCashRegister(); 26 | handle->startShift = TestData->getStartShift(); 27 | handle->endShift = TestData->getEndShift(); 28 | int voucher_number = TestData->getNumVouchers(); 29 | 30 | voucher * vouchers = 0; 31 | vouchers = TestData->getVouchers(); 32 | if (vouchers == 0) 33 | return -1; 34 | 35 | for (int i = 0; i < voucher_number; i++) 36 | { 37 | UsdsVoucher* arrayHandle = handle->addToVouchers(); 38 | arrayHandle->voucher_number = vouchers[i].voucher_number; 39 | arrayHandle->summ = vouchers[i].summ; 40 | arrayHandle->setGoods_name(USDS_DOM_UTF8, vouchers[i].goods_name); 41 | arrayHandle->time_of_sell = vouchers[i].time_of_sell; 42 | arrayHandle->status = vouchers[i].status; 43 | } 44 | 45 | // if (parser->addHead() != 0) 46 | // return -2; 47 | // if (parser->addDictionary() != 0) 48 | // return -3; 49 | 50 | if (parser->addBody() != 0) 51 | return -4; 52 | if (parser->getUSDS(&usds_data, &serialization_data_size) != 0) 53 | return -5; 54 | 55 | parser->clean(); 56 | 57 | return 0; 58 | }; 59 | 60 | int UsdsDomTest::deserializationTest() 61 | { 62 | int result = parser->parse(usds_data, serialization_data_size); 63 | if (result != 0) 64 | return -1; 65 | 66 | UsdsTicketSales* handle = parser->getFirstUsdsTicketSales(); 67 | CleanData->setShiftNumber(handle->shiftNumber); 68 | CleanData->setCashRegister(handle->cashRegister); 69 | CleanData->setStartShift(handle->startShift); 70 | CleanData->setEndShift(handle->endShift); 71 | int voucher_number = handle->getVouchersSize(); 72 | if (CleanData->getNumVouchers() != voucher_number) 73 | return -2; 74 | 75 | voucher * vouchers = 0; 76 | vouchers = CleanData->getVouchers(); 77 | if (vouchers == 0) 78 | return -3; 79 | 80 | UsdsVoucher* arrayHandle = handle->getFirstInVouchers(); 81 | for (int i = 0; i < voucher_number; i++) 82 | { 83 | vouchers[i].voucher_number = arrayHandle->voucher_number; 84 | vouchers[i].summ = arrayHandle->summ; 85 | strcpy(vouchers[i].goods_name, arrayHandle->getGoods_name()); 86 | vouchers[i].time_of_sell = arrayHandle->time_of_sell; 87 | vouchers[i].status = arrayHandle->status; 88 | arrayHandle = (UsdsVoucher*)arrayHandle->getNextObject(); 89 | }; 90 | 91 | parser->clean(); 92 | 93 | return 0; 94 | }; 95 | 96 | -------------------------------------------------------------------------------- /BenchmarkCPP/Source/USDS/usdsTest.cpp: -------------------------------------------------------------------------------- 1 | #include "USDS\usdsTest.h" 2 | 3 | UsdsTest::UsdsTest(int counts, int size) 4 | { 5 | test_counts = counts; 6 | Serializer = new UsdsSerializer(100000); 7 | Deserializer = new UsdsDeserializer(); 8 | TestData = new TicketSales(size, true); 9 | CleanData = new TicketSales(size, false); 10 | 11 | usds_data = 0; 12 | 13 | }; 14 | 15 | UsdsTest::~UsdsTest() 16 | { 17 | delete Serializer; 18 | delete Deserializer; 19 | delete TestData; 20 | delete CleanData; 21 | }; 22 | 23 | int UsdsTest::serializationTest() 24 | { 25 | if (Serializer->addHead() != 0) 26 | return -1; 27 | if(Serializer->addDictionary()!=0) 28 | return -2; 29 | if (Serializer->addToBody(TestData) != 0) 30 | return -3; 31 | if (Serializer->getUSDS(&usds_data, &serialization_data_size) != 0) 32 | return -4; 33 | if (Serializer->clean()!=0) 34 | return -5; 35 | 36 | return 0; 37 | }; 38 | 39 | int UsdsTest::deserializationTest() 40 | { 41 | //Deserializer->setUsdsVersion(1, 0); 42 | //Deserializer->setDictionaryVersion(1, 0); 43 | 44 | int err_code = Deserializer->setBinary(usds_data, serialization_data_size); 45 | if (err_code != 0) 46 | return -1; 47 | err_code = Deserializer->findFirstAndInit(CleanData); 48 | if (err_code != 0) 49 | return -2; 50 | 51 | Deserializer->clean(); 52 | 53 | return 0; 54 | }; 55 | 56 | -------------------------------------------------------------------------------- /BenchmarkCPP/Source/baseTest.cpp: -------------------------------------------------------------------------------- 1 | #include "baseTest.h" 2 | 3 | BaseTest::BaseTest() 4 | { 5 | serialization_time = 0; 6 | deserialization_time = 0; 7 | checkData = false; 8 | 9 | }; 10 | 11 | BaseTest::~BaseTest() { }; 12 | 13 | int BaseTest::beginTest() 14 | { 15 | int start_test = clock(); 16 | for (int i = 0; i < test_counts; i++) 17 | if (serializationTest()!=0) 18 | return -1; 19 | int end_test = clock(); 20 | serialization_time = end_test - start_test; 21 | 22 | start_test = clock(); 23 | for (int i = 0; i < test_counts; i++) 24 | { 25 | int ret_code = deserializationTest(); 26 | if (ret_code != 0) 27 | return -2; 28 | } 29 | end_test = clock(); 30 | deserialization_time = end_test - start_test; 31 | 32 | if (!checkDataTest()) 33 | return -3; 34 | 35 | return 0; 36 | }; 37 | 38 | bool BaseTest::checkDataTest() 39 | { 40 | if (TestData->getShiftNumber() != CleanData->getShiftNumber()) 41 | return false; 42 | 43 | if (TestData->getCashRegister() != CleanData->getCashRegister()) 44 | return false; 45 | 46 | if (TestData->getStartShift() != CleanData->getStartShift()) 47 | return false; 48 | 49 | if (TestData->getEndShift() != CleanData->getEndShift()) 50 | return false; 51 | 52 | if (TestData->getNumVouchers() != CleanData->getNumVouchers()) 53 | return false; 54 | 55 | for (int i = 0; i < TestData->getNumVouchers(); i++) 56 | { 57 | if (TestData->getVouchers()[i].voucher_number != CleanData->getVouchers()[i].voucher_number) 58 | return false; 59 | 60 | if (TestData->getVouchers()[i].summ != CleanData->getVouchers()[i].summ) 61 | return false; 62 | 63 | if(std::strcmp(TestData->getVouchers()[i].goods_name, CleanData->getVouchers()[i].goods_name)!=0) 64 | return false; 65 | 66 | if (TestData->getVouchers()[i].time_of_sell != CleanData->getVouchers()[i].time_of_sell) 67 | return false; 68 | 69 | if (TestData->getVouchers()[i].status != CleanData->getVouchers()[i].status) 70 | return false; 71 | } 72 | 73 | 74 | return true; 75 | }; -------------------------------------------------------------------------------- /BenchmarkCPP/Source/ticketSales.cpp: -------------------------------------------------------------------------------- 1 | #include "ticketSales.h" 2 | 3 | // This library is needed for USDS - memcpy() 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | TicketSales::TicketSales(int num_vouchers, bool clean) 10 | { 11 | if (clean) 12 | { 13 | shiftNumber = 1234; 14 | cashRegister = 9992828; 15 | startShift = 8887776; 16 | endShift = 8889999; 17 | 18 | numVouchers = num_vouchers; 19 | vouchers = new voucher[numVouchers]; 20 | 21 | for (int i = 0; i < numVouchers; i++) 22 | { 23 | vouchers[i].voucher_number = i; 24 | vouchers[i].summ = i*i; 25 | sprintf(vouchers[i].goods_name, "Goods ID is %i", i); 26 | vouchers[i].time_of_sell = i*i; 27 | if (i/2*2 == i) 28 | vouchers[i].status = true; 29 | else 30 | vouchers[i].status = false; 31 | } 32 | } 33 | else 34 | { 35 | shiftNumber = 0; 36 | cashRegister = 0; 37 | startShift = 0; 38 | endShift = 0; 39 | 40 | numVouchers = num_vouchers; 41 | vouchers = new voucher[numVouchers]; 42 | 43 | for (int i = 0; i < numVouchers; i++) 44 | { 45 | vouchers[i].voucher_number = 0; 46 | vouchers[i].summ = 0; 47 | vouchers[i].goods_name[0] = 0; 48 | vouchers[i].time_of_sell = 0; 49 | vouchers[i].status = false; 50 | } 51 | } 52 | }; 53 | 54 | TicketSales::~TicketSales() 55 | { 56 | delete[] vouchers; 57 | }; 58 | 59 | -------------------------------------------------------------------------------- /SaxParser/AutotestCPP/Source/TestSimpleStruct/Include/testSimpleStruct.h: -------------------------------------------------------------------------------- 1 | #ifndef TEST_SIMPLE_STRUCTS_H 2 | #define TEST_SIMPLE_STRUCTS_H 3 | 4 | #include "baseTestClass.h" 5 | #include "TestSimpleStruct/Include/testStruct.h" 6 | 7 | // Test simple structs 8 | namespace saxParserSimpleStruct 9 | { 10 | 11 | class TestSimpleStruct : public BaseTest 12 | { 13 | public: 14 | TestSimpleStruct(); 15 | virtual ~TestSimpleStruct(); 16 | 17 | Package SaxGetBinary(); 18 | Package SaxGetXml(); 19 | Package SaxGetJson(); 20 | 21 | bool SaxSetBinary(Package input); 22 | bool SaxSetXml(Package input); 23 | bool SaxSetJson(Package input); 24 | 25 | private: 26 | simpleStruct value; 27 | 28 | 29 | }; 30 | } 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /SaxParser/AutotestCPP/Source/TestSimpleStruct/Include/testStruct.h: -------------------------------------------------------------------------------- 1 | #ifndef TEST_STRUCT_H 2 | #define TEST_STRUCT_H 3 | 4 | #include 5 | 6 | // testing of commented code 7 | // test Unicode comments: тест русского комментария 8 | // 9 | //1 10 | //12 11 | //$ 12 | //$1 13 | //$12 14 | 15 | namespace saxParserSimpleStruct 16 | { 17 | //$S MyLittleAPI 18 | struct simpleStruct 19 | { 20 | bool boolParameter; 21 | int8_t byteParameter; 22 | uint8_t ubyteParameter; 23 | int16_t shortParameter; 24 | uint16_t ushortParameter; 25 | int32_t intParameter; 26 | uint32_t uintParameter; 27 | int64_t longParameter; 28 | uint64_t ulongParameter; 29 | float floatParameter; 30 | double doubleParameter; 31 | int64_t varintParameter; 32 | uint64_t uvarintParameter; 33 | //$S ENCODE:UTF-8 34 | char* stringParameter; 35 | char string2Parameter[10]; 36 | }; 37 | 38 | // testing of commented code 39 | /* 40 | //$S MyLittleAPI 41 | struct simpleStruct2 42 | { 43 | bool boolParameter; 44 | int8_t byteParameter; 45 | */ 46 | 47 | } 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /SaxParser/AutotestCPP/Source/TestSimpleStruct/Resource/api.1.0.udic: -------------------------------------------------------------------------------- 1 | USDS 888:MyLittleAPI 1.0 2 | { 3 | 1: simpleStruct 4 | { 5 | 1: BOOLEAN boolParameter; 6 | 2: BYTE byteParameter; 7 | 3: UBYTE ubyteParameter; 8 | 4: SHORT shortParameter; 9 | 5: USHORT ushortParameter; 10 | 6: INT intParameter; 11 | 7: UINT uintParameter; 12 | 8: LONG longParameter; 13 | 9: ULONG ulongParameter; 14 | 10: FLOAT floatParameter; 15 | 11: DOUBLE doubleParameter; 16 | 12: VARINT varintParameter; 17 | 13: UVARINT uvarintParameter; 18 | 14: STRING stringParameter; 19 | 15: STRING string2Parameter; 20 | }; 21 | } -------------------------------------------------------------------------------- /SaxParser/AutotestCPP/Source/TestSimpleStruct/Source/testSimpleStruct.cpp: -------------------------------------------------------------------------------- 1 | #include "TestSimpleStruct/Include/testSimpleStruct.h" 2 | 3 | #include 4 | 5 | using namespace saxParserSimpleStruct; 6 | 7 | 8 | TestSimpleStruct::TestSimpleStruct() 9 | { 10 | value.boolParameter = true; 11 | value.byteParameter = -127; 12 | value.ubyteParameter = 255; 13 | value.shortParameter = -10000; 14 | value.ushortParameter = 20000; 15 | value.intParameter = INT32_MAX; 16 | value.uintParameter = UINT32_MAX; 17 | value.longParameter = INT64_MAX; 18 | value.ulongParameter = UINT64_MAX; 19 | value.floatParameter = 1.25f; 20 | value.doubleParameter = 1.125; 21 | value.stringParameter = new char[10]; 22 | 23 | #pragma warning(disable: 4996) 24 | strcpy(value.stringParameter, "123456789"); 25 | strcpy(value.string2Parameter, "012345678"); 26 | 27 | }; 28 | 29 | TestSimpleStruct::~TestSimpleStruct() 30 | { 31 | delete[] value.stringParameter; 32 | }; 33 | 34 | Package TestSimpleStruct::SaxGetBinary() 35 | { 36 | Package out; 37 | out.body = 0; 38 | out.size = 0; 39 | 40 | 41 | return out; 42 | }; 43 | 44 | Package TestSimpleStruct::SaxGetXml() 45 | { 46 | Package out; 47 | out.body = 0; 48 | out.size = 0; 49 | 50 | 51 | return out; 52 | }; 53 | 54 | Package TestSimpleStruct::SaxGetJson() 55 | { 56 | Package out; 57 | out.body = 0; 58 | out.size = 0; 59 | 60 | 61 | return out; 62 | }; 63 | 64 | bool TestSimpleStruct::SaxSetBinary(Package input) 65 | { 66 | 67 | return true; 68 | }; 69 | 70 | bool TestSimpleStruct::SaxSetXml(Package input) 71 | { 72 | 73 | 74 | return true; 75 | }; 76 | 77 | bool TestSimpleStruct::SaxSetJson(Package input) 78 | { 79 | 80 | 81 | return true; 82 | }; 83 | -------------------------------------------------------------------------------- /SaxParser/AutotestCPP/Source/TestSimpleStruct/usdsAgent.ini: -------------------------------------------------------------------------------- 1 | [Section1] 2 | Value1 = 10 3 | Value2 = a_text_string -------------------------------------------------------------------------------- /SaxParser/AutotestCPP/Source/baseTestClass.h: -------------------------------------------------------------------------------- 1 | #ifndef BASE_TEST_CLASS_H 2 | #define BASE_TEST_CLASS_H 3 | 4 | #include 5 | 6 | namespace saxParserSimpleStruct 7 | { 8 | struct Package 9 | { 10 | uint8_t* body; 11 | size_t size; 12 | }; 13 | 14 | class BaseTest 15 | { 16 | 17 | public: 18 | virtual Package SaxGetBinary() = 0; 19 | virtual Package SaxGetXml() = 0; 20 | virtual Package SaxGetJson() = 0; 21 | 22 | virtual bool SaxSetBinary(Package input) = 0; 23 | virtual bool SaxSetXml(Package input) = 0; 24 | virtual bool SaxSetJson(Package input) = 0; 25 | 26 | }; 27 | 28 | } 29 | 30 | #endif 31 | 32 | 33 | -------------------------------------------------------------------------------- /SaxParser/AutotestCPP/Source/testSaxParser.cpp: -------------------------------------------------------------------------------- 1 | #include "testSaxParser.h" 2 | 3 | using namespace saxParserSimpleStruct; 4 | 5 | int32_t main(int32_t argc, char* argv[]) 6 | { 7 | BaseTest* tests = 0; 8 | Package sax_result; 9 | Package basic_result; 10 | 11 | // Test 1: Test simple structs 12 | std::cout << "Test 1: \"Test simple structs\"\n"; 13 | tests = new TestSimpleStruct(); 14 | std::cout << "USDS Binary: "; 15 | sax_result = tests->SaxGetBinary(); 16 | if (sax_result.size != basic_result.size) 17 | { 18 | std::cout << "error! Sizes of Binary are not equal\n"; 19 | } 20 | else if (memcmp(sax_result.body, basic_result.body, sax_result.size) != 0) 21 | { 22 | std::cout << "error! Results are not equal\n"; 23 | } 24 | else if (tests->SaxSetBinary(sax_result) != true) 25 | { 26 | std::cout << "error! Deserialization failed\n"; 27 | } 28 | std::cout << "passed\n"; 29 | 30 | 31 | std::cout << "Press any key\n"; 32 | std::cin.get(); 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /SaxParser/AutotestCPP/Source/testSaxParser.h: -------------------------------------------------------------------------------- 1 | #ifndef TEST_SAX_PARSER_H 2 | #define TEST_SAX_PARSER_H 3 | 4 | #include 5 | #include 6 | 7 | #include "TestSimpleStruct/Include/testSimpleStruct.h" 8 | 9 | 10 | 11 | 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /SaxParser/AutotestCPP/testSaxParser.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testSaxParser", "testSaxParser.vcxproj", "{92F80DF1-EB80-44DF-B042-85F5FFCF7727}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {92F80DF1-EB80-44DF-B042-85F5FFCF7727}.Debug|x64.ActiveCfg = Debug|x64 17 | {92F80DF1-EB80-44DF-B042-85F5FFCF7727}.Debug|x64.Build.0 = Debug|x64 18 | {92F80DF1-EB80-44DF-B042-85F5FFCF7727}.Debug|x86.ActiveCfg = Debug|Win32 19 | {92F80DF1-EB80-44DF-B042-85F5FFCF7727}.Debug|x86.Build.0 = Debug|Win32 20 | {92F80DF1-EB80-44DF-B042-85F5FFCF7727}.Release|x64.ActiveCfg = Release|x64 21 | {92F80DF1-EB80-44DF-B042-85F5FFCF7727}.Release|x64.Build.0 = Release|x64 22 | {92F80DF1-EB80-44DF-B042-85F5FFCF7727}.Release|x86.ActiveCfg = Release|Win32 23 | {92F80DF1-EB80-44DF-B042-85F5FFCF7727}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /SaxParser/AutotestCPP/testSaxParser.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 1.Test Simple Struct 7 | 8 | 9 | 10 | 11 | {95a57fe8-cf7b-4e31-a48c-243648434a06} 12 | 13 | 14 | 15 | 16 | 17 | 18 | 1.Test Simple Struct 19 | 20 | 21 | 1.Test Simple Struct 22 | 23 | 24 | -------------------------------------------------------------------------------- /SaxParser/UsdsAgent/Include/CodeReaders/CPPCodeReader/cppCodeReader.h: -------------------------------------------------------------------------------- 1 | #ifndef CPP_CODE_READER_H 2 | #define CPP_CODE_READER_H 3 | 4 | #include "BasicParser/Include/usdsBasicParser.h" 5 | 6 | #include 7 | 8 | namespace usdsAgent 9 | { 10 | class CppCodeReader 11 | { 12 | public: 13 | virtual void f() = 0; 14 | 15 | static std::unique_ptr parseSourceCode(std::unique_ptr& dicts, std::unique_ptr& code_mapping); 16 | 17 | private: 18 | 19 | static const char* cppAnnotation; 20 | static const char* cppCodeDictionary; 21 | 22 | 23 | 24 | }; 25 | } 26 | #endif 27 | -------------------------------------------------------------------------------- /SaxParser/UsdsAgent/Include/CodeReaders/codeReader.h: -------------------------------------------------------------------------------- 1 | #ifndef CODE_READER_H 2 | #define CODE_READER_H 3 | 4 | #include "BasicParser/Include/usdsBasicParser.h" 5 | 6 | #include 7 | 8 | namespace usdsAgent 9 | { 10 | class CodeReader 11 | { 12 | public: 13 | virtual void f() = 0; 14 | 15 | static std::unique_ptr parseSourceCode(std::unique_ptr& dicts); 16 | 17 | private: 18 | 19 | static std::unique_ptr initCodeMapping(std::unique_ptr& dicts); 20 | 21 | static const char* codeDictionary; 22 | 23 | }; 24 | 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /SaxParser/UsdsAgent/Include/Common/fileSearcher.h: -------------------------------------------------------------------------------- 1 | #ifndef FILE_SEARCHER_H 2 | #define FILE_SEARCHER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | namespace usdsAgent 12 | { 13 | class FileSearcher 14 | { 15 | public: 16 | virtual void f() = 0; 17 | 18 | static unique_ptr>> findDictFiles(string& rootPath, string& ext); 19 | static unique_ptr>> findCodeFiles(string& rootPath, vector& ext, string& annotation); 20 | 21 | }; 22 | 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /SaxParser/UsdsAgent/Include/Communication/packer.h: -------------------------------------------------------------------------------- 1 | #ifndef PACKER_H 2 | #define PACKER_H 3 | 4 | #include "BasicParser/Include/usdsBasicParser.h" 5 | 6 | #include 7 | 8 | namespace usdsAgent 9 | { 10 | struct Package 11 | { 12 | uint8_t* binary; 13 | size_t size; 14 | }; 15 | 16 | 17 | class Packer 18 | { 19 | public: 20 | virtual void f() = 0; 21 | 22 | static std::unique_ptr packToUsdsBinary(std::unique_ptr& dictdionaries, std::unique_ptr& code_descriptions); 23 | 24 | }; 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /SaxParser/UsdsAgent/Include/Communication/sender.h: -------------------------------------------------------------------------------- 1 | #ifndef SENDER_H 2 | #define SENDER_H 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | namespace usdsAgent 10 | { 11 | class Sender 12 | { 13 | public: 14 | virtual void f() = 0; 15 | 16 | static std::unique_ptr sent(uint8_t* binary, size_t size); 17 | static void wait(std::unique_ptr& session_id); 18 | 19 | }; 20 | 21 | 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /SaxParser/UsdsAgent/Include/Configuration/agentConfig.h: -------------------------------------------------------------------------------- 1 | #ifndef AGENT_CONFIG_H 2 | #define AGENT_CONFIG_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace std; 12 | 13 | namespace usdsAgent 14 | { 15 | enum class command {help, clean, build, rebuild}; 16 | enum class language { cpp }; 17 | 18 | class AgentConfig 19 | { 20 | public: 21 | virtual void f() = 0; 22 | 23 | static void parse(int argc, char* argv[]); 24 | 25 | static boost::log::trivial::severity_level severityLevel; 26 | 27 | static command action; 28 | 29 | static string codePath; 30 | static string iniFile; 31 | 32 | static string dictFileExt; 33 | 34 | static string sourceCodeEncode; 35 | static language programLang; 36 | static vector codeFileExt; 37 | static string cppAnnotation; 38 | 39 | }; 40 | 41 | } 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /SaxParser/UsdsAgent/Include/DictionaryReader/dictionaryReader.h: -------------------------------------------------------------------------------- 1 | #ifndef DICTIONARY_READER_H 2 | #define DICTIONARY_READER_H 3 | 4 | #include "BasicParser/Include/usdsBasicParser.h" 5 | #include 6 | 7 | namespace usdsAgent 8 | { 9 | 10 | class AgentConfig; 11 | 12 | class DictionaryReader 13 | { 14 | public: 15 | virtual void f() = 0; 16 | 17 | static std::unique_ptr findAllDictionaries(); 18 | 19 | 20 | }; 21 | 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /SaxParser/UsdsAgent/Include/usdsAgent.h: -------------------------------------------------------------------------------- 1 | #ifndef USDS_AGENT_H 2 | #define USDS_AGENT_H 3 | 4 | 5 | 6 | 7 | 8 | #endif -------------------------------------------------------------------------------- /SaxParser/UsdsAgent/Source/CodeReaders/CppCodeReader/CppTextReader/flexCppTextReader.h: -------------------------------------------------------------------------------- 1 | #ifndef FLEX_CPP_TEXT_READER 2 | #define FLEX_CPP_TEXT_READER 3 | 4 | #if ! defined(yyFlexLexerOnce) 5 | #include "FlexLexerCppTextReader.h" 6 | #endif 7 | #undef YY_DECL 8 | #define YY_DECL int FlexCppTextReader::scan(BisonCppTextReader::semantic_type * yylval, BisonCppTextReader::location_type* yylloc) 9 | #include "bisonCppTextReader.hh" 10 | 11 | #include 12 | 13 | namespace cppTextReader 14 | { 15 | class FlexCppTextReader : public yyFlexLexerCppTextReader 16 | { 17 | public: 18 | FlexCppTextReader(std::stringstream* input, std::stringstream* output) : yyFlexLexerCppTextReader(input, output) { offset = 0; }; 19 | ~FlexCppTextReader() {}; 20 | 21 | virtual int scan(BisonCppTextReader::semantic_type * yylval, BisonCppTextReader::location_type* yylloc); 22 | 23 | }; 24 | 25 | 26 | }; 27 | #endif -------------------------------------------------------------------------------- /SaxParser/UsdsAgent/Source/CodeReaders/CppCodeReader/CppTextReader/patchFlexAndBison.py: -------------------------------------------------------------------------------- 1 | import io 2 | import re 3 | 4 | f = io.open("position.hh", 'r', encoding='utf8') 5 | lines = [] 6 | for line in f: 7 | lines.append(line) 8 | if line == " /// Compute max(min, lhs+rhs) (provided min <= lhs).\n": 9 | lines.append(u"#pragma warning(disable:4146)\n") 10 | 11 | f.close() 12 | 13 | f_out = io.open("position.hh", 'w', encoding='utf8') 14 | for line in lines: 15 | f_out.write(line) 16 | 17 | f_out.close() 18 | 19 | 20 | f = io.open("flexCppTextReader.cpp", 'r', encoding='utf8') 21 | lines = [] 22 | for line in f: 23 | line = re.sub("yyFlexLexer","yyFlexLexerCppTextReader", line) 24 | line = re.sub("yyalloc","yyallocCppTextReader", line) 25 | line = re.sub("yyfree","yyfreeCppTextReader", line) 26 | line = re.sub("yyrealloc","yyreallocCppTextReader", line) 27 | if line == "#include \n": 28 | lines.append(u"#include \"flexLexerCppTextReader.h\"\n") 29 | else: 30 | lines.append(line) 31 | 32 | f.close() 33 | 34 | f_out = io.open("flexCppTextReader.cpp", 'w', encoding='utf8') 35 | for line in lines: 36 | f_out.write(line) 37 | 38 | f_out.close() 39 | 40 | -------------------------------------------------------------------------------- /SaxParser/UsdsAgent/Source/CodeReaders/CppCodeReader/CppTextReader/win_create_reader.bat: -------------------------------------------------------------------------------- 1 | echo off 2 | win_bison.exe -d -o bisonCppTextReader.cc bisonCppTextReader.y 3 | win_flex.exe -o flexCppTextReader.cpp flexCppTextReader.l 4 | python patchFlexAndBison.py -------------------------------------------------------------------------------- /SaxParser/UsdsAgent/Source/CodeReaders/CppCodeReader/cppCodeReader.cpp: -------------------------------------------------------------------------------- 1 | #include "CodeReaders/CPPCodeReader/cppCodeReader.h" 2 | 3 | #include "Configuration/agentConfig.h" 4 | #include "Common/fileSearcher.h" 5 | 6 | #include 7 | 8 | #include "CppTextReader/flexCppTextReader.h" 9 | #include "CppTextReader/bisonCppTextReader.hh" 10 | 11 | using namespace std; 12 | using namespace usdsAgent; 13 | 14 | const char* CppCodeReader::cppAnnotation = "//$S"; 15 | 16 | // take this string from usdsCppCodeReader.udic in repository 17 | const char* CppCodeReader::cppCodeDictionary = 18 | "USDS UsdsCppCodeReader\n" 19 | "ENCODE:UTF-8\n" 20 | "{\n" 21 | "\tCodeDescription\n" 22 | "\t{\n" 23 | "\t\tAnnotation[] mainAnnotations;\n" 24 | "\t\t typeDescription;\n" 25 | "\t};\n" 26 | "\n" 27 | "\tAnnotation\n" 28 | "\t{\n" 29 | "\t\tSTRING dictionaryName = NULL;\n" 30 | "\t\tUBYTE dictionaryMajorVersion = NULL;\n" 31 | "\t\tUBYTE dictionaryMinorVersion = NULL;\n" 32 | "\t\t attribute = NULL;\n" 33 | "\t};\n" 34 | "\t\n" 35 | "\tStringEncode\n" 36 | "\t{\n" 37 | "\t\tUINT encodeId;\n" 38 | "\t};\n" 39 | "\t\n" 40 | "\tNameMapping\n" 41 | "\t{\n" 42 | "\t\tSTRING mappedName;\n" 43 | "\t};\n" 44 | "\t\n" 45 | "\tStructDescription\n" 46 | "\t{\n" 47 | "\t\tSTRING cppName;\n" 48 | "\t\tElements []\n" 49 | "\t\t{\n" 50 | "\t\t\tAnnotation[] additionalAnnotations = NULL;\n" 51 | "\t\t\t ElementDescription;\n" 52 | "\t\t};\n" 53 | "\t};\n" 54 | "\t\n" 55 | "\tClassDescription\n" 56 | "\t{\n" 57 | "\t\tSTRING cppName;\n" 58 | "\t\tElements []\n" 59 | "\t\t{\n" 60 | "\t\t\tAnnotation[] additionalAnnotations = NULL;\n" 61 | "\t\t\t ElementDescription;\n" 62 | "\t\t};\n" 63 | "\t};\n" 64 | "\t\n" 65 | "\tFieldDescription\n" 66 | "\t{\n" 67 | "\t\tSTRING fieldName;\n" 68 | "\t\tSTRING typeName;\n" 69 | "\t\tENUM fieldKind { simple = 1, link = 2, reference = 3 };\n" 70 | "\t\tUBYTE linksNumber = NULL;\n" 71 | "\t\tUVARINT[] arraySizes = NULL;\n" 72 | "\t};\n" 73 | "\t\n" 74 | "\tMethodDescription\n" 75 | "\t{\n" 76 | "\t\tSTRING methodName;\n" 77 | "\t\n" 78 | "\t};\n" 79 | "\n" 80 | "}" 81 | ; 82 | 83 | std::unique_ptr CppCodeReader::parseSourceCode(std::unique_ptr& dicts, std::unique_ptr& code_mapping) 84 | { 85 | 86 | auto dictFiles = FileSearcher::findCodeFiles(AgentConfig::codePath, AgentConfig::codeFileExt, AgentConfig::cppAnnotation); 87 | 88 | BOOST_LOG_TRIVIAL(debug) << "Read dictionary 'cppCodeDictionary'"; 89 | auto codeDescription = make_unique();; 90 | codeDescription->addDictionaryFromText(cppCodeDictionary, 0, usds::USDS_UTF8); 91 | 92 | BOOST_LOG_TRIVIAL(info) << "Read code files:"; 93 | // Parse code files 94 | for (auto it = dictFiles->begin(); it != dictFiles->end(); ++it) 95 | { 96 | BOOST_LOG_TRIVIAL(info) << (*it).first; 97 | // Creating scanner and parser 98 | std::stringstream input; 99 | std::stringstream output; 100 | input << (*it).second.c_str(); 101 | cppTextReader::FlexCppTextReader scanner(&input, &output); 102 | cppTextReader::BisonCppTextReader textParser(&scanner, (*it).second.c_str(), codeDescription, 0); 103 | // Parse! 104 | textParser.parse(); 105 | } 106 | 107 | std::string json = ""; 108 | codeDescription->getJSON(usds::USDS_UTF8, &json); 109 | BOOST_LOG_TRIVIAL(debug) << "Result:\n" << json; 110 | 111 | return codeDescription; 112 | 113 | 114 | 115 | } 116 | -------------------------------------------------------------------------------- /SaxParser/UsdsAgent/Source/CodeReaders/CppCodeReader/usdsCppCodeReader.udic: -------------------------------------------------------------------------------- 1 | USDS UsdsCppCodeReader 2 | ENCODE:UTF-8 3 | { 4 | CodeDescription 5 | { 6 | Annotation[] mainAnnotations; 7 | typeDescription; 8 | }; 9 | 10 | Annotation 11 | { 12 | STRING dictionaryName = NULL; 13 | UBYTE dictionaryMajorVersion = NULL; 14 | UBYTE dictionaryMinorVersion = NULL; 15 | attribute = NULL; 16 | }; 17 | 18 | StringEncode 19 | { 20 | UINT encodeId; 21 | }; 22 | 23 | NameMapping 24 | { 25 | STRING mappedName; 26 | }; 27 | 28 | StructDescription 29 | { 30 | STRING cppName; 31 | Elements [] 32 | { 33 | Annotation[] additionalAnnotations = NULL; 34 | ElementDescription; 35 | }; 36 | }; 37 | 38 | ClassDescription 39 | { 40 | STRING cppName; 41 | Elements [] 42 | { 43 | Annotation[] additionalAnnotations = NULL; 44 | ElementDescription; 45 | }; 46 | }; 47 | 48 | FieldDescription 49 | { 50 | STRING fieldName; 51 | STRING typeName; 52 | ENUM fieldKind { simple = 1, link = 2, reference = 3 }; 53 | UBYTE linksNumber = NULL; 54 | UVARINT[] arraySizes = NULL; 55 | }; 56 | 57 | MethodDescription 58 | { 59 | STRING methodName; 60 | 61 | }; 62 | 63 | } -------------------------------------------------------------------------------- /SaxParser/UsdsAgent/Source/CodeReaders/usdsSaxParser.udic: -------------------------------------------------------------------------------- 1 | USDS 100001:UsdsCodeDescription 0.1 2 | ENCODE:UTF-8 3 | { 4 | ParserDescription 5 | { 6 | ENUM language { Cpp=1, C=2, CS=3, Java=4 }; 7 | languageParameters; 8 | CodeDescription [] 9 | { 10 | STRING dictionaryName; 11 | UINT dictionaryID; 12 | Versions [] 13 | { 14 | UBYTE majorVersion; 15 | UBYTE minorVersion; 16 | TagDescriptions [] 17 | { 18 | STRING tagName; 19 | INT tagID; 20 | STRING codeName; 21 | ENUM codeType { struct=1, class=2 }; 22 | STRING codeCreateMethod = NULL; 23 | STRING codeBeforeMethod = NULL; 24 | STRING codeAfterMethod = NULL; 25 | codeTypeDescription = NULL; 26 | }; 27 | }; 28 | }; 29 | }; 30 | 31 | StructDescription 32 | { 33 | fieldsDescription [] 34 | { 35 | STRING fieldName; 36 | INT fieldID; 37 | STRING codeName = NULL; 38 | ENUM codeType { bool, int8, int32, float, double }; 39 | STRING codeSetMethod = NULL; 40 | STRING codeGetMethod = NULL; 41 | STRING codeCreateMethod = NULL; 42 | STRING codeBeforeMethod = NULL; 43 | STRING codeAfterMethod = NULL; 44 | }; 45 | StructDescription[] inheritors = NULL; 46 | StructDescription[] subStructs = NULL; 47 | }; 48 | 49 | ClassDescription 50 | { 51 | fieldsDescription [] 52 | { 53 | STRING fieldName; 54 | INT fieldID; 55 | STRING codeName = NULL; 56 | ENUM codeType { bool, int8, int32, float, double }; 57 | STRING codeSetMethod = NULL; 58 | STRING codeGetMethod = NULL; 59 | STRING codeCreateMethod = NULL; 60 | STRING codeBeforeMethod = NULL; 61 | STRING codeAfterMethod = NULL; 62 | }; 63 | ClassDescription[] inheritors = NULL; 64 | ClassDescription[] subClass = NULL; 65 | }; 66 | 67 | CppParameters 68 | { 69 | ENUM platform { x86, ARM }; 70 | ENUM mode { debug, release, both }; 71 | ENUM linkMode { static, dynamic }; 72 | ENUM operationSystem { windows, linux }; 73 | }; 74 | 75 | CParameters 76 | { 77 | ENUM platform { x86, ARM }; 78 | ENUM mode { debug, release, both }; 79 | ENUM linkMode { static, dynamic }; 80 | ENUM operationSystem { windows, linux }; 81 | }; 82 | 83 | CsParameters 84 | { 85 | ENUM mode {debug, release, both }; 86 | }; 87 | 88 | } -------------------------------------------------------------------------------- /SaxParser/UsdsAgent/Source/Common/fileSearcher.cpp: -------------------------------------------------------------------------------- 1 | #include "Common/fileSearcher.h" 2 | 3 | #include "boost/filesystem.hpp" 4 | #include "boost/filesystem/fstream.hpp" 5 | #include "BasicParser/Include/common/errorMessage.h" 6 | 7 | #include 8 | #include 9 | 10 | using namespace usdsAgent; 11 | using namespace boost::filesystem; 12 | 13 | unique_ptr>> FileSearcher::findDictFiles(string& rootPath, string& ext) 14 | try 15 | { 16 | path p(rootPath.c_str()); 17 | if (!exists(p)) 18 | throw usds::ErrorStack("FileSearcher::findDictFiles") << rootPath.c_str() << ext.c_str() << (usds::ErrorMessage(3, "Directory '") << rootPath.c_str() << "' does not exist"); 19 | if (!is_directory(p)) 20 | throw usds::ErrorStack("FileSearcher::findDictFiles") << rootPath.c_str() << ext.c_str() << (usds::ErrorMessage(4, "Path '") << rootPath.c_str() << "' is not a directory"); 21 | 22 | // find all files recursively 23 | recursive_directory_iterator it(p); 24 | recursive_directory_iterator endit; 25 | 26 | auto outList = make_unique>>(); 27 | 28 | while (it != endit) 29 | { 30 | if (is_regular_file(*it) && it->path().extension() == ext) 31 | { 32 | boost::filesystem::ifstream file(it->path()); 33 | // read file to output list 34 | string content 35 | ( 36 | (std::istreambuf_iterator(file)), 37 | (std::istreambuf_iterator()) 38 | ); 39 | outList->push_back(make_pair(it->path().string(), content)); 40 | } 41 | it++; 42 | } 43 | 44 | if (outList->size() == 0) 45 | throw usds::ErrorStack("FileSearcher::findDictFiles") << rootPath.c_str() << ext.c_str() << (usds::ErrorMessage(5, "Dictionary files not found in '") << rootPath.c_str() << "' (***." << ext.c_str() << ")"); 46 | 47 | return outList; 48 | 49 | } 50 | catch (filesystem_error err) 51 | { 52 | throw usds::ErrorStack("FileSearcher::findDictFiles") << rootPath.c_str() << ext.c_str() << usds::ErrorMessage(3, err.what()); 53 | } 54 | 55 | unique_ptr>> FileSearcher::findCodeFiles(string& rootPath, vector& ext, string& annotation) 56 | try 57 | { 58 | path p(rootPath.c_str()); 59 | if (!exists(p)) 60 | throw usds::ErrorMessage(3, "Directory '") << rootPath.c_str() << "' does not exist"; 61 | if (!is_directory(p)) 62 | throw usds::ErrorMessage(4, "Path '") << rootPath.c_str() << "' is not a directory"; 63 | 64 | // find all files recursively 65 | recursive_directory_iterator it(p); 66 | recursive_directory_iterator endit; 67 | 68 | auto outList = make_unique>>(); 69 | 70 | while (it != endit) 71 | { 72 | if (is_regular_file(*it)) 73 | { 74 | auto it_ext = find(ext.begin(), ext.end(), it->path().extension()); 75 | if (it_ext != ext.end()) 76 | { 77 | boost::filesystem::ifstream file(it->path()); 78 | // read file to output list 79 | string content 80 | ( 81 | (std::istreambuf_iterator(file)), 82 | (std::istreambuf_iterator()) 83 | ); 84 | if (content.find(annotation) != string::npos) 85 | outList->push_back(make_pair(it->path().string(), content)); 86 | } 87 | } 88 | it++; 89 | } 90 | 91 | if (outList->size() == 0) 92 | throw usds::ErrorMessage(5, "Code files not found in '") << rootPath.c_str(); 93 | 94 | return outList; 95 | } 96 | catch(usds::ErrorMessage msg) 97 | { 98 | throw usds::ErrorStack("FileSearcher::findCodeFiles") << rootPath.c_str() << (void*)&ext << msg; 99 | } 100 | catch (filesystem_error err) 101 | { 102 | throw usds::ErrorStack("FileSearcher::findCodeFiles") << rootPath.c_str() << (void*)&ext << usds::ErrorMessage(3, err.what()); 103 | } 104 | 105 | 106 | -------------------------------------------------------------------------------- /SaxParser/UsdsAgent/Source/Communication/packer.cpp: -------------------------------------------------------------------------------- 1 | #include "Communication/packer.h" 2 | 3 | using namespace usdsAgent; 4 | 5 | std::unique_ptr Packer::packToUsdsBinary(std::unique_ptr& dictdionaries, std::unique_ptr& code_descriptions) 6 | { 7 | auto output = std::make_unique(); 8 | 9 | output->binary = 0; 10 | output->size = 0; 11 | 12 | 13 | return output; 14 | } -------------------------------------------------------------------------------- /SaxParser/UsdsAgent/Source/Communication/sender.cpp: -------------------------------------------------------------------------------- 1 | #include "Communication/sender.h" 2 | 3 | using namespace usdsAgent; 4 | 5 | 6 | std::unique_ptr Sender::sent(uint8_t* binary, size_t size) 7 | { 8 | 9 | auto output = make_unique(); 10 | return output; 11 | } 12 | 13 | void Sender::wait(std::unique_ptr& session_id) 14 | { 15 | 16 | 17 | 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /SaxParser/UsdsAgent/Source/Configuration/agentConfig.cpp: -------------------------------------------------------------------------------- 1 | #include "Configuration/agentConfig.h" 2 | 3 | #include "boost/property_tree/ptree.hpp" 4 | #include "boost/property_tree/ini_parser.hpp" 5 | #include "boost/program_options.hpp" 6 | 7 | #include "BasicParser/Include/common/errorMessage.h" 8 | 9 | #include 10 | 11 | using namespace boost::property_tree; 12 | using namespace boost::program_options; 13 | 14 | using namespace std; 15 | 16 | using namespace usdsAgent; 17 | 18 | // initial values 19 | #ifdef _DEBUG 20 | boost::log::trivial::severity_level AgentConfig::severityLevel = boost::log::trivial::debug; 21 | #else 22 | boost::log::trivial::severity_level AgentConfig::severityLevel = boost::log::trivial::info; 23 | #endif 24 | command AgentConfig::action = command::build; 25 | string AgentConfig::codePath = "."; 26 | string AgentConfig::iniFile = "usdsAgent.ini"; 27 | string AgentConfig::dictFileExt = ".udic"; 28 | string AgentConfig::sourceCodeEncode = "UTF-8"; 29 | language AgentConfig::programLang = language::cpp; 30 | vector AgentConfig::codeFileExt = {".cpp", ".h"}; 31 | string AgentConfig::cppAnnotation = "//$S"; 32 | 33 | void AgentConfig::parse(int argc, char* argv[]) 34 | try 35 | { 36 | // analize command line 37 | options_description command_line_options{ "Options" }; 38 | command_line_options.add_options() 39 | ("help,h", "Help screen") 40 | ("build", "Build parser") 41 | ("clean", "Clean") 42 | ("rebuild", "Rebuild") 43 | ("codePath,c", value(), "Source code directory to analize") 44 | ("iniFile,i", value(), "Configuration file"); 45 | variables_map command_line_parameters; 46 | store(parse_command_line(argc, argv, command_line_options), command_line_parameters); 47 | 48 | // Parameters from configuration file 49 | if (command_line_parameters.count("iniFile")) 50 | { 51 | iniFile = command_line_parameters["iniFile"].as().c_str(); 52 | } 53 | ptree agentConfig; 54 | ini_parser::read_ini(iniFile, agentConfig); 55 | 56 | // Parameters from command line 57 | if (command_line_parameters.count("help")) 58 | { 59 | BOOST_LOG_TRIVIAL(info) << command_line_options; 60 | action = command::help; 61 | } 62 | else 63 | { 64 | if (command_line_parameters.count("codePath")) 65 | codePath = command_line_parameters["codePath"].as().c_str(); 66 | } 67 | 68 | // Logger initialization 69 | boost::log::core::get()->set_filter 70 | ( 71 | boost::log::trivial::severity >= severityLevel 72 | ); 73 | 74 | } 75 | catch (boost::property_tree::ptree_error config_error) 76 | { 77 | throw usds::ErrorStack("AgentConfig::AgentConfig") << argc << argv << usds::ErrorMessage(1, config_error.what()); 78 | } 79 | catch (const error ¶meter_error) 80 | { 81 | throw usds::ErrorStack("AgentConfig::AgentConfig") << argc << argv << usds::ErrorMessage(2, parameter_error.what()); 82 | }; 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /SaxParser/UsdsAgent/Source/DictionaryReader/dictionaryReader.cpp: -------------------------------------------------------------------------------- 1 | #include "DictionaryReader/dictionaryReader.h" 2 | 3 | #include "Configuration/agentConfig.h" 4 | #include "Common/fileSearcher.h" 5 | 6 | #include "BasicParser/Include/common/errorMessage.h" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | using namespace usdsAgent; 13 | 14 | std::unique_ptr DictionaryReader::findAllDictionaries() 15 | try 16 | { 17 | if (AgentConfig::action == command::help || AgentConfig::action == command::clean) 18 | return nullptr; 19 | 20 | BOOST_LOG_TRIVIAL(info) << "Read usds-dictionary files"; 21 | auto dictFiles = FileSearcher::findDictFiles(AgentConfig::codePath, AgentConfig::dictFileExt); 22 | 23 | auto dicts = make_unique(); 24 | for(auto it = dictFiles->begin(); it != dictFiles->end(); ++it) 25 | { 26 | BOOST_LOG_TRIVIAL(debug) << (*it).first; 27 | dicts->addDictionaryFromText((*it).second.c_str(), 0, usds::USDS_UTF8); 28 | BOOST_LOG_TRIVIAL(debug) << dicts->getDictionaryName() << " " << dicts->getDictionaryID() << "." << (uint32_t)dicts->getDictionaryMajor() << "." << (uint32_t)dicts->getDictionaryMinor() << " success"; 29 | } 30 | 31 | return dicts; 32 | 33 | } 34 | catch (usds::ErrorStack err) 35 | { 36 | throw err.addLevel("DictionaryReader::findAllDictionaries"); 37 | 38 | } 39 | 40 | -------------------------------------------------------------------------------- /SaxParser/UsdsAgent/Source/usdsAgent.cpp: -------------------------------------------------------------------------------- 1 | #include "usdsAgent.h" 2 | 3 | #include "BasicParser/Include/common/errorMessage.h" 4 | #include "BasicParser/Include/usdsBasicParser.h" 5 | 6 | #include "Configuration/agentConfig.h" 7 | #include "DictionaryReader/dictionaryReader.h" 8 | #include "CodeReaders/codeReader.h" 9 | #include "Communication/packer.h" 10 | #include "Communication/sender.h" 11 | 12 | #include 13 | 14 | using namespace usdsAgent; 15 | using namespace std; 16 | 17 | int main(int argc, char* argv[]) 18 | try 19 | { 20 | AgentConfig::parse(argc, argv); 21 | auto usdsDictionaries = DictionaryReader::findAllDictionaries(); 22 | auto codeMapping = CodeReader::parseSourceCode(usdsDictionaries); 23 | auto package = Packer::packToUsdsBinary(usdsDictionaries, codeMapping); 24 | auto session_id = Sender::sent(package->binary, package->size); 25 | Sender::wait(session_id); 26 | 27 | #ifdef _DEBUG 28 | cout << "Press enter"; 29 | cin.get(); 30 | #endif 31 | 32 | return 0; 33 | } 34 | catch (usds::ErrorStack msg) 35 | { 36 | BOOST_LOG_TRIVIAL(fatal) << msg.getMessage(); 37 | #ifdef _DEBUG 38 | cout << "Press enter"; 39 | cin.get(); 40 | #endif 41 | return -1; 42 | } 43 | 44 | 45 | -------------------------------------------------------------------------------- /SaxParser/UsdsAgent/UsdsAgent.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UsdsAgent", "UsdsAgent.vcxproj", "{0C35A7D6-405A-4674-A6FB-472E749AA3CC}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {0C35A7D6-405A-4674-A6FB-472E749AA3CC}.Debug|x64.ActiveCfg = Debug|x64 17 | {0C35A7D6-405A-4674-A6FB-472E749AA3CC}.Debug|x64.Build.0 = Debug|x64 18 | {0C35A7D6-405A-4674-A6FB-472E749AA3CC}.Debug|x86.ActiveCfg = Debug|Win32 19 | {0C35A7D6-405A-4674-A6FB-472E749AA3CC}.Debug|x86.Build.0 = Debug|Win32 20 | {0C35A7D6-405A-4674-A6FB-472E749AA3CC}.Release|x64.ActiveCfg = Release|x64 21 | {0C35A7D6-405A-4674-A6FB-472E749AA3CC}.Release|x64.Build.0 = Release|x64 22 | {0C35A7D6-405A-4674-A6FB-472E749AA3CC}.Release|x86.ActiveCfg = Release|Win32 23 | {0C35A7D6-405A-4674-A6FB-472E749AA3CC}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | USDS home page: 2 | http://www.it-dc.org/projects/USDS --------------------------------------------------------------------------------