src/lib/ASN1ContentHandler.h
branchv_0
changeset 8 d37c1a5d09ce
parent 4 7230e1ea0b07
child 9 7a6abdd00ab5
equal deleted inserted replaced
7:afb7f3a4981a 8:d37c1a5d09ce
    25 namespace lib {
    25 namespace lib {
    26 
    26 
    27 class ASN1ContentHandler {
    27 class ASN1ContentHandler {
    28 public:
    28 public:
    29 
    29 
       
    30 	enum class CollectionType {
       
    31 		Sequence,
       
    32 		Set
       
    33 	};
       
    34 
       
    35 	enum class StringType {
       
    36 		OctetString,
       
    37 		UTF8String,
       
    38 		NumericString,
       
    39 		PrintableString,
       
    40 		T61String,
       
    41 		VideotexString,
       
    42 		IA5String,
       
    43 		GraphicString,
       
    44 		VisibleString,
       
    45 		GeneralString,
       
    46 		UniversalString,
       
    47 		CharacterString,
       
    48 		BMPString,
       
    49 	};
       
    50 
    30 	virtual ~ASN1ContentHandler() = default;
    51 	virtual ~ASN1ContentHandler() = default;
    31 
    52 
    32 	virtual void abc() = 0; // FIXME: remove dummy method
    53 	virtual void writeCollectionStart(CollectionType type) = 0;
    33 	virtual void def(int a) = 0; // FIXME: remove dummy method
    54 	virtual void writeCollectionEnd() = 0;
    34 	virtual void ghi(int a, int b) = 0; // FIXME: remove dummy method
    55 	virtual void writeBoolean(bool value) = 0;
       
    56 	virtual void writeNull() = 0;
       
    57 	virtual void writeInteger(int64_t value) = 0;
       
    58 	virtual void writeString(StringType type, std::string value) = 0;
       
    59 	// virtual void writeOID(std::string value) = 0;
       
    60 	// Object descriptor
       
    61 	// virtual void writeReal(float value) = 0;
       
    62 	// Enumerated
       
    63 	// Embedded PVD
       
    64 	// Relative OID
       
    65 	// TIME
       
    66 	// UTC time
       
    67 	// Generalized time
       
    68 	// Date
       
    69 	// Time of day
       
    70 	// Date-time
       
    71 	// Duration
       
    72 	// OID-IRI
       
    73 	// Relative OID-IRI
    35 
    74 
    36 };
    75 };
    37 
    76 
    38 class ASN1ContentHandlerProxy : public ASN1ContentHandler {
    77 class ASN1ContentHandlerProxy : public ASN1ContentHandler {
    39 private:
    78 private:
    44 		handlers.push_back(handler);
    83 		handlers.push_back(handler);
    45 	}
    84 	}
    46 
    85 
    47 #define handler for (auto ___h : handlers) ___h
    86 #define handler for (auto ___h : handlers) ___h
    48 
    87 
    49 	void abc() override {
    88 	void writeCollectionStart(CollectionType type) {
    50 		handler->abc();
    89 		handler->writeCollectionStart(type);
    51 	}
    90 	}
    52 
    91 
    53 	void def(int a) override {
    92 	void writeCollectionEnd() {
    54 		handler->def(a);
    93 		handler->writeCollectionEnd();
    55 	}
    94 	}
    56 
    95 
    57 	void ghi(int a, int b) override {
    96 	void writeBoolean(bool value) {
    58 		handler->ghi(a, b);
    97 		handler->writeBoolean(value);
       
    98 	}
       
    99 
       
   100 	void writeNull() {
       
   101 		handler->writeNull();
       
   102 	}
       
   103 
       
   104 	void writeInteger(int64_t value) {
       
   105 		handler->writeInteger(value);
       
   106 	}
       
   107 
       
   108 	void writeString(StringType type, std::string value) {
       
   109 		handler->writeString(type, value);
    59 	}
   110 	}
    60 
   111 
    61 #undef handler
   112 #undef handler
    62 
   113 
    63 };
   114 };