8#ifndef INCLUDED_BALXML_ENCODER
9#define INCLUDED_BALXML_ENCODER
158#include <balscm_version.h>
188#include <bsl_ostream.h>
189#include <bsl_string.h>
190#include <bsl_vector.h>
195class Encoder_Context;
216 class MemOutStream :
public bsl::ostream
221 MemOutStream(
const MemOutStream&);
222 MemOutStream& operator=(
const MemOutStream&);
248 const
char *data() const;
258 bslma::Allocator *d_allocator;
261 bsls::ObjectBuffer<MemOutStream> d_logArea;
265 MemOutStream *d_logStream;
269 bsl::ostream *d_errorStream;
270 bsl::ostream *d_warningStream;
273 ErrorInfo::Severity logError(const
char *text,
274 const
bsl::string_view& tag,
280 bsl::ostream& logStream();
295 bslma::Allocator *basicAllocator = 0);
306 template <class TYPE>
307 int encode(
bsl::streambuf *buffer, const TYPE&
object);
314 template <class TYPE>
330 template <class TYPE>
331 bsl::ostream&
encode(
bsl::ostream& stream, const TYPE&
object);
338 template <class TYPE>
349 template <class TYPE>
350 int encodeAny(
bsl::streambuf *buffer, const TYPE&
object);
361 template <class TYPE>
364 const
bdlar::AnyConstRef&
object);
375 template <class TYPE>
378 const
bdlar::AnyConstRef&
object);
388 template <class TYPE>
445 template <
class NAME_TYPE,
class VALUE_TYPE>
446 void addAttribute(
const NAME_TYPE& name,
const VALUE_TYPE& value);
448 template<
class NAME_TYPE,
class VALUE_TYPE>
449 void addAttribute(
const NAME_TYPE& name,
450 const VALUE_TYPE& value,
453 template <
class NAME_TYPE>
454 void closeElement(
const NAME_TYPE& name);
463 template <
class NAME_TYPE>
464 void openElement(
const NAME_TYPE& name);
466 bsl::ostream& rawOutputStream();
495 static int getFormatterInitialIndentLevel(
503 static int getFormatterSpacesPerLevel(
511 static int getFormatterWrapColumn(
const EncoderOptions& encoderOptions);
528 int *formatterIndentLevel,
529 int *formatterSpacesPerLevel,
530 int *formatterWrapColumn,
559 struct CanBeListOrRepetition { };
560 struct CanBeRepetitionOnly { };
567 template <
class TYPE>
568 int executeImp(
const TYPE&
object,
574 template <
class TYPE>
575 int executeImp(
const TYPE&
object,
581 template <
class TYPE>
582 int executeImp(
const TYPE&
object,
588 template <
class TYPE,
class ANY_CATEGORY>
589 int executeImp(
const TYPE&
object,
601 template <
class TYPE>
604 template <
class TYPE>
605 int executeArrayRepetitionImp(
const TYPE&
object,
622 template <
class TYPE,
class INFO_TYPE>
623 int operator()(
const TYPE&
object,
const INFO_TYPE& info);
625 template <
class TYPE>
626 int execute(
const TYPE&
object,
648 template <
class TYPE>
649 int executeImp(
const TYPE&
object,
653 template <
class TYPE>
654 int executeImp(
const TYPE&
object,
658 template <
class TYPE>
659 int executeImp(
const TYPE&
object,
663 template <
class TYPE,
class ANY_CATEGORY>
664 int executeImp(
const TYPE&
object,
int formattingMode, ANY_CATEGORY);
679 template <
class TYPE,
class INFO_TYPE>
680 int operator()(
const TYPE&
object,
const INFO_TYPE& info);
682 template <
class TYPE>
683 int execute(
const TYPE&
object,
int formattingMode);
710 bool d_hasSubElements;
725 template <
class TYPE>
726 int addAttributeImp(
const TYPE&
object,
730 template <
class TYPE>
731 int addAttributeImp(
const TYPE&
object,
735 template <
class TYPE,
class ANY_CATEGORY>
736 int addAttributeImp(
const TYPE&
object,
743 template <
class TYPE>
744 int addAttribute(
const TYPE&
object,
765 template <
class TYPE,
class INFO_TYPE>
766 int operator()(
const TYPE&
object,
const INFO_TYPE& info);
771 const bool& hasSubElements()
const;
817 template <
class TYPE,
class INFO_TYPE>
818 int operator()(
const TYPE&
object,
const INFO_TYPE& info);
846 template <
class TYPE>
850 return d_instance_p->
execute(
object,
878 template <
class TYPE>
886 template <
class TYPE,
class ANY_CATEGORY>
917 template <
class TYPE>
925 template <
class TYPE,
class ANY_CATEGORY>
929 return d_instance_p->
executeImp(
object, d_formattingMode, category);
953 template <
class TYPE>
957 return d_instance_p->
addAttribute(
object, *d_name_p, d_formattingMode);
981 template <
class TYPE>
989 template <
class TYPE,
class ANY_CATEGORY>
1014, d_sb(
bslma::Default::allocator(basicAllocator))
1021void Encoder::MemOutStream::reset()
1028const char *Encoder::MemOutStream::data()
const
1034int Encoder::MemOutStream::length()
const
1036 return (
int)d_sb.length();
1058 return d_errorStream;
1064 return d_warningStream;
1084bsl::ostream& Encoder::logStream()
1086 if (0 == d_logStream) {
1087 d_logStream =
new(d_logArea.
buffer()) MemOutStream(d_allocator);
1089 return *d_logStream;
1092template <
class TYPE>
1096 int indentLevel = 0;
1097 int spacesPerLevel = 0;
1105 &formatterEncoderOptions,
1109 formatterEncoderOptions,
1114 const int rc =
encode(formatter,
object);
1121template <
class TYPE>
1125 return encode(stream.rdbuf(),
object);
1128template <
class TYPE>
1132 int indentLevel = 0;
1133 int spacesPerLevel = 0;
1141 &formatterEncoderOptions,
1145 formatterEncoderOptions,
1150 encode(formatter,
object);
1157template <
class TYPE>
1161 if (d_logStream != 0) {
1162 d_logStream->reset();
1171 const char *tag = d_options->
tag().
empty()
1187 "http://www.w3.org/2001/XMLSchema-instance");
1199 "http://www.w3.org/2001/XMLSchema-instance");
1216 switch (d_severity) {
1220 if (d_warningStream) {
1225 if (d_errorStream) {
1233template <
class TYPE>
1240template <
class TYPE>
1251 return encodeAny(stream.rdbuf(),
object);
1254template <
class TYPE>
1261template <
class TYPE>
1273template <
class NAME_TYPE,
class VALUE_TYPE>
1276 const VALUE_TYPE& value)
1283template <
class NAME_TYPE,
class VALUE_TYPE>
1286 const VALUE_TYPE& value,
1289 d_formatter->
addAttribute(name, value, formattingMode);
1292template <
class NAME_TYPE>
1312 return d_encoder->logError(text, tag, formattingMode, index);
1315template <
class NAME_TYPE>
1338 return d_formatter->
status();
1346template <
class TYPE>
1363template <
class TYPE>
1372 enum { k_SUCCESS = 0 };
1388 return d_context_p->
status();
1401template <
class TYPE>
1420template <
class TYPE,
class ANY_CATEGORY>
1427 enum { k_FAILURE = -1 };
1437 if (0 != encodeValue.
execute(
object, formattingMode)) {
1438 d_context_p->
logError(
"Unable to encode value", tag, formattingMode);
1446 int ret = d_context_p->
status();
1449 d_context_p->
logError(
"Formatter was invalidated for",
1457template <
class TYPE>
1469 int ret = d_context_p->
status();
1474 "Error while encoding list for",
1482template <
class TYPE>
1488 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1493 {
this, &tag, formattingMode,
true };
1495 for (
int i = 0; i < size; ++i) {
1499 "Error while encoding array element",
1514: d_context_p(context)
1520template <
class TYPE,
class INFO_TYPE>
1526 return execute(
object, name, info.formattingMode(),
false);
1529template <
class TYPE>
1538 return executeImp(
object, tag, formattingMode, isMultiple, TypeCategory());
1546template <
class TYPE>
1553 enum { k_SUCCESS = 0, k_FAILURE = -1 };
1555#if defined(BSLS_ASSERT_SAFE_IS_ACTIVE)
1560 (void) formattingMode;
1589template <
class TYPE>
1595 enum { k_FAILURE = -1 };
1597#if defined(BSLS_ASSERT_SAFE_IS_ACTIVE)
1606 d_context_p->
logError(
"Undefined selection is not allowed ",
1617template <
class TYPE>
1629template <
class TYPE,
class ANY_CATEGORY>
1640 return d_context_p->
status();
1646: d_context_p(context)
1652template <
class TYPE,
class INFO_TYPE>
1658 return executeImp(
object, info.formattingMode(), TypeCategory());
1661template <
class TYPE>
1667 return executeImp(
object, formattingMode, TypeCategory());
1675template <
class TYPE>
1683 enum { k_SUCCESS = 0 };
1698template <
class TYPE>
1716template <
class TYPE,
class ANY_CATEGORY>
1724 d_context_p->
addAttribute(name,
object, formattingMode);
1726 int ret = d_context_p->
status();
1729 d_context_p->
logError(
"Failed to encode attribute",
1737template <
class TYPE>
1752: d_context_p(context)
1753, d_hasSubElements(false)
1764 d_simpleContentId.reset();
1768template <
class TYPE,
class INFO_TYPE>
1770 const INFO_TYPE& info)
1772 enum { k_SUCCESS = 0 };
1774 int formattingMode = info.formattingMode();
1775 bool isSimpleContent = formattingMode
1779 if (isSimpleContent) {
1786 else if (isAttribute) {
1794 d_hasSubElements =
true;
1804 return d_hasSubElements;
1811 return d_simpleContentId;
1820Encoder_SequenceSecondPass::Encoder_SequenceSecondPass(
1822: d_encodeObjectFunctor(context)
1827template <
class TYPE,
class INFO_TYPE>
1829 const INFO_TYPE& info)
1831 enum { k_SUCCESS = 0 };
1833 int formattingMode = info.formattingMode();
1839 return d_encodeObjectFunctor(
object, info);
#define BSLMF_NESTED_TRAIT_DECLARATION(t_TYPE, t_TRAIT)
Definition bslmf_nestedtraitdeclaration.h:231
Definition balxml_encoderoptions.h:89
bool outputXSIAlias() const
Return the value of the "OutputXSIAlias" attribute of this object.
Definition balxml_encoderoptions.h:1024
const bsl::string & schemaLocation() const
Definition balxml_encoderoptions.h:952
EncodingStyle::Value encodingStyle() const
Return the value of the "EncodingStyle" attribute of this object.
Definition balxml_encoderoptions.h:1006
bool outputXMLHeader() const
Return the value of the "OutputXMLHeader" attribute of this object.
Definition balxml_encoderoptions.h:1018
const bsl::string & tag() const
Definition balxml_encoderoptions.h:958
static const int DEFAULT_INITIALIZER_FORMATTING_MODE
Definition balxml_encoderoptions.h:197
const bsl::string & objectNamespace() const
Definition balxml_encoderoptions.h:946
int formattingMode() const
Return the value of the "FormattingMode" attribute of this object.
Definition balxml_encoderoptions.h:964
Definition balxml_encoder.h:429
void openElement(const NAME_TYPE &name)
Definition balxml_encoder.h:1317
Encoder_Context(Formatter *formatter, Encoder *encoder)
void addAttribute(const NAME_TYPE &name, const VALUE_TYPE &value)
Definition balxml_encoder.h:1275
const EncoderOptions & encoderOptions() const
Definition balxml_encoder.h:1330
int status() const
Definition balxml_encoder.h:1336
void closeElement(const NAME_TYPE &name)
Definition balxml_encoder.h:1294
void invalidate()
Definition balxml_encoder.h:1300
ErrorInfo::Severity logError(const char *text, const bsl::string_view &tag, int formattingMode, int index=-1)
Definition balxml_encoder.h:1306
bsl::ostream & rawOutputStream()
Definition balxml_encoder.h:1323
Definition balxml_encoder.h:556
int executeImp(const bsl::vector< char > &object, const bsl::string_view &tag, int formattingMode, bool isMultiple, bdlat_TypeCategory::Array)
int operator()(const TYPE &object, const INFO_TYPE &info)
Definition balxml_encoder.h:1522
int executeArrayRepetitionImp(const TYPE &object, const bsl::string_view &tag, int formattingMode)
Definition balxml_encoder.h:1483
int executeArrayListImp(const TYPE &object, const bsl::string_view &tag)
Definition balxml_encoder.h:1458
int execute(const TYPE &object, const bsl::string_view &tag, int formattingMode, bool isMultiple)
Definition balxml_encoder.h:1531
int executeImp(const TYPE &object, const bsl::string_view &tag, int formattingMode, bool isMultiple, bdlat_TypeCategory::Array)
Definition balxml_encoder.h:1348
Definition balxml_encoder.h:641
int execute(const TYPE &object, int formattingMode)
Definition balxml_encoder.h:1663
int executeImp(const TYPE &object, int formattingMode, bdlat_TypeCategory::Sequence)
Definition balxml_encoder.h:1548
int operator()(const TYPE &object, const INFO_TYPE &info)
Definition balxml_encoder.h:1654
Definition balxml_encoder.h:706
const bdlb::NullableValue< int > & simpleContentId() const
Definition balxml_encoder.h:1809
int operator()(const TYPE &object, const INFO_TYPE &info)
Called back when an element is visited.
Definition balxml_encoder.h:1769
int addAttribute(const TYPE &object, const bsl::string_view &name, int formattingMode)
Definition balxml_encoder.h:1739
const bool & hasSubElements() const
Return true if a sub-element is found, and false otherwise.
Definition balxml_encoder.h:1802
int addAttributeImp(const TYPE &object, const bsl::string_view &name, int formattingMode, bdlat_TypeCategory::NullableValue)
Definition balxml_encoder.h:1677
Definition balxml_encoder.h:792
int operator()(const TYPE &object, const INFO_TYPE &info)
Called back when an element is visited.
Definition balxml_encoder.h:1828
Definition balxml_encoder.h:205
bslstl::StringRef loggedMessages() const
Definition balxml_encoder.h:1074
int encodeAnyToStream(bsl::ostream &stream, const TYPE &object)
Definition balxml_encoder.h:1242
bsl::ostream * warningStream() const
Return pointer to the warning stream.
Definition balxml_encoder.h:1062
bsl::ostream * errorStream() const
Return pointer to the error stream.
Definition balxml_encoder.h:1056
int encodeAny(bsl::streambuf *buffer, const TYPE &object)
Definition balxml_encoder.h:1235
friend class Encoder_Context
Definition balxml_encoder.h:208
bool isCompact() const
Definition balxml_encoder.h:1044
ErrorInfo::Severity errorSeverity() const
Definition balxml_encoder.h:1068
const EncoderOptions * options() const
Return the encoder options.
Definition balxml_encoder.h:1050
int encode(bsl::streambuf *buffer, const TYPE &object)
Definition balxml_encoder.h:1094
int encodeToStream(bsl::ostream &stream, const TYPE &object)
Definition balxml_encoder.h:1123
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 bdlar_anyref.h:247
static bsl::enable_if<!IsDynamic< t_TYPE >::value, AnyConstRef >::type makeAnyConstRef(const t_TYPE &object)
Make AnyConstRef to the specified object.
Definition bdlar_refutil.h:194
Definition bdlb_nullablevalue.h:262
bool isNull() const BSLS_KEYWORD_NOEXCEPT
Return true if this object is null, and false otherwise.
Definition bdlb_nullablevalue.h:1829
TYPE & value()
Definition bdlb_nullablevalue.h:1792
TYPE & makeValue(BSLS_COMPILERFEATURES_FORWARD_REF(BDE_OTHER_TYPE) value)
Definition bdlb_nullablevalue.h:1767
Definition bdlsb_memoutstreambuf.h:212
Definition bslstl_stringview.h:471
const CHAR_TYPE * c_str() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_string.h:7405
bool empty() const BSLS_KEYWORD_NOEXCEPT
Return true if this string has length 0, and false otherwise.
Definition bslstl_string.h:7331
Definition bslstl_vector.h:1120
Definition bslma_allocator.h:545
Definition bslstl_stringref.h:374
static int accessByCategory(const TYPE &object, ACCESSOR &accessor)
Definition bdlat_typecategory.h:1455
static const char * xsdName(const TYPE &object, int format)
Definition bdlat_typename.h:1047
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1917
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_OVERRIDE
Definition bsls_keyword.h:695
Definition balxml_base64parser.h:150
Definition bdlar_accessorref.h:59
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:515
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 bdlat_valuetypefunctions.h:939
Definition baljsn_encoder_testtypes.h:76
Definition bdlt_iso8601util.h:707
Definition bslstl_algorithm.h:84
StringRefImp< char > StringRef
Definition bslstl_stringref.h:725
Definition balxml_encoder.h:864
int operator()(const TYPE &object, ANY_CATEGORY category)
Definition balxml_encoder.h:888
int operator()(const TYPE &, bslmf::Nil)
Definition balxml_encoder.h:880
bool d_isMultiple
Definition balxml_encoder.h:870
int d_formattingMode
Definition balxml_encoder.h:869
Encoder_EncodeObject * d_instance_p
Definition balxml_encoder.h:867
const bsl::string_view * d_tag_p
Definition balxml_encoder.h:868
Definition balxml_encoder.h:832
bool d_isMultiple
Definition balxml_encoder.h:838
int d_formattingMode
Definition balxml_encoder.h:837
int operator()(const TYPE &object)
Definition balxml_encoder.h:848
Encoder_EncodeObject * d_instance_p
Definition balxml_encoder.h:835
const bsl::string_view * d_tag_p
Definition balxml_encoder.h:836
Definition balxml_encoder.h:905
int operator()(const TYPE &object, ANY_CATEGORY category)
Definition balxml_encoder.h:927
int operator()(const TYPE &, bslmf::Nil)
Definition balxml_encoder.h:919
int d_formattingMode
Definition balxml_encoder.h:909
Encoder_EncodeValue * d_instance_p
Definition balxml_encoder.h:908
Definition balxml_encoder.h:485
static void getFormatterOptions(int *formatterIndentLevel, int *formatterSpacesPerLevel, int *formatterWrapColumn, EncoderOptions *formatterOptions, const EncoderOptions &encoderOptions)
Definition balxml_encoder.h:968
const bsl::string_view * d_name_p
Definition balxml_encoder.h:972
int d_formattingMode
Definition balxml_encoder.h:973
int operator()(const TYPE &object, ANY_CATEGORY category)
Definition balxml_encoder.h:991
int operator()(const TYPE &, bslmf::Nil)
Definition balxml_encoder.h:983
Encoder_SequenceFirstPass * d_instance_p
Definition balxml_encoder.h:971
Definition balxml_encoder.h:940
int operator()(const TYPE &object)
Definition balxml_encoder.h:955
int d_formattingMode
Definition balxml_encoder.h:945
const bsl::string_view * d_name_p
Definition balxml_encoder.h:944
Encoder_SequenceFirstPass * d_instance_p
Definition balxml_encoder.h:943
@ COMPACT
Definition balxml_encodingstyle.h:77
static bsl::ostream & print(bsl::ostream &stream, const TYPE &object, int formattingMode, const EncoderOptions *encoderOptions=0)
Definition balxml_typesprintutil.h:1166
static bsl::ostream & printList(bsl::ostream &stream, const TYPE &object, const EncoderOptions *encoderOptions=0)
Definition balxml_typesprintutil.h:1258
Definition bdlat_typecategory.h:1037
Definition bdlat_typecategory.h:1038
Definition bdlat_typecategory.h:1036
Definition bdlat_typecategory.h:1041
Definition bdlat_typecategory.h:1042
Definition bslmf_nil.h:133
char * buffer()
Definition bsls_objectbuffer.h:345