src/FreeformASN1ContentHandler.h
branchv_0
changeset 3 807f8543d10e
parent 2 7128fabeede0
child 4 368ba99bb98f
equal deleted inserted replaced
2:7128fabeede0 3:807f8543d10e
    13  *
    13  *
    14  * You should have received a copy of the GNU General Public License
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
    15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
    16  */
    16  */
    17 #pragma once
    17 #pragma once
       
    18 
       
    19 #include <string>
    18 
    20 
    19 #include <relpipe/writer/RelationalWriter.h>
    21 #include <relpipe/writer/RelationalWriter.h>
    20 #include "lib/ASN1ContentHandler.h"
    22 #include "lib/ASN1ContentHandler.h"
    21 #include "Configuration.h"
    23 #include "Configuration.h"
    22 
    24 
    48 		relpipe::common::type::Integer tag = r.header ? r.header->tag : -1; // TODO: null + possible integer overflow
    50 		relpipe::common::type::Integer tag = r.header ? r.header->tag : -1; // TODO: null + possible integer overflow
    49 		relpipe::common::type::Integer id = r.position.back();
    51 		relpipe::common::type::Integer id = r.position.back();
    50 		relpipe::common::type::Integer parent = r.position[r.position.size() - 2];
    52 		relpipe::common::type::Integer parent = r.position[r.position.size() - 2];
    51 		relpipe::common::type::Integer level = r.position.size() - 2;
    53 		relpipe::common::type::Integer level = r.position.size() - 2;
    52 
    54 
       
    55 		relpipe::common::type::StringX pc;
       
    56 		relpipe::common::type::StringX tagClass;
       
    57 
       
    58 		if (r.header) {
       
    59 			if (r.header->pc == PC::Primitive) pc = L"primitive";
       
    60 			else if (r.header->pc == PC::Constructed) pc = L"primitive";
       
    61 			else throw std::logic_error("Unexpected PC: " + std::to_string((uint8_t) r.header->pc)); // should never happen
       
    62 
       
    63 			if (r.header->tagClass == TagClass::Universal) tagClass = L"universal";
       
    64 			else if (r.header->tagClass == TagClass::ContextSpecific) tagClass = L"context";
       
    65 			else if (r.header->tagClass == TagClass::Application) tagClass = L"application";
       
    66 			else if (r.header->tagClass == TagClass::Private) tagClass = L"private";
       
    67 			else throw std::logic_error("Unexpected TagClass: " + std::to_string((uint8_t) r.header->tagClass)); // should never happen
       
    68 		}
       
    69 
    53 		writer->writeAttribute(&id, typeid (id));
    70 		writer->writeAttribute(&id, typeid (id));
    54 		writer->writeAttribute(&parent, typeid (parent));
    71 		writer->writeAttribute(&parent, typeid (parent));
    55 		writer->writeAttribute(&level, typeid (level));
    72 		writer->writeAttribute(&level, typeid (level));
    56 		writer->writeAttribute(&r.event, typeid (r.event));
    73 		writer->writeAttribute(&r.event, typeid (r.event));
       
    74 		// writer->writeAttribute(&pc, typeid (pc));
       
    75 		writer->writeAttribute(&tagClass, typeid (tagClass));
    57 		writer->writeAttribute(&tag, typeid (tag));
    76 		writer->writeAttribute(&tag, typeid (tag));
    58 	}
    77 	}
    59 
    78 
    60 public:
    79 public:
    61 
    80 
    70 		writer->startRelation(configuration.relation,{
    89 		writer->startRelation(configuration.relation,{
    71 			{L"id", relpipe::writer::TypeId::INTEGER},
    90 			{L"id", relpipe::writer::TypeId::INTEGER},
    72 			{L"parent", relpipe::writer::TypeId::INTEGER},
    91 			{L"parent", relpipe::writer::TypeId::INTEGER},
    73 			{L"level", relpipe::writer::TypeId::INTEGER},
    92 			{L"level", relpipe::writer::TypeId::INTEGER},
    74 			{L"event", relpipe::writer::TypeId::STRING},
    93 			{L"event", relpipe::writer::TypeId::STRING},
    75 			//{L"pc", relpipe::writer::TypeId::STRING},
    94 			// {L"pc", relpipe::writer::TypeId::STRING},
    76 			//{L"tag_class", relpipe::writer::TypeId::STRING},
    95 			{L"tag_class", relpipe::writer::TypeId::STRING},
    77 			{L"tag", relpipe::writer::TypeId::INTEGER},
    96 			{L"tag", relpipe::writer::TypeId::INTEGER},
    78 		}, true);
    97 		}, true);
    79 
    98 
    80 		position.push_back(-1); // TODO: null
    99 		position.push_back(-1); // TODO: null
    81 		position.push_back(1);
   100 		position.push_back(1);