#include <baljsn_encoderoptions.h>
List of all members.
Public Types |
enum | EncodingStyle { e_COMPACT = baljsn::EncodingStyle::e_COMPACT,
e_PRETTY = baljsn::EncodingStyle::e_PRETTY,
BAEJSN_COMPACT = e_COMPACT,
BAEJSN_PRETTY = e_PRETTY
} |
enum | {
ATTRIBUTE_ID_INITIAL_INDENT_LEVEL = 0,
ATTRIBUTE_ID_SPACES_PER_LEVEL = 1,
ATTRIBUTE_ID_ENCODING_STYLE = 2,
ATTRIBUTE_ID_ENCODE_EMPTY_ARRAYS = 3,
ATTRIBUTE_ID_ENCODE_NULL_ELEMENTS = 4,
ATTRIBUTE_ID_ENCODE_INF_AND_NA_N_AS_STRINGS = 5,
ATTRIBUTE_ID_DATETIME_FRACTIONAL_SECOND_PRECISION = 6,
ATTRIBUTE_ID_MAX_FLOAT_PRECISION = 7,
ATTRIBUTE_ID_MAX_DOUBLE_PRECISION = 8,
ATTRIBUTE_ID_ENCODE_QUOTED_DECIMAL64 = 9
} |
enum | { NUM_ATTRIBUTES = 10
} |
enum | {
ATTRIBUTE_INDEX_INITIAL_INDENT_LEVEL = 0,
ATTRIBUTE_INDEX_SPACES_PER_LEVEL = 1,
ATTRIBUTE_INDEX_ENCODING_STYLE = 2,
ATTRIBUTE_INDEX_ENCODE_EMPTY_ARRAYS = 3,
ATTRIBUTE_INDEX_ENCODE_NULL_ELEMENTS = 4,
ATTRIBUTE_INDEX_ENCODE_INF_AND_NA_N_AS_STRINGS = 5,
ATTRIBUTE_INDEX_DATETIME_FRACTIONAL_SECOND_PRECISION = 6,
ATTRIBUTE_INDEX_MAX_FLOAT_PRECISION = 7,
ATTRIBUTE_INDEX_MAX_DOUBLE_PRECISION = 8,
ATTRIBUTE_INDEX_ENCODE_QUOTED_DECIMAL64 = 9
} |
Public Member Functions |
| EncoderOptions () |
| EncoderOptions (const EncoderOptions &original) |
| ~EncoderOptions () |
EncoderOptions & | operator= (const EncoderOptions &rhs) |
void | reset () |
template<class MANIPULATOR > |
int | manipulateAttributes (MANIPULATOR &manipulator) |
template<class MANIPULATOR > |
int | manipulateAttribute (MANIPULATOR &manipulator, int id) |
template<class MANIPULATOR > |
int | manipulateAttribute (MANIPULATOR &manipulator, const char *name, int nameLength) |
void | setInitialIndentLevel (int value) |
void | setSpacesPerLevel (int value) |
void | setEncodingStyle (baljsn::EncodingStyle::Value value) |
void | setEncodingStyle (baljsn::EncoderOptions::EncodingStyle value) |
void | setEncodeEmptyArrays (bool value) |
void | setEncodeNullElements (bool value) |
void | setEncodeInfAndNaNAsStrings (bool value) |
void | setDatetimeFractionalSecondPrecision (int value) |
void | setMaxFloatPrecision (int value) |
void | setMaxDoublePrecision (int value) |
void | setEncodeQuotedDecimal64 (bool value) |
bsl::ostream & | print (bsl::ostream &stream, int level=0, int spacesPerLevel=4) const |
template<class ACCESSOR > |
int | accessAttributes (ACCESSOR &accessor) const |
template<class ACCESSOR > |
int | accessAttribute (ACCESSOR &accessor, int id) const |
template<class ACCESSOR > |
int | accessAttribute (ACCESSOR &accessor, const char *name, int nameLength) const |
int | initialIndentLevel () const |
int | spacesPerLevel () const |
baljsn::EncoderOptions::EncodingStyle | encodingStyle () const |
bool | encodeEmptyArrays () const |
bool | encodeNullElements () const |
bool | encodeInfAndNaNAsStrings () const |
int | datetimeFractionalSecondPrecision () const |
int | maxFloatPrecision () const |
int | maxDoublePrecision () const |
bool | encodeQuotedDecimal64 () const |
Static Public Member Functions |
static const bdlat_AttributeInfo * | lookupAttributeInfo (int id) |
static const bdlat_AttributeInfo * | lookupAttributeInfo (const char *name, int nameLength) |
Static Public Attributes |
static const char | CLASS_NAME [] |
static const int | DEFAULT_INITIALIZER_INITIAL_INDENT_LEVEL |
static const int | DEFAULT_INITIALIZER_SPACES_PER_LEVEL |
static const
baljsn::EncodingStyle::Value | DEFAULT_INITIALIZER_ENCODING_STYLE |
static const bool | DEFAULT_INITIALIZER_ENCODE_EMPTY_ARRAYS |
static const bool | DEFAULT_INITIALIZER_ENCODE_NULL_ELEMENTS |
static const bool | DEFAULT_INITIALIZER_ENCODE_INF_AND_NA_N_AS_STRINGS |
static const int | DEFAULT_INITIALIZER_DATETIME_FRACTIONAL_SECOND_PRECISION |
static const int | DEFAULT_INITIALIZER_MAX_FLOAT_PRECISION |
static const int | DEFAULT_INITIALIZER_MAX_DOUBLE_PRECISION |
static const bool | DEFAULT_INITIALIZER_ENCODE_QUOTED_DECIMAL64 |
static const bdlat_AttributeInfo | ATTRIBUTE_INFO_ARRAY [] |
Detailed Description
Options for performing JSON encoding. EncodingStyle
is either COMPACT
or PRETTY
. If EncodingStyle
is COMPACT
, no whitespace will be added between elements. If encoding style is PRETTY
, then the InitialIndentLevel
and SpacesPerLevel
parameters are used to specify the formatting of the output. Note that InitialIndentLevel
and SpacesPerLevel
are ignored when EncodingStyle
is COMPACT
(this is the default). The EncodeEmptyArrays
and EncodeNullElements
encode empty array and null elements respectively. By default empty array and null elements are not encoded. The EncodeInfAndNaNAsStrings
attribute provides users the option to encode Infinity
and NaN
floating point values as strings. These values do not have a valid JSON representation and by default such value will result in an encoding error. The DatetimeFractionalSecondPrecision
specifies the precision of milliseconds printed with date time values. By default a precision of 3
decimal places is used. The MaxFloatPrecision
and MaxDoublePrecision
attributes allow specifying the maximum precision for float
and double
values. When not specified, or 0 is specified, the precision is determined automatically to use enough digits to ensure restoring the original binary floating point value by a reader. We recommend against setting these options: they were provided prior to the current default behavior (of choosing the shortest presentation that can be restored to the original value) being available.
See Component baljsn_encoderoptions
Member Enumeration Documentation
This enum
provides enumerators to specify the encoding styles. This enum
is replicated in this class
for backwards-compatibility with baejsn
. Users should use baljsn::EncodingStyle
directly.
- Enumerator:
e_COMPACT |
|
e_PRETTY |
|
BAEJSN_COMPACT |
|
BAEJSN_PRETTY |
|
- Enumerator:
ATTRIBUTE_ID_INITIAL_INDENT_LEVEL |
|
ATTRIBUTE_ID_SPACES_PER_LEVEL |
|
ATTRIBUTE_ID_ENCODING_STYLE |
|
ATTRIBUTE_ID_ENCODE_EMPTY_ARRAYS |
|
ATTRIBUTE_ID_ENCODE_NULL_ELEMENTS |
|
ATTRIBUTE_ID_ENCODE_INF_AND_NA_N_AS_STRINGS |
|
ATTRIBUTE_ID_DATETIME_FRACTIONAL_SECOND_PRECISION |
|
ATTRIBUTE_ID_MAX_FLOAT_PRECISION |
|
ATTRIBUTE_ID_MAX_DOUBLE_PRECISION |
|
ATTRIBUTE_ID_ENCODE_QUOTED_DECIMAL64 |
|
- Enumerator:
ATTRIBUTE_INDEX_INITIAL_INDENT_LEVEL |
|
ATTRIBUTE_INDEX_SPACES_PER_LEVEL |
|
ATTRIBUTE_INDEX_ENCODING_STYLE |
|
ATTRIBUTE_INDEX_ENCODE_EMPTY_ARRAYS |
|
ATTRIBUTE_INDEX_ENCODE_NULL_ELEMENTS |
|
ATTRIBUTE_INDEX_ENCODE_INF_AND_NA_N_AS_STRINGS |
|
ATTRIBUTE_INDEX_DATETIME_FRACTIONAL_SECOND_PRECISION |
|
ATTRIBUTE_INDEX_MAX_FLOAT_PRECISION |
|
ATTRIBUTE_INDEX_MAX_DOUBLE_PRECISION |
|
ATTRIBUTE_INDEX_ENCODE_QUOTED_DECIMAL64 |
|
Constructor & Destructor Documentation
baljsn::EncoderOptions::EncoderOptions |
( |
|
) |
|
baljsn::EncoderOptions::EncoderOptions |
( |
const EncoderOptions & |
original |
) |
|
Create an object of type EncoderOptions
having the value of the specified original
object.
baljsn::EncoderOptions::~EncoderOptions |
( |
|
) |
|
Member Function Documentation
static const bdlat_AttributeInfo* baljsn::EncoderOptions::lookupAttributeInfo |
( |
int |
id |
) |
[static] |
Return attribute information for the attribute indicated by the specified id
if the attribute exists, and 0 otherwise.
static const bdlat_AttributeInfo* baljsn::EncoderOptions::lookupAttributeInfo |
( |
const char * |
name, |
|
|
int |
nameLength | |
|
) |
| | [static] |
Return attribute information for the attribute indicated by the specified name
of the specified nameLength
if the attribute exists, and 0 otherwise.
Assign to this object the value of the specified rhs
object.
void baljsn::EncoderOptions::reset |
( |
|
) |
|
Reset this object to the default value (i.e., its value upon default construction).
template<class MANIPULATOR >
int baljsn::EncoderOptions::manipulateAttributes |
( |
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 invocation returns a non-zero value. Return the value from the last invocation of manipulator
(i.e., the invocation that terminated the sequence).
template<class MANIPULATOR >
int baljsn::EncoderOptions::manipulateAttribute |
( |
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 information structure. Return the value returned from the invocation of manipulator
if id
identifies an attribute of this class, and -1 otherwise.
template<class MANIPULATOR >
int baljsn::EncoderOptions::manipulateAttribute |
( |
MANIPULATOR & |
manipulator, |
|
|
const char * |
name, |
|
|
int |
nameLength | |
|
) |
| | |
Invoke the specified manipulator
on the address of the (modifiable) attribute indicated by the specified name
of the specified nameLength
, supplying manipulator
with the corresponding attribute information structure. Return the value returned from the invocation of manipulator
if name
identifies an attribute of this class, and -1 otherwise.
void baljsn::EncoderOptions::setInitialIndentLevel |
( |
int |
value |
) |
|
Set the "InitialIndentLevel" attribute of this object to the specified value
.
void baljsn::EncoderOptions::setSpacesPerLevel |
( |
int |
value |
) |
|
Set the "SpacesPerLevel" attribute of this object to the specified value
.
Set the "EncodingStyle" attribute of this object to the specified value
.
void baljsn::EncoderOptions::setEncodeEmptyArrays |
( |
bool |
value |
) |
|
Set the "EncodeEmptyArrays" attribute of this object to the specified value
.
void baljsn::EncoderOptions::setEncodeNullElements |
( |
bool |
value |
) |
|
Set the "EncodeNullElements" attribute of this object to the specified value
.
void baljsn::EncoderOptions::setEncodeInfAndNaNAsStrings |
( |
bool |
value |
) |
|
Set the "EncodeInfAndNaNAsStrings" attribute of this object to the specified value
.
void baljsn::EncoderOptions::setDatetimeFractionalSecondPrecision |
( |
int |
value |
) |
|
Set the "DatetimeFractionalSecondPrecision" attribute of this object to the specified value
.
void baljsn::EncoderOptions::setMaxFloatPrecision |
( |
int |
value |
) |
|
Set the "MaxFloatPrecision" attribute of this object to the specified value
.
void baljsn::EncoderOptions::setMaxDoublePrecision |
( |
int |
value |
) |
|
Set the "MaxDoublePrecision" attribute of this object to the specified value
.
void baljsn::EncoderOptions::setEncodeQuotedDecimal64 |
( |
bool |
value |
) |
|
Set the "EncodeQuotedDecimal64" attribute of this object to the specified value
.
bsl::ostream& baljsn::EncoderOptions::print |
( |
bsl::ostream & |
stream, |
|
|
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 the modifiable stream
. If level
is specified, optionally specify spacesPerLevel
, the number of spaces per indentation level for this and all of its nested objects. Each line is indented by the absolute value of level * spacesPerLevel
. If level
is negative, suppress indentation of the first line. If spacesPerLevel
is negative, suppress line breaks and format the entire output on one line. If stream
is initially invalid, this operation has no effect. Note that a trailing newline is provided in multiline mode only.
template<class ACCESSOR >
int baljsn::EncoderOptions::accessAttributes |
( |
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 invocation returns a non-zero value. Return the value from the last invocation of accessor
(i.e., the invocation that terminated the sequence).
template<class ACCESSOR >
int baljsn::EncoderOptions::accessAttribute |
( |
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<class ACCESSOR >
int baljsn::EncoderOptions::accessAttribute |
( |
ACCESSOR & |
accessor, |
|
|
const char * |
name, |
|
|
int |
nameLength | |
|
) |
| | const |
Invoke the specified accessor
on the (non-modifiable) attribute of this object indicated by the specified name
of the specified nameLength
, supplying accessor
with the corresponding attribute information structure. Return the value returned from the invocation of accessor
if name
identifies an attribute of this class, and -1 otherwise.
int baljsn::EncoderOptions::initialIndentLevel |
( |
|
) |
const |
Return a reference to the non-modifiable "InitialIndentLevel" attribute of this object.
int baljsn::EncoderOptions::spacesPerLevel |
( |
|
) |
const |
Return a reference to the non-modifiable "SpacesPerLevel" attribute of this object.
Return a reference to the non-modifiable "EncodingStyle" attribute of this object.
bool baljsn::EncoderOptions::encodeEmptyArrays |
( |
|
) |
const |
Return a reference to the non-modifiable "EncodeEmptyArrays" attribute of this object. Note that empty arrays occurring as selections of choices are always encoded regardless of the setting of this option.
bool baljsn::EncoderOptions::encodeNullElements |
( |
|
) |
const |
Return a reference to the non-modifiable "EncodeNullElements" attribute of this object.
bool baljsn::EncoderOptions::encodeInfAndNaNAsStrings |
( |
|
) |
const |
Return a reference to the non-modifiable "EncodeInfAndNaNAsStrings" attribute of this object.
int baljsn::EncoderOptions::datetimeFractionalSecondPrecision |
( |
|
) |
const |
Return a reference to the non-modifiable "DatetimeFractionalSecondPrecision" attribute of this object.
int baljsn::EncoderOptions::maxFloatPrecision |
( |
|
) |
const |
Return a reference to the non-modifiable "MaxFloatPrecision" attribute of this object.
int baljsn::EncoderOptions::maxDoublePrecision |
( |
|
) |
const |
Return a reference to the non-modifiable "MaxDoublePrecision" attribute of this object.
bool baljsn::EncoderOptions::encodeQuotedDecimal64 |
( |
|
) |
const |
Return the value of the "EncodeQuotedDecimal64" attribute of this object.
Member Data Documentation
The documentation for this class was generated from the following file: