BDE 4.14.0 Production release
Loading...
Searching...
No Matches
baljsn::EncoderOptions Class Reference

#include <baljsn_encoderoptions.h>

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 ()
 Create an object of type EncoderOptions having the default value.
 
 EncoderOptions (const EncoderOptions &original)
 
 ~EncoderOptions ()
 Destroy this object.
 
EncoderOptionsoperator= (const EncoderOptions &rhs)
 Assign to this object the value of the specified rhs object.
 
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_AttributeInfolookupAttributeInfo (int id)
 
static const bdlat_AttributeInfolookupAttributeInfo (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 baljsn_encoderoptions

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
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 

◆ anonymous enum

anonymous enum
Enumerator
NUM_ATTRIBUTES 

◆ anonymous enum

anonymous enum
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 

◆ EncodingStyle

Enumerator
e_COMPACT 
e_PRETTY 
BAEJSN_COMPACT 
BAEJSN_PRETTY 

Constructor & Destructor Documentation

◆ EncoderOptions() [1/2]

baljsn::EncoderOptions::EncoderOptions ( )

◆ EncoderOptions() [2/2]

baljsn::EncoderOptions::EncoderOptions ( const EncoderOptions original)

Create an object of type EncoderOptions having the value of the specified original object.

◆ ~EncoderOptions()

baljsn::EncoderOptions::~EncoderOptions ( )

Member Function Documentation

◆ accessAttribute() [1/2]

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.

◆ accessAttribute() [2/2]

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.

◆ accessAttributes()

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).

◆ datetimeFractionalSecondPrecision()

int baljsn::EncoderOptions::datetimeFractionalSecondPrecision ( ) const
inline

Return a reference to the non-modifiable "DatetimeFractionalSecondPrecision" attribute of this object.

◆ encodeEmptyArrays()

bool baljsn::EncoderOptions::encodeEmptyArrays ( ) const
inline

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.

◆ encodeInfAndNaNAsStrings()

bool baljsn::EncoderOptions::encodeInfAndNaNAsStrings ( ) const
inline

Return a reference to the non-modifiable "EncodeInfAndNaNAsStrings" attribute of this object.

◆ encodeNullElements()

bool baljsn::EncoderOptions::encodeNullElements ( ) const
inline

Return a reference to the non-modifiable "EncodeNullElements" attribute of this object.

◆ encodeQuotedDecimal64()

bool baljsn::EncoderOptions::encodeQuotedDecimal64 ( ) const
inline

Return the value of the "EncodeQuotedDecimal64" attribute of this object.

◆ encodingStyle()

baljsn::EncoderOptions::EncodingStyle baljsn::EncoderOptions::encodingStyle ( ) const
inline

Return a reference to the non-modifiable "EncodingStyle" attribute of this object.

◆ initialIndentLevel()

int baljsn::EncoderOptions::initialIndentLevel ( ) const
inline

Return a reference to the non-modifiable "InitialIndentLevel" attribute of this object.

◆ lookupAttributeInfo() [1/2]

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.

◆ lookupAttributeInfo() [2/2]

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.

◆ manipulateAttribute() [1/2]

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.

◆ manipulateAttribute() [2/2]

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.

◆ manipulateAttributes()

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).

◆ maxDoublePrecision()

int baljsn::EncoderOptions::maxDoublePrecision ( ) const
inline

Return a reference to the non-modifiable "MaxDoublePrecision" attribute of this object.

◆ maxFloatPrecision()

int baljsn::EncoderOptions::maxFloatPrecision ( ) const
inline

Return a reference to the non-modifiable "MaxFloatPrecision" attribute of this object.

◆ operator=()

EncoderOptions & baljsn::EncoderOptions::operator= ( const EncoderOptions rhs)

◆ print()

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.

◆ reset()

void baljsn::EncoderOptions::reset ( )

Reset this object to the default value (i.e., its value upon default construction).

◆ setDatetimeFractionalSecondPrecision()

void baljsn::EncoderOptions::setDatetimeFractionalSecondPrecision ( int  value)
inline

Set the "DatetimeFractionalSecondPrecision" attribute of this object to the specified value.

◆ setEncodeEmptyArrays()

void baljsn::EncoderOptions::setEncodeEmptyArrays ( bool  value)
inline

Set the "EncodeEmptyArrays" attribute of this object to the specified value.

◆ setEncodeInfAndNaNAsStrings()

void baljsn::EncoderOptions::setEncodeInfAndNaNAsStrings ( bool  value)
inline

Set the "EncodeInfAndNaNAsStrings" attribute of this object to the specified value.

◆ setEncodeNullElements()

void baljsn::EncoderOptions::setEncodeNullElements ( bool  value)
inline

Set the "EncodeNullElements" attribute of this object to the specified value.

◆ setEncodeQuotedDecimal64()

void baljsn::EncoderOptions::setEncodeQuotedDecimal64 ( bool  value)
inline

Set the "EncodeQuotedDecimal64" attribute of this object to the specified value.

◆ setEncodingStyle() [1/2]

void baljsn::EncoderOptions::setEncodingStyle ( baljsn::EncoderOptions::EncodingStyle  value)
inline

Set the "EncodingStyle" attribute of this object to the specified value.

◆ setEncodingStyle() [2/2]

void baljsn::EncoderOptions::setEncodingStyle ( baljsn::EncodingStyle::Value  value)
inline

◆ setInitialIndentLevel()

void baljsn::EncoderOptions::setInitialIndentLevel ( int  value)
inline

Set the "InitialIndentLevel" attribute of this object to the specified value.

◆ setMaxDoublePrecision()

void baljsn::EncoderOptions::setMaxDoublePrecision ( int  value)
inline

Set the "MaxDoublePrecision" attribute of this object to the specified value.

◆ setMaxFloatPrecision()

void baljsn::EncoderOptions::setMaxFloatPrecision ( int  value)
inline

Set the "MaxFloatPrecision" attribute of this object to the specified value.

◆ setSpacesPerLevel()

void baljsn::EncoderOptions::setSpacesPerLevel ( int  value)
inline

Set the "SpacesPerLevel" attribute of this object to the specified value.

◆ spacesPerLevel()

int baljsn::EncoderOptions::spacesPerLevel ( ) const
inline

Return a reference to the non-modifiable "SpacesPerLevel" attribute of this object.

Member Data Documentation

◆ ATTRIBUTE_INFO_ARRAY

const bdlat_AttributeInfo baljsn::EncoderOptions::ATTRIBUTE_INFO_ARRAY[]
static

◆ CLASS_NAME

const char baljsn::EncoderOptions::CLASS_NAME[]
static

◆ DEFAULT_INITIALIZER_DATETIME_FRACTIONAL_SECOND_PRECISION

const int baljsn::EncoderOptions::DEFAULT_INITIALIZER_DATETIME_FRACTIONAL_SECOND_PRECISION
static

◆ DEFAULT_INITIALIZER_ENCODE_EMPTY_ARRAYS

const bool baljsn::EncoderOptions::DEFAULT_INITIALIZER_ENCODE_EMPTY_ARRAYS
static

◆ DEFAULT_INITIALIZER_ENCODE_INF_AND_NA_N_AS_STRINGS

const bool baljsn::EncoderOptions::DEFAULT_INITIALIZER_ENCODE_INF_AND_NA_N_AS_STRINGS
static

◆ DEFAULT_INITIALIZER_ENCODE_NULL_ELEMENTS

const bool baljsn::EncoderOptions::DEFAULT_INITIALIZER_ENCODE_NULL_ELEMENTS
static

◆ DEFAULT_INITIALIZER_ENCODE_QUOTED_DECIMAL64

const bool baljsn::EncoderOptions::DEFAULT_INITIALIZER_ENCODE_QUOTED_DECIMAL64
static

◆ DEFAULT_INITIALIZER_ENCODING_STYLE

const baljsn::EncodingStyle::Value baljsn::EncoderOptions::DEFAULT_INITIALIZER_ENCODING_STYLE
static

◆ DEFAULT_INITIALIZER_INITIAL_INDENT_LEVEL

const int baljsn::EncoderOptions::DEFAULT_INITIALIZER_INITIAL_INDENT_LEVEL
static

◆ DEFAULT_INITIALIZER_MAX_DOUBLE_PRECISION

const int baljsn::EncoderOptions::DEFAULT_INITIALIZER_MAX_DOUBLE_PRECISION
static

◆ DEFAULT_INITIALIZER_MAX_FLOAT_PRECISION

const int baljsn::EncoderOptions::DEFAULT_INITIALIZER_MAX_FLOAT_PRECISION
static

◆ DEFAULT_INITIALIZER_SPACES_PER_LEVEL

const int baljsn::EncoderOptions::DEFAULT_INITIALIZER_SPACES_PER_LEVEL
static

The documentation for this class was generated from the following file: