[esnacc-dev] [PATCH] iomanip: Add an IO Manipulator for C++
Aaron Conole
aconole at bytheb.org
Fri Sep 23 18:33:10 UTC 2016
This patch starts on a series adding IO Manipulators for C++ support.
Currently, Print(), and BEnc() are supported. A future commit will add
support for input streams.
As new Encode/Decode rules are added, it is expected that additional
manipulators will be created to make convenient IO routines.
Signed-off-by: Aaron Conole <aconole at bytheb.org>
---
cxx-examples/src/automatic.cpp | 8 ++++++--
cxx-lib/inc/asn-incl.h | 13 +++++++------
cxx-lib/src/print.cpp | 21 +++++++++++++++++++--
3 files changed, 32 insertions(+), 10 deletions(-)
diff --git a/cxx-examples/src/automatic.cpp b/cxx-examples/src/automatic.cpp
index b35f5aa..7c08b91 100644
--- a/cxx-examples/src/automatic.cpp
+++ b/cxx-examples/src/automatic.cpp
@@ -1,4 +1,5 @@
#include "autotags.h"
+#include <sstream>
static SNACC::Human *
getHuman(const char *name, int age, bool isBiblical,
@@ -102,10 +103,13 @@ int automaticTests()
return 1;
}
- SNACC::AsnBuf benc;
SNACC::AsnBuf expected((const char *)(t[i].bytes), t[i].byte_len);
try {
- h.BEnc(benc);
+ std::stringstream s;
+ s << SNACC::EncodeBER;
+ s << h;
+ SNACC::AsnBuf benc(s.str().c_str(), s.str().length());
+
if (!(benc == expected)) {
fail_enc = true;
}
diff --git a/cxx-lib/inc/asn-incl.h b/cxx-lib/inc/asn-incl.h
index ebd04ee..7270f28 100644
--- a/cxx-lib/inc/asn-incl.h
+++ b/cxx-lib/inc/asn-incl.h
@@ -1404,18 +1404,19 @@ extern "C" {
void SNACCDLL_API SNACC_CleanupMemory();
}
-
//########################################################################
//########################################################################
-_END_SNACC_NAMESPACE
-
-// Overload of operator<< to stream out an AsnType
-SNACCDLL_API std::ostream& operator<<(std::ostream& os,
- const SNACC::AsnType& a);
+enum SNACCEncodeDecodeRules {
+ SNACC_ASCII,
+ BER,
+ PER
+};
+_END_SNACC_NAMESPACE
+#include "asn-iomanip.h"
#include "snaccexcept.h"
#include "asn-usefultypes.h"
diff --git a/cxx-lib/src/print.cpp b/cxx-lib/src/print.cpp
index e19b54f..075049d 100644
--- a/cxx-lib/src/print.cpp
+++ b/cxx-lib/src/print.cpp
@@ -17,7 +17,7 @@
//
#include "asn-incl.h"
-
+#include "asn-iomanip.h"
void SNACC::Indent(std::ostream& os, unsigned short i)
{
@@ -27,6 +27,23 @@ void SNACC::Indent(std::ostream& os, unsigned short i)
std::ostream& operator<<(std::ostream& os, const SNACC::AsnType& v)
{
- v.Print(os);
+ switch(SNACC::SNACC_getiosencodetype(os)) {
+ default:
+ case SNACC::SNACC_ASCII:
+ v.Print(os);
+ break;
+ case SNACC::BER:
+ {
+ SNACC::AsnBuf b(os.rdbuf());
+ b.ResetMode(std::ios_base::out);
+ v.BEnc(b);
+ }
+ break;
+ case SNACC::PER:
+ throw SNACC::SnaccException(__FILE__, __LINE__,
+ "operator<<",
+ "No Proper PER Support at this time");
+ break;
+ }
return os;
}
--
2.7.4
More information about the dev
mailing list