Quick Links:

bal | bbl | bdl | bsl

Public Member Functions

baljsn::Encoder Class Reference

#include <baljsn_encoder.h>

List of all members.

Public Member Functions

 Encoder (bslma::Allocator *basicAllocator=0)
 ~Encoder ()
template<class TYPE >
int encode (bsl::streambuf *streamBuf, const TYPE &value, const EncoderOptions &options)
template<class TYPE >
int encode (bsl::streambuf *streamBuf, const TYPE &value, const EncoderOptions *options)
template<class TYPE >
int encode (bsl::ostream &stream, const TYPE &value, const EncoderOptions &options)
template<class TYPE >
int encode (bsl::ostream &stream, const TYPE &value, const EncoderOptions *options)
template<class TYPE >
int encode (bsl::streambuf *streamBuf, const TYPE &value)
template<class TYPE >
int encode (bsl::ostream &stream, const TYPE &value)
bsl::string loggedMessages () const

Detailed Description

This class provides a mechanism for encoding value-semantic objects in the JSON format. The encode methods are function templates that will encode any object that meets the requirements of a sequence, choice, or array object as defined in the bdlat_sequencefunctions, bdlat_choicefunctions, and bdlat_choicefunctions components respectively. These generic frameworks provide a common compile-time interface for accessing struct-like and union-like objects. In particular, the types generated by bas_codegen.pl provide the necessary interface and can be encoded using this component.

See Component baljsn_encoder


Constructor & Destructor Documentation

baljsn::Encoder::Encoder ( bslma::Allocator basicAllocator = 0  )  [explicit]

Create a encoder object. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

baljsn::Encoder::~Encoder (  ) 

Destroy this object.


Member Function Documentation

template<class TYPE >
int baljsn::Encoder::encode ( bsl::streambuf *  streamBuf,
const TYPE &  value,
const EncoderOptions options 
)
template<class TYPE >
int baljsn::Encoder::encode ( bsl::streambuf *  streamBuf,
const TYPE &  value,
const EncoderOptions options 
)

Encode the specified value, of (template parameter) TYPE, in the JSON format using the specified options and output it onto the specified streamBuf. Specifying a nullptr options is equivalent to passing a default-constructed DecoderOptions in options. TYPE shall be a bdlat-compatible sequence, choice, or array type, or a bdlat-compatible dynamic type referring to one of those types. Return 0 on success, and a non-zero value otherwise.

template<class TYPE >
int baljsn::Encoder::encode ( bsl::ostream &  stream,
const TYPE &  value,
const EncoderOptions options 
)
template<class TYPE >
int baljsn::Encoder::encode ( bsl::ostream &  stream,
const TYPE &  value,
const EncoderOptions options 
)

Encode the specified value, of (template parameter) TYPE, in the JSON format using the specified options and output it onto the specified stream. Specifying a nullptr options is equivalent to passing a default-constructed DecoderOptions in options. TYPE shall be a bdlat-compatible choice, or array type, or a bdlat-compatible dynamic type referring to one of those types. Return 0 on success, and a non-zero value otherwise.

template<class TYPE >
int baljsn::Encoder::encode ( bsl::streambuf *  streamBuf,
const TYPE &  value 
)

Encode the specified value of (template parameter) TYPE into the specified streamBuf. Return 0 on success, and a non-zero value otherwise.

DEPRECATED: Use the encode function passed a reference to a non-modifiable EncoderOptions object instead.

template<class TYPE >
int baljsn::Encoder::encode ( bsl::ostream &  stream,
const TYPE &  value 
)

Encode the specified value of (template parameter) TYPE into the specified stream. Return 0 on success, and a non-zero value otherwise. Note that stream will be invalidated if the encoding failed.

DEPRECATED: Use the encode function passed a reference to a non-modifiable EncoderOptions object instead.

bsl::string baljsn::Encoder::loggedMessages (  )  const

Return a string containing any error, warning, or trace messages that were logged during the last call to the encode method. The log is reset each time encode is called.


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