8#ifndef INCLUDED_BALXML_ENCODER
9#define INCLUDED_BALXML_ENCODER
155#include <balscm_version.h>
183#include <bsl_ostream.h>
184#include <bsl_string.h>
185#include <bsl_vector.h>
190class Encoder_Context;
211 class MemOutStream :
public bsl::ostream
216 MemOutStream(
const MemOutStream&);
217 MemOutStream& operator=(
const MemOutStream&);
243 const
char *data() const;
253 bslma::Allocator *d_allocator;
256 bsls::ObjectBuffer<MemOutStream> d_logArea;
260 MemOutStream *d_logStream;
264 bsl::ostream *d_errorStream;
265 bsl::ostream *d_warningStream;
268 ErrorInfo::Severity logError(const
char *text,
269 const
bsl::string_view& tag,
275 bsl::ostream& logStream();
290 bslma::Allocator *basicAllocator = 0);
300 template <class TYPE>
301 int encode(
bsl::streambuf *buffer, const TYPE&
object);
307 template <class TYPE>
322 template <class TYPE>
323 bsl::ostream&
encode(
bsl::ostream& stream, const TYPE&
object);
329 template <class TYPE>
384 template <
class NAME_TYPE,
class VALUE_TYPE>
385 void addAttribute(
const NAME_TYPE& name,
const VALUE_TYPE& value);
387 template<
class NAME_TYPE,
class VALUE_TYPE>
388 void addAttribute(
const NAME_TYPE& name,
389 const VALUE_TYPE& value,
392 template <
class NAME_TYPE>
393 void closeElement(
const NAME_TYPE& name);
402 template <
class NAME_TYPE>
403 void openElement(
const NAME_TYPE& name);
405 bsl::ostream& rawOutputStream();
432 static int getFormatterInitialIndentLevel(
440 static int getFormatterSpacesPerLevel(
448 static int getFormatterWrapColumn(
const EncoderOptions& encoderOptions);
464 int *formatterIndentLevel,
465 int *formatterSpacesPerLevel,
466 int *formatterWrapColumn,
495 struct CanBeListOrRepetition { };
496 struct CanBeRepetitionOnly { };
503 template <
class TYPE>
504 int executeImp(
const TYPE&
object,
509 template <
class TYPE>
510 int executeImp(
const TYPE&
object,
515 template <
class TYPE>
516 int executeImp(
const TYPE&
object,
521 template <
class TYPE,
class ANY_CATEGORY>
522 int executeImp(
const TYPE&
object,
532 template <
class TYPE>
535 template <
class TYPE>
536 int executeArrayRepetitionImp(
const TYPE&
object,
553 template <
class TYPE,
class INFO_TYPE>
554 int operator()(
const TYPE&
object,
const INFO_TYPE& info);
556 template <
class TYPE>
557 int execute(
const TYPE&
object,
578 template <
class TYPE>
579 int executeImp(
const TYPE&
object,
583 template <
class TYPE>
584 int executeImp(
const TYPE&
object,
588 template <
class TYPE>
589 int executeImp(
const TYPE&
object,
593 template <
class TYPE,
class ANY_CATEGORY>
594 int executeImp(
const TYPE&
object,
int formattingMode, ANY_CATEGORY);
609 template <
class TYPE,
class INFO_TYPE>
610 int operator()(
const TYPE&
object,
const INFO_TYPE& info);
612 template <
class TYPE>
613 int execute(
const TYPE&
object,
int formattingMode);
639 bool d_hasSubElements;
653 template <
class TYPE>
654 int addAttributeImp(
const TYPE&
object,
658 template <
class TYPE>
659 int addAttributeImp(
const TYPE&
object,
663 template <
class TYPE,
class ANY_CATEGORY>
664 int addAttributeImp(
const TYPE&
object,
671 template <
class TYPE>
672 int addAttribute(
const TYPE&
object,
693 template <
class TYPE,
class INFO_TYPE>
694 int operator()(
const TYPE&
object,
const INFO_TYPE& info);
699 const bool& hasSubElements()
const;
743 template <
class TYPE,
class INFO_TYPE>
744 int operator()(
const TYPE&
object,
const INFO_TYPE& info);
769 template <
class TYPE>
773 return d_instance_p->
execute(
object, *d_tag_p, d_formattingMode);
795 template <
class TYPE>
803 template <
class TYPE,
class ANY_CATEGORY>
831 template <
class TYPE>
839 template <
class TYPE,
class ANY_CATEGORY>
843 return d_instance_p->
executeImp(
object, d_formattingMode, category);
865 template <
class TYPE>
869 return d_instance_p->
addAttribute(
object, *d_name_p, d_formattingMode);
891 template <
class TYPE>
899 template <
class TYPE,
class ANY_CATEGORY>
924, d_sb(
bslma::Default::allocator(basicAllocator))
931void Encoder::MemOutStream::reset()
938const char *Encoder::MemOutStream::data()
const
944int Encoder::MemOutStream::length()
const
946 return (
int)d_sb.length();
968 return d_errorStream;
974 return d_warningStream;
994bsl::ostream& Encoder::logStream()
996 if (0 == d_logStream) {
997 d_logStream =
new(d_logArea.
buffer()) MemOutStream(d_allocator);
1002template <
class TYPE>
1006 int indentLevel = 0;
1007 int spacesPerLevel = 0;
1015 &formatterEncoderOptions,
1019 formatterEncoderOptions,
1024 const int rc =
encode(formatter,
object);
1031template <
class TYPE>
1035 return encode(stream.rdbuf(),
object);
1038template <
class TYPE>
1042 int indentLevel = 0;
1043 int spacesPerLevel = 0;
1051 &formatterEncoderOptions,
1055 formatterEncoderOptions,
1060 encode(formatter,
object);
1067template <
class TYPE>
1071 if (d_logStream != 0) {
1072 d_logStream->reset();
1081 const char *tag = d_options->
tag().
empty()
1097 "http://www.w3.org/2001/XMLSchema-instance");
1109 "http://www.w3.org/2001/XMLSchema-instance");
1126 switch (d_severity) {
1130 if (d_warningStream) {
1135 if (d_errorStream) {
1148template <
class NAME_TYPE,
class VALUE_TYPE>
1151 const VALUE_TYPE& value)
1158template <
class NAME_TYPE,
class VALUE_TYPE>
1161 const VALUE_TYPE& value,
1164 d_formatter->
addAttribute(name, value, formattingMode);
1167template <
class NAME_TYPE>
1187 return d_encoder->logError(text, tag, formattingMode, index);
1190template <
class NAME_TYPE>
1213 return d_formatter->
status();
1221template <
class TYPE>
1237template <
class TYPE>
1245 enum { k_SUCCESS = 0 };
1259 return d_context_p->
status();
1271template <
class TYPE>
1288template <
class TYPE,
class ANY_CATEGORY>
1294 enum { k_FAILURE = -1 };
1304 if (0 != encodeValue.
execute(
object, formattingMode)) {
1305 d_context_p->
logError(
"Unable to encode value", tag, formattingMode);
1313 int ret = d_context_p->
status();
1316 d_context_p->
logError(
"Formatter was invalidated for",
1324template <
class TYPE>
1336 int ret = d_context_p->
status();
1341 "Error while encoding list for",
1349template <
class TYPE>
1355 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1361 for (
int i = 0; i < size; ++i) {
1365 "Error while encoding array element",
1380: d_context_p(context)
1386template <
class TYPE,
class INFO_TYPE>
1392 return execute(
object, name, info.formattingMode());
1395template <
class TYPE>
1403 return executeImp(
object, tag, formattingMode, TypeCategory());
1411template <
class TYPE>
1418 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1420#if defined(BSLS_ASSERT_SAFE_IS_ACTIVE)
1425 (void) formattingMode;
1454template <
class TYPE>
1460 enum { k_FAILURE = -1 };
1462#if defined(BSLS_ASSERT_SAFE_IS_ACTIVE)
1471 d_context_p->
logError(
"Undefined selection is not allowed ",
1482template <
class TYPE>
1494template <
class TYPE,
class ANY_CATEGORY>
1505 return d_context_p->
status();
1511: d_context_p(context)
1517template <
class TYPE,
class INFO_TYPE>
1523 return executeImp(
object, info.formattingMode(), TypeCategory());
1526template <
class TYPE>
1532 return executeImp(
object, formattingMode, TypeCategory());
1540template <
class TYPE>
1548 enum { k_SUCCESS = 0 };
1563template <
class TYPE>
1581template <
class TYPE,
class ANY_CATEGORY>
1589 d_context_p->
addAttribute(name,
object, formattingMode);
1591 int ret = d_context_p->
status();
1594 d_context_p->
logError(
"Failed to encode attribute",
1602template <
class TYPE>
1617: d_context_p(context)
1618, d_hasSubElements(false)
1629 d_simpleContentId.reset();
1633template <
class TYPE,
class INFO_TYPE>
1635 const INFO_TYPE& info)
1637 enum { k_SUCCESS = 0 };
1639 int formattingMode = info.formattingMode();
1640 bool isSimpleContent = formattingMode
1644 if (isSimpleContent) {
1651 else if (isAttribute) {
1659 d_hasSubElements =
true;
1669 return d_hasSubElements;
1676 return d_simpleContentId;
1685Encoder_SequenceSecondPass::Encoder_SequenceSecondPass(
1687: d_encodeObjectFunctor(context)
1692template <
class TYPE,
class INFO_TYPE>
1694 const INFO_TYPE& info)
1696 enum { k_SUCCESS = 0 };
1698 int formattingMode = info.formattingMode();
1704 return d_encodeObjectFunctor(
object, info);
#define BSLMF_NESTED_TRAIT_DECLARATION(t_TYPE, t_TRAIT)
Definition bslmf_nestedtraitdeclaration.h:231
Definition balxml_encoderoptions.h:88
bool outputXSIAlias() const
Return the value of the "OutputXSIAlias" attribute of this object.
Definition balxml_encoderoptions.h:1022
const bsl::string & schemaLocation() const
Definition balxml_encoderoptions.h:950
EncodingStyle::Value encodingStyle() const
Return the value of the "EncodingStyle" attribute of this object.
Definition balxml_encoderoptions.h:1004
bool outputXMLHeader() const
Return the value of the "OutputXMLHeader" attribute of this object.
Definition balxml_encoderoptions.h:1016
const bsl::string & tag() const
Definition balxml_encoderoptions.h:956
static const int DEFAULT_INITIALIZER_FORMATTING_MODE
Definition balxml_encoderoptions.h:196
const bsl::string & objectNamespace() const
Definition balxml_encoderoptions.h:944
int formattingMode() const
Return the value of the "FormattingMode" attribute of this object.
Definition balxml_encoderoptions.h:962
Definition balxml_encoder.h:369
void openElement(const NAME_TYPE &name)
Definition balxml_encoder.h:1192
Encoder_Context(Formatter *formatter, Encoder *encoder)
void addAttribute(const NAME_TYPE &name, const VALUE_TYPE &value)
Definition balxml_encoder.h:1150
const EncoderOptions & encoderOptions() const
Definition balxml_encoder.h:1205
int status() const
Definition balxml_encoder.h:1211
void closeElement(const NAME_TYPE &name)
Definition balxml_encoder.h:1169
void invalidate()
Definition balxml_encoder.h:1175
ErrorInfo::Severity logError(const char *text, const bsl::string_view &tag, int formattingMode, int index=-1)
Definition balxml_encoder.h:1181
bsl::ostream & rawOutputStream()
Definition balxml_encoder.h:1198
Definition balxml_encoder.h:492
int operator()(const TYPE &object, const INFO_TYPE &info)
Definition balxml_encoder.h:1388
int executeImp(const bsl::vector< char > &object, const bsl::string_view &tag, int formattingMode, bdlat_TypeCategory::Array)
int executeArrayRepetitionImp(const TYPE &object, const bsl::string_view &tag, int formattingMode)
Definition balxml_encoder.h:1350
int executeArrayListImp(const TYPE &object, const bsl::string_view &tag)
Definition balxml_encoder.h:1325
int executeImp(const TYPE &object, const bsl::string_view &tag, int formattingMode, bdlat_TypeCategory::Array)
Definition balxml_encoder.h:1223
int execute(const TYPE &object, const bsl::string_view &tag, int formattingMode)
Definition balxml_encoder.h:1397
Definition balxml_encoder.h:571
int execute(const TYPE &object, int formattingMode)
Definition balxml_encoder.h:1528
int executeImp(const TYPE &object, int formattingMode, bdlat_TypeCategory::Sequence)
Definition balxml_encoder.h:1413
int operator()(const TYPE &object, const INFO_TYPE &info)
Definition balxml_encoder.h:1519
Definition balxml_encoder.h:635
const bdlb::NullableValue< int > & simpleContentId() const
Definition balxml_encoder.h:1674
int operator()(const TYPE &object, const INFO_TYPE &info)
Called back when an element is visited.
Definition balxml_encoder.h:1634
int addAttribute(const TYPE &object, const bsl::string_view &name, int formattingMode)
Definition balxml_encoder.h:1604
const bool & hasSubElements() const
Return true if a sub-element is found, and false otherwise.
Definition balxml_encoder.h:1667
int addAttributeImp(const TYPE &object, const bsl::string_view &name, int formattingMode, bdlat_TypeCategory::NullableValue)
Definition balxml_encoder.h:1542
Definition balxml_encoder.h:719
int operator()(const TYPE &object, const INFO_TYPE &info)
Called back when an element is visited.
Definition balxml_encoder.h:1693
Definition balxml_encoder.h:200
bslstl::StringRef loggedMessages() const
Definition balxml_encoder.h:984
bsl::ostream * warningStream() const
Return pointer to the warning stream.
Definition balxml_encoder.h:972
bsl::ostream * errorStream() const
Return pointer to the error stream.
Definition balxml_encoder.h:966
friend class Encoder_Context
Definition balxml_encoder.h:203
bool isCompact() const
Definition balxml_encoder.h:954
ErrorInfo::Severity errorSeverity() const
Definition balxml_encoder.h:978
const EncoderOptions * options() const
Return the encoder options.
Definition balxml_encoder.h:960
int encode(bsl::streambuf *buffer, const TYPE &object)
Definition balxml_encoder.h:1004
int encodeToStream(bsl::ostream &stream, const TYPE &object)
Definition balxml_encoder.h:1033
Definition balxml_errorinfo.h:353
Severity
Definition balxml_errorinfo.h:358
@ e_WARNING
Definition balxml_errorinfo.h:372
@ e_NO_ERROR
Definition balxml_errorinfo.h:371
Definition bdlb_nullablevalue.h:257
bool isNull() const BSLS_KEYWORD_NOEXCEPT
Return true if this object is null, and false otherwise.
Definition bdlb_nullablevalue.h:1779
TYPE & value()
Definition bdlb_nullablevalue.h:1742
TYPE & makeValue(BSLS_COMPILERFEATURES_FORWARD_REF(BDE_OTHER_TYPE) value)
Definition bdlb_nullablevalue.h:1717
Definition bdlsb_memoutstreambuf.h:212
Definition bslstl_stringview.h:441
const CHAR_TYPE * c_str() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_string.h:6705
bool empty() const BSLS_KEYWORD_NOEXCEPT
Return true if this string has length 0, and false otherwise.
Definition bslstl_string.h:6631
Definition bslstl_vector.h:1025
Definition bslma_allocator.h:457
Definition bslstl_stringref.h:372
static int accessByCategory(const TYPE &object, ACCESSOR &accessor)
Definition bdlat_typecategory.h:1444
static const char * xsdName(const TYPE &object, int format)
Definition bdlat_typename.h:1039
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_OVERRIDE
Definition bsls_keyword.h:653
Definition balxml_base64parser.h:150
bsl::size_t size(const TYPE &array)
Return the number of elements in the specified array.
int accessElement(const TYPE &array, ACCESSOR &accessor, int index)
int accessSelection(const TYPE &object, ACCESSOR &accessor)
@ k_UNDEFINED_SELECTION_ID
Definition bdlat_choicefunctions.h:511
int selectionId(const TYPE &object)
bool isNull(const TYPE &object)
int accessValue(const TYPE &object, ACCESSOR &accessor)
int accessAttribute(const TYPE &object, ACCESSOR &accessor, const char *attributeName, int attributeNameLength)
int accessAttributes(const TYPE &object, ACCESSOR &accessor)
Definition bdlb_printmethods.h:283
Definition balxml_encoderoptions.h:68
Definition bdlt_iso8601util.h:691
Definition bslstl_algorithm.h:82
StringRefImp< char > StringRef
Definition bslstl_stringref.h:699
Component-private struct. Do not use.
Definition balxml_encoder.h:782
int operator()(const TYPE &object, ANY_CATEGORY category)
Definition balxml_encoder.h:805
int operator()(const TYPE &, bslmf::Nil)
Definition balxml_encoder.h:797
int d_formattingMode
Definition balxml_encoder.h:787
Encoder_EncodeObject * d_instance_p
Definition balxml_encoder.h:785
const bsl::string_view * d_tag_p
Definition balxml_encoder.h:786
Component-private struct. Do not use.
Definition balxml_encoder.h:756
int d_formattingMode
Definition balxml_encoder.h:761
int operator()(const TYPE &object)
Definition balxml_encoder.h:771
Encoder_EncodeObject * d_instance_p
Definition balxml_encoder.h:759
const bsl::string_view * d_tag_p
Definition balxml_encoder.h:760
Component-private struct. Do not use.
Definition balxml_encoder.h:819
int operator()(const TYPE &object, ANY_CATEGORY category)
Definition balxml_encoder.h:841
int operator()(const TYPE &, bslmf::Nil)
Definition balxml_encoder.h:833
int d_formattingMode
Definition balxml_encoder.h:823
Encoder_EncodeValue * d_instance_p
Definition balxml_encoder.h:822
Definition balxml_encoder.h:422
static void getFormatterOptions(int *formatterIndentLevel, int *formatterSpacesPerLevel, int *formatterWrapColumn, EncoderOptions *formatterOptions, const EncoderOptions &encoderOptions)
Component-private struct. Do not use.
Definition balxml_encoder.h:878
const bsl::string_view * d_name_p
Definition balxml_encoder.h:882
int d_formattingMode
Definition balxml_encoder.h:883
int operator()(const TYPE &object, ANY_CATEGORY category)
Definition balxml_encoder.h:901
int operator()(const TYPE &, bslmf::Nil)
Definition balxml_encoder.h:893
Encoder_SequenceFirstPass * d_instance_p
Definition balxml_encoder.h:881
Component-private struct. Do not use.
Definition balxml_encoder.h:852
int operator()(const TYPE &object)
Definition balxml_encoder.h:867
int d_formattingMode
Definition balxml_encoder.h:857
const bsl::string_view * d_name_p
Definition balxml_encoder.h:856
Encoder_SequenceFirstPass * d_instance_p
Definition balxml_encoder.h:855
@ COMPACT
Definition balxml_encodingstyle.h:75
static bsl::ostream & print(bsl::ostream &stream, const TYPE &object, int formattingMode, const EncoderOptions *encoderOptions=0)
Definition balxml_typesprintutil.h:1161
static bsl::ostream & printList(bsl::ostream &stream, const TYPE &object, const EncoderOptions *encoderOptions=0)
Definition balxml_typesprintutil.h:1253
Definition bdlat_typecategory.h:1035
Definition bdlat_typecategory.h:1036
Definition bdlat_typecategory.h:1034
Definition bdlat_typecategory.h:1039
Definition bdlat_typecategory.h:1040
This struct is empty and represents a nil type.
Definition bslmf_nil.h:131
char * buffer()
Definition bsls_objectbuffer.h:344