diff --git a/groups/bal/balxml/balxml.xsd b/groups/bal/balxml/balxml.xsd
index b3afe95db4..21069a3fe5 100644
--- a/groups/bal/balxml/balxml.xsd
+++ b/groups/bal/balxml/balxml.xsd
@@ -275,6 +275,17 @@
+
+
+
+ Option to validate the root tag when decoding a structure.
+
+
+
diff --git a/groups/bal/balxml/balxml_decoder.h b/groups/bal/balxml/balxml_decoder.h
index e4ec73a678..c019a05d75 100644
--- a/groups/bal/balxml/balxml_decoder.h
+++ b/groups/bal/balxml/balxml_decoder.h
@@ -264,6 +264,7 @@ BSLS_IDENT("$Id: $")
#include
#include
#include
+#include
#include
#include
@@ -286,6 +287,7 @@ BSLS_IDENT("$Id: $")
#include
#include
#include
+#include // NULL
#include
#include
#include
@@ -435,6 +437,12 @@ class Decoder {
int checkForReaderErrors();
int checkForErrors(const ErrorInfo& errInfo);
+ template
+ int validateTopElement(const TYPE *object);
+ // When decoding a structure, make sure that the root tag of the XML
+ // matches the structure of the specified 'object' that we are decoding
+ // into. Return 0 if it does.
+
void setDecoderError(ErrorInfo::Severity severity, bsl::string_view msg);
int readTopElement();
@@ -1948,6 +1956,47 @@ int Decoder::warningCount() const
return d_warningCount;
}
+template
+inline
+int Decoder::validateTopElement(const TYPE *object) {
+ // If we're decoding a structure (aka 'sequence' or 'choice'), check to
+ // make sure that the root tag in the XML matches the name of the specified
+ // 'TYPE' that we are decoding into. If 'TYPE' has not implemented the
+ // bdlat introspection protocol, then the class name will be NULL, and we
+ // cannot check it against the tag name.
+
+ // has the user asked us to validate the root tag?
+ if (!d_options->validateRootTag()) {
+ return 0; // RETURN
+ }
+
+ // Are we decoding a sequence or a choice?
+ typedef typename bdlat_TypeCategory::Select::Type Category_t;
+ if (0 == bsl::is_same::value &&
+ 0 == bsl::is_same::value) {
+ return 0; // RETURN
+ }
+
+ // Do we have introspection on 'TYPE'?
+ const char *typeName = bdlat_TypeName::className(*object);
+ if (0 == typeName) { // no introspection support for 'TYPE'
+ return 0; // RETURN
+ }
+
+ // Does the class name match the root tag?
+ const char *nodeName = d_reader->nodeName(); // this is the root tag
+ if (0 == strcmp(nodeName, typeName)) {
+ return 0; // RETURN
+ }
+
+ BALXML_DECODER_LOG_ERROR(this)
+ << "The root object is of type '" << nodeName << "',"
+ << " but we're attempting to decode an object of type "
+ << "'" << typeName << "'." << BALXML_DECODER_LOG_END;
+ return -1;
+}
+
+
inline
int Decoder::open(bsl::istream& stream, const char *uri)
{
@@ -1986,7 +2035,10 @@ Decoder::decode(bsl::streambuf *buffer, TYPE *object, const char *uri)
}
- int ret = this->decode(object);
+ int ret = validateTopElement(object);
+ if (0 == ret) {
+ ret = this->decode(object);
+ }
switch(errorSeverity()) {
case ErrorInfo::e_NO_ERROR:
@@ -2018,7 +2070,11 @@ int Decoder::decode(const char *buffer,
return this->errorCount(); // RETURN
}
- int ret = this->decode(object);
+ int ret = validateTopElement(object);
+ if (0 == ret) {
+ ret = this->decode(object);
+ }
+
this->close();
return ret;
}
@@ -2031,7 +2087,11 @@ int Decoder::decode(const char *filename, TYPE *object)
return this->errorCount(); // RETURN
}
- int ret = this->decode(object);
+ int ret = validateTopElement(object);
+ if (0 == ret) {
+ ret = this->decode(object);
+ }
+
this->close();
return ret;
}
diff --git a/groups/bal/balxml/balxml_decoder.t.cpp b/groups/bal/balxml/balxml_decoder.t.cpp
index 9c3c859433..02763d1d9b 100644
--- a/groups/bal/balxml/balxml_decoder.t.cpp
+++ b/groups/bal/balxml/balxml_decoder.t.cpp
@@ -67,6 +67,8 @@
#include
#include
+#include
+
#include
#include
#include
@@ -190,7 +192,8 @@ namespace Test = s_baltst;
// [ 1] BREATHING TEST
// [16] USAGE EXAMPLES
// [22] REPRODUCE SCENARIO FROM DRQS 169438741
-// [23] DECODING CUSTOMIZED HEX AND BASE64 BINARY DATA
+// [23] REPRODUCE SCENARIO FROM DRQS 171405619
+// [24] DECODING CUSTOMIZED HEX AND BASE64 BINARY DATA
// [-1] TESTING VALID & INVALID UTF-8: e_STRING
// [-1] TESTING VALID & INVALID UTF-8: e_STREAMBUF
// [-1] TESTING VALID & INVALID UTF-8: e_ISTREAM
@@ -1366,6 +1369,10 @@ const bdlat_SelectionInfo TestChoice2::SELECTION_INFO_ARRAY[] = {
{ 2, "S2", 2, "Selection 2", 0 },
};
+const char *bdlat_TypeName_className(const TestChoice2 &) {
+ return "TestChoice2";
+ }
+
// ===============================================
// bdlat_ChoiceFunctions Overrides For TestChoice2
// ===============================================
@@ -4411,7 +4418,7 @@ int main(int argc, char *argv[])
bsls::ReviewFailureHandlerGuard reviewGuard(&bsls::Review::failByAbort);
switch (test) { case 0: // Zero is always the leading case.
- case 23: {
+ case 24: {
// --------------------------------------------------------------------
// DECODING CUSTOMIZED HEX AND BASE64 BINARY DATA
// This case tests that the decoder can decode elements that are
@@ -4570,6 +4577,89 @@ int main(int argc, char *argv[])
ASSERTV(LINE, RESULT, RESULT_DATA == data);
}
}
+ } break;
+ case 23: {
+ // --------------------------------------------------------------------
+ // REPRODUCE SCENARIO FROM DRQS 171405619
+ //
+ // Concerns:
+ //: 1 Decoding a XML input that does not match the type of the class
+ //: being decoded should cause an error.
+ //:
+ //
+ // Plan:
+ //: 1 Attempt to decode some XML that contains a structure named
+ //: 'ErrorEmployee1' into a 'Employee'. Verify that an error is
+ //: reported. (C-1)
+ //
+ // Testing:
+ // DRQS 171405619
+ // --------------------------------------------------------------------
+
+ if (verbose) cout << "\nREPRODUCE SCENARIO FROM DRQS 171405619"
+ << "\n======================================"
+ << endl;
+
+
+ balxml::MiniReader reader;
+ balxml::ErrorInfo errInfo;
+ balxml::DecoderOptions options;
+
+ options.setSkipUnknownElements(false);
+ options.setValidateRootTag(true);
+
+ balxml::Decoder decoder(&options,
+ &reader,
+ &errInfo,
+ &bsl::cerr,
+ &bsl::cerr);
+
+ // Structure - Tag matches
+ {
+ bsl::string_view INPUT = "";
+ bdlsb::FixedMemInStreamBuf isb(INPUT.data(), INPUT.size());
+ Test::Employee bob;
+ int rc = decoder.decode(&isb, &bob);
+ ASSERTV(errInfo.message(), rc, 0 == rc);
+ }
+
+ // Structure - Tag does not match
+ {
+ bsl::string_view INPUT
+ = "";
+ bdlsb::FixedMemInStreamBuf isb(INPUT.data(), INPUT.size());
+ Test::Employee bob;
+ int rc = decoder.decode(&isb, &bob);
+ ASSERTV(errInfo.message(), rc, 0 != rc);
+ }
+
+ // Choice - Tag matches
+ {
+ bsl::string_view INPUT =
+ "\n"
+ "\n"
+ " 123\n"
+ "\n";
+
+ bdlsb::FixedMemInStreamBuf isb(INPUT.data(), INPUT.size());
+ TestChoice2 tc;
+ int rc = decoder.decode(&isb, &tc);
+ ASSERTV(errInfo.message(), rc, 0 == rc);
+ }
+
+ // Choice - Tag does not match
+ {
+ bsl::string_view INPUT =
+ "\n"
+ "\n"
+ " 123\n"
+ "\n";
+
+ bdlsb::FixedMemInStreamBuf isb(INPUT.data(), INPUT.size());
+ TestChoice2 tc;
+ int rc = decoder.decode(&isb, &tc);
+ ASSERTV(errInfo.message(), rc, 0 != rc);
+ }
} break;
case 22: {
diff --git a/groups/bal/balxml/balxml_decoderoptions.cpp b/groups/bal/balxml/balxml_decoderoptions.cpp
index acffa239d8..ea975b97ec 100644
--- a/groups/bal/balxml/balxml_decoderoptions.cpp
+++ b/groups/bal/balxml/balxml_decoderoptions.cpp
@@ -1,7 +1,7 @@
// balxml_decoderoptions.cpp *DO NOT EDIT* @generated -*-C++-*-
#include
-BSLS_IDENT_RCSID(balxml_decoderoptions_cpp,"$Id$ $CSID$")
+BSLS_IDENT_RCSID(balxml_decoderoptions_cpp, "$Id$ $CSID$")
#include
@@ -14,9 +14,11 @@ BSLS_IDENT_RCSID(balxml_decoderoptions_cpp,"$Id$ $CSID$")
#include
#include
+#include
#include
#include
#include
+#include
namespace BloombergLP {
namespace balxml {
@@ -37,6 +39,8 @@ const bool DecoderOptions::DEFAULT_INITIALIZER_SKIP_UNKNOWN_ELEMENTS = true;
const bool DecoderOptions::DEFAULT_INITIALIZER_VALIDATE_INPUT_IS_UTF8 = false;
+const bool DecoderOptions::DEFAULT_INITIALIZER_VALIDATE_ROOT_TAG = false;
+
const bdlat_AttributeInfo DecoderOptions::ATTRIBUTE_INFO_ARRAY[] = {
{
ATTRIBUTE_ID_MAX_DEPTH,
@@ -65,6 +69,13 @@ const bdlat_AttributeInfo DecoderOptions::ATTRIBUTE_INFO_ARRAY[] = {
sizeof("ValidateInputIsUtf8") - 1,
"",
bdlat_FormattingMode::e_TEXT
+ },
+ {
+ ATTRIBUTE_ID_VALIDATE_ROOT_TAG,
+ "ValidateRootTag",
+ sizeof("ValidateRootTag") - 1,
+ "",
+ bdlat_FormattingMode::e_TEXT
}
};
@@ -74,7 +85,7 @@ const bdlat_AttributeInfo *DecoderOptions::lookupAttributeInfo(
const char *name,
int nameLength)
{
- for (int i = 0; i < 4; ++i) {
+ for (int i = 0; i < 5; ++i) {
const bdlat_AttributeInfo& attributeInfo =
DecoderOptions::ATTRIBUTE_INFO_ARRAY[i];
@@ -99,6 +110,8 @@ const bdlat_AttributeInfo *DecoderOptions::lookupAttributeInfo(int id)
return &ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_SKIP_UNKNOWN_ELEMENTS];
case ATTRIBUTE_ID_VALIDATE_INPUT_IS_UTF8:
return &ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_VALIDATE_INPUT_IS_UTF8];
+ case ATTRIBUTE_ID_VALIDATE_ROOT_TAG:
+ return &ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_VALIDATE_ROOT_TAG];
default:
return 0;
}
@@ -111,6 +124,7 @@ DecoderOptions::DecoderOptions()
, d_formattingMode(DEFAULT_INITIALIZER_FORMATTING_MODE)
, d_skipUnknownElements(DEFAULT_INITIALIZER_SKIP_UNKNOWN_ELEMENTS)
, d_validateInputIsUtf8(DEFAULT_INITIALIZER_VALIDATE_INPUT_IS_UTF8)
+, d_validateRootTag(DEFAULT_INITIALIZER_VALIDATE_ROOT_TAG)
{
}
@@ -119,6 +133,7 @@ DecoderOptions::DecoderOptions(const DecoderOptions& original)
, d_formattingMode(original.d_formattingMode)
, d_skipUnknownElements(original.d_skipUnknownElements)
, d_validateInputIsUtf8(original.d_validateInputIsUtf8)
+, d_validateRootTag(original.d_validateRootTag)
{
}
@@ -136,6 +151,7 @@ DecoderOptions::operator=(const DecoderOptions& rhs)
d_formattingMode = rhs.d_formattingMode;
d_skipUnknownElements = rhs.d_skipUnknownElements;
d_validateInputIsUtf8 = rhs.d_validateInputIsUtf8;
+ d_validateRootTag = rhs.d_validateRootTag;
}
return *this;
@@ -151,6 +167,7 @@ DecoderOptions::operator=(DecoderOptions&& rhs)
d_formattingMode = bsl::move(rhs.d_formattingMode);
d_skipUnknownElements = bsl::move(rhs.d_skipUnknownElements);
d_validateInputIsUtf8 = bsl::move(rhs.d_validateInputIsUtf8);
+ d_validateRootTag = bsl::move(rhs.d_validateRootTag);
}
return *this;
@@ -163,14 +180,14 @@ void DecoderOptions::reset()
d_formattingMode = DEFAULT_INITIALIZER_FORMATTING_MODE;
d_skipUnknownElements = DEFAULT_INITIALIZER_SKIP_UNKNOWN_ELEMENTS;
d_validateInputIsUtf8 = DEFAULT_INITIALIZER_VALIDATE_INPUT_IS_UTF8;
+ d_validateRootTag = DEFAULT_INITIALIZER_VALIDATE_ROOT_TAG;
}
// ACCESSORS
-bsl::ostream& DecoderOptions::print(
- bsl::ostream& stream,
- int level,
- int spacesPerLevel) const
+bsl::ostream& DecoderOptions::print(bsl::ostream& stream,
+ int level,
+ int spacesPerLevel) const
{
bslim::Printer printer(&stream, level, spacesPerLevel);
printer.start();
@@ -178,6 +195,7 @@ bsl::ostream& DecoderOptions::print(
printer.printAttribute("formattingMode", this->formattingMode());
printer.printAttribute("skipUnknownElements", this->skipUnknownElements());
printer.printAttribute("validateInputIsUtf8", this->validateInputIsUtf8());
+ printer.printAttribute("validateRootTag", this->validateRootTag());
printer.end();
return stream;
}
@@ -186,22 +204,12 @@ bsl::ostream& DecoderOptions::print(
} // close package namespace
} // close enterprise namespace
-// BAS_CODEGEN RUN BY code_from_xsd.pl RUN ON Thu Sep 24 20:40:02 EDT 2020
-// GENERATED BY BLP_BAS_CODEGEN_2020.09.14
+// GENERATED BY @BLP_BAS_CODEGEN_VERSION@
// USING bas_codegen.pl -m msg -p balxml -E --noExternalization --noAggregateConversion --noHashSupport balxml.xsd
-
// ----------------------------------------------------------------------------
-// Copyright 2020 Bloomberg Finance L.P.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-// ----------------------------- END-OF-FILE ----------------------------------
+// NOTICE:
+// Copyright 2023 Bloomberg Finance L.P. All rights reserved.
+// Property of Bloomberg Finance L.P. (BFLP)
+// This software is made available solely pursuant to the
+// terms of a BFLP license agreement which governs its use.
+// ------------------------------- END-OF-FILE --------------------------------
diff --git a/groups/bal/balxml/balxml_decoderoptions.h b/groups/bal/balxml/balxml_decoderoptions.h
index 8d570c3e0a..cdf8b6ec17 100644
--- a/groups/bal/balxml/balxml_decoderoptions.h
+++ b/groups/bal/balxml/balxml_decoderoptions.h
@@ -3,7 +3,7 @@
#define INCLUDED_BALXML_DECODEROPTIONS
#include
-BSLS_IDENT_RCSID(balxml_decoderoptions_h,"$Id$ $CSID$")
+BSLS_IDENT_RCSID(balxml_decoderoptions_h, "$Id$ $CSID$")
BSLS_IDENT_PRAGMA_ONCE
//@PURPOSE: Provide value-semantic attribute classes
@@ -34,8 +34,8 @@ namespace balxml {
class DecoderOptions {
// Options for controlling the XML decoding process.
- // This struct is generated using bas_codegen.pl called by
- // balxml/code_from_xsd.pl
+ // The generated C++ code for this schema element is created by using
+ // bas_codegen.pl, run by balxml/code_from_xsd.pl with no hand-editing.
// INSTANCE DATA
int d_maxDepth;
@@ -46,6 +46,8 @@ class DecoderOptions {
// Option to skip unknown elements
bool d_validateInputIsUtf8;
// option to check that input is valid UTF-8
+ bool d_validateRootTag;
+ // Option to validate the root tag when decoding a structure.
public:
// TYPES
@@ -54,10 +56,11 @@ class DecoderOptions {
, ATTRIBUTE_ID_FORMATTING_MODE = 1
, ATTRIBUTE_ID_SKIP_UNKNOWN_ELEMENTS = 2
, ATTRIBUTE_ID_VALIDATE_INPUT_IS_UTF8 = 3
+ , ATTRIBUTE_ID_VALIDATE_ROOT_TAG = 4
};
enum {
- NUM_ATTRIBUTES = 4
+ NUM_ATTRIBUTES = 5
};
enum {
@@ -65,6 +68,7 @@ class DecoderOptions {
, ATTRIBUTE_INDEX_FORMATTING_MODE = 1
, ATTRIBUTE_INDEX_SKIP_UNKNOWN_ELEMENTS = 2
, ATTRIBUTE_INDEX_VALIDATE_INPUT_IS_UTF8 = 3
+ , ATTRIBUTE_INDEX_VALIDATE_ROOT_TAG = 4
};
// CONSTANTS
@@ -78,6 +82,8 @@ class DecoderOptions {
static const bool DEFAULT_INITIALIZER_VALIDATE_INPUT_IS_UTF8;
+ static const bool DEFAULT_INITIALIZER_VALIDATE_ROOT_TAG;
+
static const bdlat_AttributeInfo ATTRIBUTE_INFO_ARRAY[];
public:
@@ -128,8 +134,8 @@ class DecoderOptions {
// Reset this object to the default value (i.e., its value upon
// default construction).
- template
- int manipulateAttributes(MANIPULATOR& manipulator);
+ template
+ int manipulateAttributes(t_MANIPULATOR& manipulator);
// Invoke the specified 'manipulator' sequentially on the address of
// each (modifiable) attribute of this object, supplying 'manipulator'
// with the corresponding attribute information structure until such
@@ -137,8 +143,8 @@ class DecoderOptions {
// last invocation of 'manipulator' (i.e., the invocation that
// terminated the sequence).
- template
- int manipulateAttribute(MANIPULATOR& manipulator, int id);
+ template
+ int manipulateAttribute(t_MANIPULATOR& manipulator, int id);
// Invoke the specified 'manipulator' on the address of
// the (modifiable) attribute indicated by the specified 'id',
// supplying 'manipulator' with the corresponding attribute
@@ -146,8 +152,8 @@ class DecoderOptions {
// invocation of 'manipulator' if 'id' identifies an attribute of this
// class, and -1 otherwise.
- template
- int manipulateAttribute(MANIPULATOR& manipulator,
+ template
+ int manipulateAttribute(t_MANIPULATOR& manipulator,
const char *name,
int nameLength);
// Invoke the specified 'manipulator' on the address of
@@ -173,9 +179,13 @@ class DecoderOptions {
// Set the "ValidateInputIsUtf8" attribute of this object to the
// specified 'value'.
+ void setValidateRootTag(bool value);
+ // Set the "ValidateRootTag" attribute of this object to the specified
+ // 'value'.
+
// ACCESSORS
bsl::ostream& print(bsl::ostream& stream,
- int level = 0,
+ int level = 0,
int spacesPerLevel = 4) const;
// Format this object to the specified output 'stream' at the
// optionally specified indentation 'level' and return a reference to
@@ -189,8 +199,8 @@ class DecoderOptions {
// operation has no effect. Note that a trailing newline is provided
// in multiline mode only.
- template
- int accessAttributes(ACCESSOR& accessor) const;
+ template
+ int accessAttributes(t_ACCESSOR& accessor) const;
// Invoke the specified 'accessor' sequentially on each
// (non-modifiable) attribute of this object, supplying 'accessor'
// with the corresponding attribute information structure until such
@@ -198,16 +208,16 @@ class DecoderOptions {
// last invocation of 'accessor' (i.e., the invocation that terminated
// the sequence).
- template
- int accessAttribute(ACCESSOR& accessor, int id) const;
+ template
+ int accessAttribute(t_ACCESSOR& accessor, int id) const;
// Invoke the specified 'accessor' on the (non-modifiable) attribute
// of this object indicated by the specified 'id', supplying 'accessor'
// with the corresponding attribute information structure. Return the
// value returned from the invocation of 'accessor' if 'id' identifies
// an attribute of this class, and -1 otherwise.
- template
- int accessAttribute(ACCESSOR& accessor,
+ template
+ int accessAttribute(t_ACCESSOR& accessor,
const char *name,
int nameLength) const;
// Invoke the specified 'accessor' on the (non-modifiable) attribute
@@ -218,20 +228,21 @@ class DecoderOptions {
// class, and -1 otherwise.
int maxDepth() const;
- // Return a reference to the non-modifiable "MaxDepth" attribute of
- // this object.
+ // Return the value of the "MaxDepth" attribute of this object.
int formattingMode() const;
- // Return a reference to the non-modifiable "FormattingMode" attribute
- // of this object.
+ // Return the value of the "FormattingMode" attribute of this object.
bool skipUnknownElements() const;
- // Return a reference to the non-modifiable "SkipUnknownElements"
- // attribute of this object.
+ // Return the value of the "SkipUnknownElements" attribute of this
+ // object.
bool validateInputIsUtf8() const;
- // Return a reference to the non-modifiable "ValidateInputIsUtf8"
- // attribute of this object.
+ // Return the value of the "ValidateInputIsUtf8" attribute of this
+ // object.
+
+ bool validateRootTag() const;
+ // Return the value of the "ValidateRootTag" attribute of this object.
};
// FREE OPERATORS
@@ -271,8 +282,8 @@ namespace balxml {
// CLASS METHODS
// MANIPULATORS
-template
-int DecoderOptions::manipulateAttributes(MANIPULATOR& manipulator)
+template
+int DecoderOptions::manipulateAttributes(t_MANIPULATOR& manipulator)
{
int ret;
@@ -296,11 +307,16 @@ int DecoderOptions::manipulateAttributes(MANIPULATOR& manipulator)
return ret;
}
- return ret;
+ ret = manipulator(&d_validateRootTag, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_VALIDATE_ROOT_TAG]);
+ if (ret) {
+ return ret;
+ }
+
+ return 0;
}
-template
-int DecoderOptions::manipulateAttribute(MANIPULATOR& manipulator, int id)
+template
+int DecoderOptions::manipulateAttribute(t_MANIPULATOR& manipulator, int id)
{
enum { NOT_FOUND = -1 };
@@ -317,16 +333,19 @@ int DecoderOptions::manipulateAttribute(MANIPULATOR& manipulator, int id)
case ATTRIBUTE_ID_VALIDATE_INPUT_IS_UTF8: {
return manipulator(&d_validateInputIsUtf8, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_VALIDATE_INPUT_IS_UTF8]);
}
+ case ATTRIBUTE_ID_VALIDATE_ROOT_TAG: {
+ return manipulator(&d_validateRootTag, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_VALIDATE_ROOT_TAG]);
+ }
default:
return NOT_FOUND;
}
}
-template
+template
int DecoderOptions::manipulateAttribute(
- MANIPULATOR& manipulator,
- const char *name,
- int nameLength)
+ t_MANIPULATOR& manipulator,
+ const char *name,
+ int nameLength)
{
enum { NOT_FOUND = -1 };
@@ -363,9 +382,15 @@ void DecoderOptions::setValidateInputIsUtf8(bool value)
d_validateInputIsUtf8 = value;
}
+inline
+void DecoderOptions::setValidateRootTag(bool value)
+{
+ d_validateRootTag = value;
+}
+
// ACCESSORS
-template
-int DecoderOptions::accessAttributes(ACCESSOR& accessor) const
+template
+int DecoderOptions::accessAttributes(t_ACCESSOR& accessor) const
{
int ret;
@@ -389,11 +414,16 @@ int DecoderOptions::accessAttributes(ACCESSOR& accessor) const
return ret;
}
- return ret;
+ ret = accessor(d_validateRootTag, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_VALIDATE_ROOT_TAG]);
+ if (ret) {
+ return ret;
+ }
+
+ return 0;
}
-template
-int DecoderOptions::accessAttribute(ACCESSOR& accessor, int id) const
+template
+int DecoderOptions::accessAttribute(t_ACCESSOR& accessor, int id) const
{
enum { NOT_FOUND = -1 };
@@ -410,16 +440,19 @@ int DecoderOptions::accessAttribute(ACCESSOR& accessor, int id) const
case ATTRIBUTE_ID_VALIDATE_INPUT_IS_UTF8: {
return accessor(d_validateInputIsUtf8, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_VALIDATE_INPUT_IS_UTF8]);
}
+ case ATTRIBUTE_ID_VALIDATE_ROOT_TAG: {
+ return accessor(d_validateRootTag, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_VALIDATE_ROOT_TAG]);
+ }
default:
return NOT_FOUND;
}
}
-template
+template
int DecoderOptions::accessAttribute(
- ACCESSOR& accessor,
- const char *name,
- int nameLength) const
+ t_ACCESSOR& accessor,
+ const char *name,
+ int nameLength) const
{
enum { NOT_FOUND = -1 };
@@ -456,6 +489,12 @@ bool DecoderOptions::validateInputIsUtf8() const
return d_validateInputIsUtf8;
}
+inline
+bool DecoderOptions::validateRootTag() const
+{
+ return d_validateRootTag;
+}
+
} // close package namespace
// FREE FUNCTIONS
@@ -468,7 +507,8 @@ bool balxml::operator==(
return lhs.maxDepth() == rhs.maxDepth()
&& lhs.formattingMode() == rhs.formattingMode()
&& lhs.skipUnknownElements() == rhs.skipUnknownElements()
- && lhs.validateInputIsUtf8() == rhs.validateInputIsUtf8();
+ && lhs.validateInputIsUtf8() == rhs.validateInputIsUtf8()
+ && lhs.validateRootTag() == rhs.validateRootTag();
}
inline
@@ -490,22 +530,12 @@ bsl::ostream& balxml::operator<<(
} // close enterprise namespace
#endif
-// BAS_CODEGEN RUN BY code_from_xsd.pl RUN ON Thu Sep 24 20:40:02 EDT 2020
-// GENERATED BY BLP_BAS_CODEGEN_2020.09.14
+// GENERATED BY @BLP_BAS_CODEGEN_VERSION@
// USING bas_codegen.pl -m msg -p balxml -E --noExternalization --noAggregateConversion --noHashSupport balxml.xsd
-
// ----------------------------------------------------------------------------
-// Copyright 2020 Bloomberg Finance L.P.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-// ----------------------------- END-OF-FILE ----------------------------------
+// NOTICE:
+// Copyright 2023 Bloomberg Finance L.P. All rights reserved.
+// Property of Bloomberg Finance L.P. (BFLP)
+// This software is made available solely pursuant to the
+// terms of a BFLP license agreement which governs its use.
+// ------------------------------- END-OF-FILE --------------------------------
diff --git a/groups/bal/balxml/balxml_encoderoptions.cpp b/groups/bal/balxml/balxml_encoderoptions.cpp
index b5a21db5a2..c39de783bc 100644
--- a/groups/bal/balxml/balxml_encoderoptions.cpp
+++ b/groups/bal/balxml/balxml_encoderoptions.cpp
@@ -1,7 +1,7 @@
// balxml_encoderoptions.cpp *DO NOT EDIT* @generated -*-C++-*-
#include
-BSLS_IDENT_RCSID(balxml_encoderoptions_cpp,"$Id$ $CSID$")
+BSLS_IDENT_RCSID(balxml_encoderoptions_cpp, "$Id$ $CSID$")
#include
@@ -17,9 +17,11 @@ BSLS_IDENT_RCSID(balxml_encoderoptions_cpp,"$Id$ $CSID$")
#include
#include
+#include
#include
#include
#include
+#include
namespace BloombergLP {
namespace balxml {
@@ -395,10 +397,9 @@ void EncoderOptions::reset()
// ACCESSORS
-bsl::ostream& EncoderOptions::print(
- bsl::ostream& stream,
- int level,
- int spacesPerLevel) const
+bsl::ostream& EncoderOptions::print(bsl::ostream& stream,
+ int level,
+ int spacesPerLevel) const
{
bslim::Printer printer(&stream, level, spacesPerLevel);
printer.start();
@@ -426,22 +427,12 @@ bsl::ostream& EncoderOptions::print(
} // close package namespace
} // close enterprise namespace
-// BAS_CODEGEN RUN BY code_from_xsd.pl RUN ON Thu Sep 24 20:40:02 EDT 2020
-// GENERATED BY BLP_BAS_CODEGEN_2020.09.14
+// GENERATED BY @BLP_BAS_CODEGEN_VERSION@
// USING bas_codegen.pl -m msg -p balxml -E --noExternalization --noAggregateConversion --noHashSupport balxml.xsd
-
// ----------------------------------------------------------------------------
-// Copyright 2020 Bloomberg Finance L.P.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-// ----------------------------- END-OF-FILE ----------------------------------
+// NOTICE:
+// Copyright 2023 Bloomberg Finance L.P. All rights reserved.
+// Property of Bloomberg Finance L.P. (BFLP)
+// This software is made available solely pursuant to the
+// terms of a BFLP license agreement which governs its use.
+// ------------------------------- END-OF-FILE --------------------------------
diff --git a/groups/bal/balxml/balxml_encoderoptions.h b/groups/bal/balxml/balxml_encoderoptions.h
index dea7f55e50..b4cdfa4403 100644
--- a/groups/bal/balxml/balxml_encoderoptions.h
+++ b/groups/bal/balxml/balxml_encoderoptions.h
@@ -3,7 +3,7 @@
#define INCLUDED_BALXML_ENCODEROPTIONS
#include
-BSLS_IDENT_RCSID(balxml_encoderoptions_h,"$Id$ $CSID$")
+BSLS_IDENT_RCSID(balxml_encoderoptions_h, "$Id$ $CSID$")
BSLS_IDENT_PRAGMA_ONCE
//@PURPOSE: Provide value-semantic attribute classes
@@ -31,10 +31,9 @@ BSLS_IDENT_PRAGMA_ONCE
#include
#include
-#include
-
namespace BloombergLP {
+namespace bslma { class Allocator; }
namespace balxml { class EncoderOptions; }
namespace balxml {
@@ -51,8 +50,8 @@ class EncoderOptions {
// used to specify the formatting of the output. Note that
// 'InitialIndentLevel', 'SpacesPerLevel', and 'WrapColumn' are ignored
// when 'EncodingStyle' is COMPACT (this is the default).
- // This struct is generated using bas_codegen.pl called by
- // balxml/code_from_xsd.pl
+ // The generated C++ code for this schema element is created by using
+ // bas_codegen.pl, run by balxml/code_from_xsd.pl, with no hand-editing.
// INSTANCE DATA
bsl::string d_objectNamespace;
@@ -72,6 +71,9 @@ class EncoderOptions {
int d_datetimeFractionalSecondPrecision;
// This option controls the number of decimal places used for seconds
// when encoding 'Datetime' and 'DatetimeTz'.
+ // Note that the default of this field is '6' in
+ // 'balxml_encoderoptions.cpp', but is edited to '3' in
+ // 'balxml_configschema.cpp' by balxml/code_from_xsd.pl.
bdlb::NullableValue d_maxDecimalTotalDigits;
// Maximum total digits of the decimal value that should be displayed
bdlb::NullableValue d_maxDecimalFractionDigits;
@@ -92,8 +94,7 @@ class EncoderOptions {
// alias with the top-level element.
bool d_useZAbbreviationForUtc;
// This option control whether 'Z' should be used for the zone
- // designator of 'DateTz', TimeTz, and 'DatetimeTz' or instead of
- // +00:00' (specific to UTC).
+ // designator of 'DateTz' or instead of '+00:00' (specific to UTC).
public:
// TYPES
@@ -227,8 +228,8 @@ class EncoderOptions {
// Reset this object to the default value (i.e., its value upon
// default construction).
- template
- int manipulateAttributes(MANIPULATOR& manipulator);
+ template
+ int manipulateAttributes(t_MANIPULATOR& manipulator);
// Invoke the specified 'manipulator' sequentially on the address of
// each (modifiable) attribute of this object, supplying 'manipulator'
// with the corresponding attribute information structure until such
@@ -236,8 +237,8 @@ class EncoderOptions {
// last invocation of 'manipulator' (i.e., the invocation that
// terminated the sequence).
- template
- int manipulateAttribute(MANIPULATOR& manipulator, int id);
+ template
+ int manipulateAttribute(t_MANIPULATOR& manipulator, int id);
// Invoke the specified 'manipulator' on the address of
// the (modifiable) attribute indicated by the specified 'id',
// supplying 'manipulator' with the corresponding attribute
@@ -245,8 +246,8 @@ class EncoderOptions {
// invocation of 'manipulator' if 'id' identifies an attribute of this
// class, and -1 otherwise.
- template
- int manipulateAttribute(MANIPULATOR& manipulator,
+ template
+ int manipulateAttribute(t_MANIPULATOR& manipulator,
const char *name,
int nameLength);
// Invoke the specified 'manipulator' on the address of
@@ -256,15 +257,15 @@ class EncoderOptions {
// returned from the invocation of 'manipulator' if 'name' identifies
// an attribute of this class, and -1 otherwise.
- void setObjectNamespace(const bsl::string_view& value);
+ void setObjectNamespace(const bsl::string& value);
// Set the "ObjectNamespace" attribute of this object to the specified
// 'value'.
- void setSchemaLocation(const bsl::string_view& value);
+ void setSchemaLocation(const bsl::string& value);
// Set the "SchemaLocation" attribute of this object to the specified
// 'value'.
- void setTag(const bsl::string_view& value);
+ void setTag(const bsl::string& value);
// Set the "Tag" attribute of this object to the specified 'value'.
void setFormattingMode(int value);
@@ -321,7 +322,7 @@ class EncoderOptions {
// ACCESSORS
bsl::ostream& print(bsl::ostream& stream,
- int level = 0,
+ int level = 0,
int spacesPerLevel = 4) const;
// Format this object to the specified output 'stream' at the
// optionally specified indentation 'level' and return a reference to
@@ -335,8 +336,8 @@ class EncoderOptions {
// operation has no effect. Note that a trailing newline is provided
// in multiline mode only.
- template
- int accessAttributes(ACCESSOR& accessor) const;
+ template
+ int accessAttributes(t_ACCESSOR& accessor) const;
// Invoke the specified 'accessor' sequentially on each
// (non-modifiable) attribute of this object, supplying 'accessor'
// with the corresponding attribute information structure until such
@@ -344,16 +345,16 @@ class EncoderOptions {
// last invocation of 'accessor' (i.e., the invocation that terminated
// the sequence).
- template
- int accessAttribute(ACCESSOR& accessor, int id) const;
+ template
+ int accessAttribute(t_ACCESSOR& accessor, int id) const;
// Invoke the specified 'accessor' on the (non-modifiable) attribute
// of this object indicated by the specified 'id', supplying 'accessor'
// with the corresponding attribute information structure. Return the
// value returned from the invocation of 'accessor' if 'id' identifies
// an attribute of this class, and -1 otherwise.
- template
- int accessAttribute(ACCESSOR& accessor,
+ template
+ int accessAttribute(t_ACCESSOR& accessor,
const char *name,
int nameLength) const;
// Invoke the specified 'accessor' on the (non-modifiable) attribute
@@ -364,68 +365,62 @@ class EncoderOptions {
// class, and -1 otherwise.
const bsl::string& objectNamespace() const;
- // Return a reference to the non-modifiable "ObjectNamespace" attribute
- // of this object.
+ // Return a reference offering non-modifiable access to the
+ // "ObjectNamespace" attribute of this object.
const bsl::string& schemaLocation() const;
- // Return a reference to the non-modifiable "SchemaLocation" attribute
- // of this object.
+ // Return a reference offering non-modifiable access to the
+ // "SchemaLocation" attribute of this object.
const bsl::string& tag() const;
- // Return a reference to the non-modifiable "Tag" attribute of this
- // object.
+ // Return a reference offering non-modifiable access to the "Tag"
+ // attribute of this object.
int formattingMode() const;
- // Return a reference to the non-modifiable "FormattingMode" attribute
- // of this object.
+ // Return the value of the "FormattingMode" attribute of this object.
int initialIndentLevel() const;
- // Return a reference to the non-modifiable "InitialIndentLevel"
- // attribute of this object.
+ // Return the value of the "InitialIndentLevel" attribute of this
+ // object.
int spacesPerLevel() const;
- // Return a reference to the non-modifiable "SpacesPerLevel" attribute
- // of this object.
+ // Return the value of the "SpacesPerLevel" attribute of this object.
int wrapColumn() const;
- // Return a reference to the non-modifiable "WrapColumn" attribute of
- // this object.
+ // Return the value of the "WrapColumn" attribute of this object.
const bdlb::NullableValue& maxDecimalTotalDigits() const;
- // Return a reference to the non-modifiable "MaxDecimalTotalDigits"
- // attribute of this object.
+ // Return a reference offering non-modifiable access to the
+ // "MaxDecimalTotalDigits" attribute of this object.
const bdlb::NullableValue& maxDecimalFractionDigits() const;
- // Return a reference to the non-modifiable "MaxDecimalFractionDigits"
- // attribute of this object.
+ // Return a reference offering non-modifiable access to the
+ // "MaxDecimalFractionDigits" attribute of this object.
const bdlb::NullableValue& significantDoubleDigits() const;
- // Return a reference to the non-modifiable "SignificantDoubleDigits"
- // attribute of this object.
+ // Return a reference offering non-modifiable access to the
+ // "SignificantDoubleDigits" attribute of this object.
EncodingStyle::Value encodingStyle() const;
- // Return a reference to the non-modifiable "EncodingStyle" attribute
- // of this object.
+ // Return the value of the "EncodingStyle" attribute of this object.
bool allowControlCharacters() const;
- // Return a reference to the non-modifiable "AllowControlCharacters"
- // attribute of this object.
+ // Return the value of the "AllowControlCharacters" attribute of this
+ // object.
bool outputXMLHeader() const;
- // Return a reference to the non-modifiable "OutputXMLHeader" attribute
- // of this object.
+ // Return the value of the "OutputXMLHeader" attribute of this object.
bool outputXSIAlias() const;
- // Return a reference to the non-modifiable "OutputXSIAlias" attribute
- // of this object.
+ // Return the value of the "OutputXSIAlias" attribute of this object.
int datetimeFractionalSecondPrecision() const;
- // Return a reference to the non-modifiable
- // "DatetimeFractionalSecondPrecision" attribute of this object.
+ // Return the value of the "DatetimeFractionalSecondPrecision"
+ // attribute of this object.
bool useZAbbreviationForUtc() const;
- // Return a reference to the non-modifiable "UseZAbbreviationForUtc"
- // attribute of this object.
+ // Return the value of the "UseZAbbreviationForUtc" attribute of this
+ // object.
};
// FREE OPERATORS
@@ -465,8 +460,8 @@ namespace balxml {
// CLASS METHODS
// MANIPULATORS
-template
-int EncoderOptions::manipulateAttributes(MANIPULATOR& manipulator)
+template
+int EncoderOptions::manipulateAttributes(t_MANIPULATOR& manipulator)
{
int ret;
@@ -550,11 +545,11 @@ int EncoderOptions::manipulateAttributes(MANIPULATOR& manipulator)
return ret;
}
- return ret;
+ return 0;
}
-template
-int EncoderOptions::manipulateAttribute(MANIPULATOR& manipulator, int id)
+template
+int EncoderOptions::manipulateAttribute(t_MANIPULATOR& manipulator, int id)
{
enum { NOT_FOUND = -1 };
@@ -612,11 +607,11 @@ int EncoderOptions::manipulateAttribute(MANIPULATOR& manipulator, int id)
}
}
-template
+template
int EncoderOptions::manipulateAttribute(
- MANIPULATOR& manipulator,
- const char *name,
- int nameLength)
+ t_MANIPULATOR& manipulator,
+ const char *name,
+ int nameLength)
{
enum { NOT_FOUND = -1 };
@@ -630,19 +625,19 @@ int EncoderOptions::manipulateAttribute(
}
inline
-void EncoderOptions::setObjectNamespace(const bsl::string_view& value)
+void EncoderOptions::setObjectNamespace(const bsl::string& value)
{
d_objectNamespace = value;
}
inline
-void EncoderOptions::setSchemaLocation(const bsl::string_view& value)
+void EncoderOptions::setSchemaLocation(const bsl::string& value)
{
d_schemaLocation = value;
}
inline
-void EncoderOptions::setTag(const bsl::string_view& value)
+void EncoderOptions::setTag(const bsl::string& value)
{
d_tag = value;
}
@@ -726,8 +721,8 @@ void EncoderOptions::setUseZAbbreviationForUtc(bool value)
}
// ACCESSORS
-template
-int EncoderOptions::accessAttributes(ACCESSOR& accessor) const
+template
+int EncoderOptions::accessAttributes(t_ACCESSOR& accessor) const
{
int ret;
@@ -811,11 +806,11 @@ int EncoderOptions::accessAttributes(ACCESSOR& accessor) const
return ret;
}
- return ret;
+ return 0;
}
-template
-int EncoderOptions::accessAttribute(ACCESSOR& accessor, int id) const
+template
+int EncoderOptions::accessAttribute(t_ACCESSOR& accessor, int id) const
{
enum { NOT_FOUND = -1 };
@@ -873,11 +868,11 @@ int EncoderOptions::accessAttribute(ACCESSOR& accessor, int id) const
}
}
-template
+template
int EncoderOptions::accessAttribute(
- ACCESSOR& accessor,
- const char *name,
- int nameLength) const
+ t_ACCESSOR& accessor,
+ const char *name,
+ int nameLength) const
{
enum { NOT_FOUND = -1 };
@@ -1032,22 +1027,12 @@ bsl::ostream& balxml::operator<<(
} // close enterprise namespace
#endif
-// BAS_CODEGEN RUN BY code_from_xsd.pl RUN ON Thu Sep 24 20:40:02 EDT 2020
-// GENERATED BY BLP_BAS_CODEGEN_2020.09.14
+// GENERATED BY @BLP_BAS_CODEGEN_VERSION@
// USING bas_codegen.pl -m msg -p balxml -E --noExternalization --noAggregateConversion --noHashSupport balxml.xsd
-
// ----------------------------------------------------------------------------
-// Copyright 2020 Bloomberg Finance L.P.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-// ----------------------------- END-OF-FILE ----------------------------------
+// NOTICE:
+// Copyright 2023 Bloomberg Finance L.P. All rights reserved.
+// Property of Bloomberg Finance L.P. (BFLP)
+// This software is made available solely pursuant to the
+// terms of a BFLP license agreement which governs its use.
+// ------------------------------- END-OF-FILE --------------------------------