<commit_before>// baljsn_encoderoptions.h                                            -*-C++-*-
#ifndef INCLUDED_BALJSN_ENCODEROPTIONS
#define INCLUDED_BALJSN_ENCODEROPTIONS

#ifndef INCLUDED_BSLS_IDENT
#include <bsls_ident.h>
#endif
BSLS_IDENT("$Id: $")

//@PURPOSE: Provide an attribute class for specifying JSON encoding options.
//
//@CLASSES:
//  baljsn::EncoderOptions: options for encoding objects in the JSON format
//
//@SEE_ALSO: baljsn_encoder, baljsn_decoderoptions
//
//@DESCRIPTION: This component provides a single, simply constrained
// (value-semantic) attribute class, 'baljsn::EncoderOptions', that is used to
// specify options for encoding objects in the JSON format.
//
///Attributes
///----------
//..
//  Name                Type           Default         Simple Constraints
//  ------------------  -----------    -------         ------------------
//  encodingStyle       EncodingStyle  BAEJSN_COMPACT  none
//  initialIndentLevel  int            0               >= 0
//  spacesPerLevel      int            0               >= 0
//  encodeEmptyArrays   bool           false           none
//  encodeNullElements  bool           false           none
//  datetimeFractionalSecondPrecision
//                      int            3               >= 0 and <= 6
//..
//: o 'encodingStyle': encoding style used to encode the JSON data.
//:
//: o 'initialIndentLevel': Initial indent level for the topmost element.
//:
//: o 'spacesPerLevel': spaces per additional indent level.
//:
//: o 'encodeEmptyArrays': option specifying if empty arrays should be encoded.
//:
//: o 'encodeNullElements': option specifying if null elements should be
//:                         encoded.
//:
//: o 'datetimeFractionalSecondPrecision': option specifying the number of
//:                                        decimal places used for seconds when
//:                                        encoding 'Datetime' and
//:                                        'DatetimeTz'.
//
///Usage
///-----
// This section illustrates intended use of this component.
//
///Example 1: Creating and Populating an Options Object
/// - - - - - - - - - - - - - - - - - - - - - - - - - -
// This component is designed to be used at a higher level to set the options
// for encoding objects in the JSON format.  This example shows how to create
// and populate an options object.
//
// First, we default-construct a 'baljsn::EncoderOptions' object:
//..
//  const int  INITIAL_INDENT_LEVEL = 1;
//  const int  SPACES_PER_LEVEL     = 4;
//  const bool ENCODE_EMPTY_ARRAYS  = true;
//  const bool ENCODE_NULL_ELEMENTS = true;
//
//  baljsn::EncoderOptions options;
//  assert(0 == options.initialIndentLevel());
//  assert(0 == options.spacesPerLevel());
//  assert(baljsn::EncoderOptions::e_COMPACT == options.encodingStyle());
//  assert(false == options.encodeEmptyArrays());
//  assert(false == options.encodeNullElements());
//..
// Next, we populate that object to encode in a pretty format using a
// pre-defined initial indent level and spaces per level:
//..
//  options.setEncodingStyle(baljsn::EncoderOptions::e_PRETTY);
//  assert(baljsn::EncoderOptions::e_PRETTY == options.encodingStyle());
//
//  options.setInitialIndentLevel(INITIAL_INDENT_LEVEL);
//  assert(INITIAL_INDENT_LEVEL == options.initialIndentLevel());
//
//  options.setSpacesPerLevel(SPACES_PER_LEVEL);
//  assert(SPACES_PER_LEVEL == options.spacesPerLevel());
//
//  options.setEncodeEmptyArrays(ENCODE_EMPTY_ARRAYS);
//  assert(ENCODE_EMPTY_ARRAYS == options.encodeEmptyArrays());
//
//  options.setEncodeNullElements(ENCODE_NULL_ELEMENTS);
//  assert(ENCODE_NULL_ELEMENTS == options.encodeNullElements());
//..

#ifndef INCLUDED_BALSCM_VERSION
#include <balscm_version.h>
#endif

#ifndef INCLUDED_BSLS_ASSERT
#include <bsls_assert.h>
#endif

#ifndef INCLUDED_BSL_IOSFWD
#include <bsl_iosfwd.h>
#define INCLUDED_BSL_IOSFWD
#endif

namespace BloombergLP {
namespace baljsn {

                            // ====================
                            // class EncoderOptions
                            // ====================

class EncoderOptions {
    // This simply constrained (value-semantic) attribute class describes
    // options for encoding an object in the JSON format.  See the Attributes
    // section under @DESCRIPTION in the component-level documentation.  Note
    // that the class invariants are identically the constraints on the
    // individual attributes.
    //
    // This class:
    //: o supports a complete set of *value-semantic* operations
    //:   o except for 'bdex' serialization
    //: o is *exception-safe*
    //: o is *alias-safe*
    //: o is 'const' *thread-safe*
    // For terminology see 'bsldoc_glossary'.

  public:
    // TYPES
    enum EncodingStyle {
        // This 'enum' provides enumerators to specify the encoding styles.

        e_COMPACT = 0,  // compact encoding without any whitespace
        e_PRETTY        // pretty encoding with appropriate indentation
    };

  private:
    // DATA
    int           d_initialIndentLevel;  // initial indentation level

    int           d_spacesPerLevel;      // spaces per level per indent level

    EncodingStyle d_encodingStyle;       // encoding style

    bool          d_encodeEmptyArrays;   // flag specifying if empty arrays
                                         // should be encoded

    bool          d_encodeNullElements;  // flag specifying if null elements
                                         // should be encoded

    int           d_datetimeFractionalSecondPrecision;
                                         // number of decimal places used for
                                         // second in 'Datetime' and
                                         // 'DatetimeTz'

  public:
    // CREATORS
    EncoderOptions();
        // Create a 'EncoderOptions' object having the (default) attribute
        // values:
        //..
        //  encodingStyle      == BAEJSN_COMPACT
        //  initialIndentLevel == 0
        //  spacesPerLevel     == 0
        //  encodeEmptyArrays  == false
        //  encodeNullElements == false
        //..

    //! EncoderOptions(const EncoderOptions& original) = default;
        // Create a 'EncoderOptions' object having the same value as the
        // specified 'original' object.

    ~EncoderOptions();<commit_msg>Adopt commit 547dfbd from master: Merge pull request #592 from che2/update-doc-baljsn_encoderoptions<commit_after>// baljsn_encoderoptions.h                                            -*-C++-*-
#ifndef INCLUDED_BALJSN_ENCODEROPTIONS
#define INCLUDED_BALJSN_ENCODEROPTIONS

#ifndef INCLUDED_BSLS_IDENT
#include <bsls_ident.h>
#endif
BSLS_IDENT("$Id: $")

//@PURPOSE: Provide an attribute class for specifying JSON encoding options.
//
//@CLASSES:
//  baljsn::EncoderOptions: options for encoding objects in the JSON format
//
//@SEE_ALSO: baljsn_encoder, baljsn_decoderoptions
//
//@DESCRIPTION: This component provides a single, simply constrained
// (value-semantic) attribute class, 'baljsn::EncoderOptions', that is used to
// specify options for encoding objects in the JSON format.
//
///Attributes
///----------
//..
//  Name                Type           Default         Simple Constraints
//  ------------------  -----------    -------         ------------------
//  encodingStyle       EncodingStyle  BAEJSN_COMPACT  none
//  initialIndentLevel  int            0               >= 0
//  spacesPerLevel      int            0               >= 0
//  encodeEmptyArrays   bool           false           none
//  encodeNullElements  bool           false           none
//  datetimeFractionalSecondPrecision
//                      int            3               >= 0 and <= 6
//..
//: o 'encodingStyle': encoding style used to encode the JSON data.
//:
//: o 'initialIndentLevel': Initial indent level for the topmost element.
//:
//: o 'spacesPerLevel': spaces per additional indent level.
//:
//: o 'encodeEmptyArrays': option specifying if empty arrays should be encoded.
//:
//: o 'encodeNullElements': option specifying if null elements should be
//:                         encoded.
//:
//: o 'datetimeFractionalSecondPrecision': option specifying the number of
//:                                        decimal places used for seconds when
//:                                        encoding 'Datetime' and
//:                                        'DatetimeTz'.
//
///Usage
///-----
// This section illustrates intended use of this component.
//
///Example 1: Creating and Populating an Options Object
/// - - - - - - - - - - - - - - - - - - - - - - - - - -
// This component is designed to be used at a higher level to set the options
// for encoding objects in the JSON format.  This example shows how to create
// and populate an options object.
//
// First, we default-construct a 'baljsn::EncoderOptions' object:
//..
//  const int  INITIAL_INDENT_LEVEL = 1;
//  const int  SPACES_PER_LEVEL     = 4;
//  const bool ENCODE_EMPTY_ARRAYS  = true;
//  const bool ENCODE_NULL_ELEMENTS = true;
//
//  baljsn::EncoderOptions options;
//  assert(0 == options.initialIndentLevel());
//  assert(0 == options.spacesPerLevel());
//  assert(baljsn::EncoderOptions::e_COMPACT == options.encodingStyle());
//  assert(false == options.encodeEmptyArrays());
//  assert(false == options.encodeNullElements());
//..
// Next, we populate that object to encode in a pretty format using a
// pre-defined initial indent level and spaces per level:
//..
//  options.setEncodingStyle(baljsn::EncoderOptions::e_PRETTY);
//  assert(baljsn::EncoderOptions::e_PRETTY == options.encodingStyle());
//
//  options.setInitialIndentLevel(INITIAL_INDENT_LEVEL);
//  assert(INITIAL_INDENT_LEVEL == options.initialIndentLevel());
//
//  options.setSpacesPerLevel(SPACES_PER_LEVEL);
//  assert(SPACES_PER_LEVEL == options.spacesPerLevel());
//
//  options.setEncodeEmptyArrays(ENCODE_EMPTY_ARRAYS);
//  assert(ENCODE_EMPTY_ARRAYS == options.encodeEmptyArrays());
//
//  options.setEncodeNullElements(ENCODE_NULL_ELEMENTS);
//  assert(ENCODE_NULL_ELEMENTS == options.encodeNullElements());
//..

#ifndef INCLUDED_BALSCM_VERSION
#include <balscm_version.h>
#endif

#ifndef INCLUDED_BSLS_ASSERT
#include <bsls_assert.h>
#endif

#ifndef INCLUDED_BSL_IOSFWD
#include <bsl_iosfwd.h>
#define INCLUDED_BSL_IOSFWD
#endif

namespace BloombergLP {
namespace baljsn {

                            // ====================
                            // class EncoderOptions
                            // ====================

class EncoderOptions {
    // This simply constrained (value-semantic) attribute class describes
    // options for encoding an object in the JSON format.  See the Attributes
    // section under @DESCRIPTION in the component-level documentation.  Note
    // that the class invariants are identically the constraints on the
    // individual attributes.
    //
    // This class:
    //: o supports a complete set of *value-semantic* operations
    //:   o except for 'bdex' serialization
    //: o is *exception-safe*
    //: o is *alias-safe*
    //: o is 'const' *thread-safe*
    // For terminology see 'bsldoc_glossary'.

  public:
    // TYPES
    enum EncodingStyle {
        // This 'enum' provides enumerators to specify the encoding styles.

        e_COMPACT = 0,  // compact encoding without any whitespace
        e_PRETTY        // pretty encoding with appropriate indentation
    };

  private:
    // DATA
    int           d_initialIndentLevel;  // initial indentation level

    int           d_spacesPerLevel;      // spaces per level per indent level

    EncodingStyle d_encodingStyle;       // encoding style

    bool          d_encodeEmptyArrays;   // flag specifying if empty arrays
                                         // should be encoded

    bool          d_encodeNullElements;  // flag specifying if null elements
                                         // should be encoded

    int           d_datetimeFractionalSecondPrecision;
                                         // number of decimal places used for
                                         // second in 'Datetime' and
                                         // 'DatetimeTz'

  public:
    // CREATORS
    EncoderOptions();
        // Create a 'EncoderOptions' object having the (default) attribute
        // values:
        //..
        //  encodingStyle                     == BAEJSN_COMPACT
        //  initialIndentLevel                == 0
        //  spacesPerLevel                    == 0
        //  encodeEmptyArrays                 == false
        //  datetimeFractionalSecondPrecision == 3
        //  encodeNullElements                == false
        //..

    //! EncoderOptions(const EncoderOptions& original) = default;
        // Create a 'EncoderOptions' object having the same value as the
        // specified 'original' object.

    ~EncoderOptions();
{'fraction_non_alphanumeric': 0.11825292341051653, 'fraction_numerical': 0.002942770851080307, 'mean_word_length': 1.9565018315018314, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4320242', 'n_tokens_mistral': 3507, 'n_tokens_neox': 3395, 'n_words': 985}