DCMTK  Version 3.6.1 20170228
OFFIS DICOM Toolkit
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | List of all members
DcmJsonFormat Class Referenceabstract

Class for handling JSON format options. More...

+ Inheritance diagram for DcmJsonFormat:

Classes

class  Indention
 A class to create small proxy objects that ease indention handling. More...
 

Public Member Functions

 DcmJsonFormat (const OFBool printMetaheaderInformation)
 Constructor. More...
 
virtual OFString newline ()=0
 Method to return line break(s) More...
 
virtual OFString space ()=0
 Method to return whitespace(s) More...
 
Indention indent ()
 Method to return an indention proxy object for increasing, decreasing or printing indention. More...
 
virtual OFBool asBulkDataURI (const DcmTagKey &tag, OFString &uri)
 Check if an attribute should be exported as BulkDataURI. More...
 
virtual void printValuePrefix (STD_NAMESPACE ostream &out)
 Print the Prefix which for JSON Values needed with indention and newlines as in the format Variable given. More...
 
virtual void printValueSuffix (STD_NAMESPACE ostream &out)
 Print the Suffix which for JSON Values needed with indention and newlines as in the format Variable given. More...
 
virtual void printBulkDataURIPrefix (STD_NAMESPACE ostream &out)
 Print the Prefix which for JSON BulkDataURI needed with indention and newlines as in the format Variable given. More...
 
virtual void printInlineBinaryPrefix (STD_NAMESPACE ostream &out)
 Print the Prefix which for JSON InlineBinary needed with indention and newlines as the format specifies. More...
 
virtual void printNextArrayElementPrefix (STD_NAMESPACE ostream &out)
 Print the prefix for array elements (except the first one), with indention and newlines as the format specifies. More...
 

Static Public Member Functions

static void escapeControlCharacters (STD_NAMESPACE ostream &out, OFString const &value)
 Escapes all forbidden control characters in JSON. More...
 
static void normalizeDecimalString (OFString &value)
 Normalize Decimal String to specific JSON format. More...
 
static void normalizeIntegerString (OFString &value)
 Normalize Integer String to specific JSON format. More...
 
static void printString (STD_NAMESPACE ostream &out, const OFString &value)
 Prints either null if empty or the string value (with all illegal characters escaped). More...
 
static void printValueString (STD_NAMESPACE ostream &out, const OFString &value)
 Prints either null if empty or a quoted string (with leading and ending quotation marks and all illegal characters escaped). More...
 
static void printNumberInteger (STD_NAMESPACE ostream &out, OFString &value)
 Print either null if empty or a Number as normelized IntegerString. More...
 
static void printNumberDecimal (STD_NAMESPACE ostream &out, OFString &value)
 Print either null if empty or a Number as normelized IntegerDecimal. More...
 

Public Attributes

const OFBool printMetaheaderInformation
 Option that defines if metaheader information should be printed.
 

Protected Member Functions

virtual void printIndention (STD_NAMESPACE ostream &out)=0
 Indent to the specific level. More...
 
virtual void increaseIndention ()=0
 Used for increasing the indention level.
 
virtual void decreaseIndention ()=0
 Used for decreasing the indention level.
 

Detailed Description

Class for handling JSON format options.

Base class to implement custom formatting. Purpose:

Usage Example:

#include "dcmtk/dcmdata/dcjson.h"
// ...
DcmFileFormat fileformat;
if(fileformat.loadFile("test.dcm").good())
{
// print the DICOM file in JSON format
// using the pretty format (muti-line with indention and other whitespace)
fileformat.writeJson(COUT, DcmJsonFormatPretty(OFTrue));
// using the compact (single line, without unneeded whitespace) format
fileformat.writeJson(COUT, DcmJsonFormatCompact(OFTrue));
}

Implementing a custom formatter:

struct CustomJsonFormat : DcmJsonFormatPretty
{
CustomJsonFormat(const OFBool printMetaheaderInformation = OFTrue)
{
}
OFString OFJsonFormatExample::space()
{
// use tabstops instead of spaces for indention
return "\t";
}
}

Constructor & Destructor Documentation

DcmJsonFormat::DcmJsonFormat ( const OFBool  printMetaheaderInformation)
inline

Constructor.

Parameters
printMetaheaderInformationparameter that defines if meta information should be written

Member Function Documentation

virtual OFBool DcmJsonFormat::asBulkDataURI ( const DcmTagKey tag,
OFString uri 
)
virtual

Check if an attribute should be exported as BulkDataURI.

Override this function to implement bulk data URI output.

Parameters
tagthe tag of the attribute being printed, for letting the implementation decide how to handle it.
urithe resulting URI to output.
Returns
OFTrue if yes, OFFalse if no.

Usage Example:

struct BulkDataURIJsonFormat : DcmJsonFormatPretty
{
CustomJsonFormat(const OFBool printMetaheaderInformation = OFTrue,
... bulkDataURIDatabase)
, TheDatabase(bulkDataURIDatabase)
{
}
virtual OFBool asBulkDataURI(const DcmTagKey& tag, OFString& uri)
{
... result = TheDatabase.findBulkDataFor(tag);
if (result.found())
{
uri = result.uri();
return OFTrue;
}
return OFFalse;
}
... TheDatabase;
}
static void DcmJsonFormat::escapeControlCharacters ( STD_NAMESPACE ostream &  out,
OFString const &  value 
)
static

Escapes all forbidden control characters in JSON.

Parameters
outoutput stream to which the escaped String is written
valueString that should be escaped
Indention DcmJsonFormat::indent ( )
inline

Method to return an indention proxy object for increasing, decreasing or printing indention.

Returns
an indention proxy object.
virtual OFString DcmJsonFormat::newline ( )
pure virtual

Method to return line break(s)

Returns
line break(s).

Implemented in DcmJsonFormatCompact, and DcmJsonFormatPretty.

static void DcmJsonFormat::normalizeDecimalString ( OFString value)
static

Normalize Decimal String to specific JSON format.

remove leading zeros, except before dot. Example:

00.123 --> 0.123
023.12 --> 23.12
-01.00 --> -1.00
0200 --> 200
.12 --> 0.12
000.1 --> 0.1
Parameters
valueString that should be normalize
static void DcmJsonFormat::normalizeIntegerString ( OFString value)
static

Normalize Integer String to specific JSON format.

remove leading zeros, except before dot. Example:

000 --> 0
023 --> 23
-01 --> -1
0200 --> 200
Parameters
valueString that should be normalize
virtual void DcmJsonFormat::printBulkDataURIPrefix ( STD_NAMESPACE ostream &  out)
virtual

Print the Prefix which for JSON BulkDataURI needed with indention and newlines as in the format Variable given.

Example:

,"BulkDataURI":
Parameters
outoutput stream to which the Value prefix is written
virtual void DcmJsonFormat::printIndention ( STD_NAMESPACE ostream &  out)
protectedpure virtual

Indent to the specific level.

Parameters
outoutput stream to which the indention is written.

Implemented in DcmJsonFormatCompact, and DcmJsonFormatPretty.

virtual void DcmJsonFormat::printInlineBinaryPrefix ( STD_NAMESPACE ostream &  out)
virtual

Print the Prefix which for JSON InlineBinary needed with indention and newlines as the format specifies.

Example:

,"InlineBinary":
Parameters
outoutput stream to which the Value prefix is written
virtual void DcmJsonFormat::printNextArrayElementPrefix ( STD_NAMESPACE ostream &  out)
virtual

Print the prefix for array elements (except the first one), with indention and newlines as the format specifies.

Example:

Example,\n
Example...
Parameters
outoutput stream to which the Value prefix is written
static void DcmJsonFormat::printNumberDecimal ( STD_NAMESPACE ostream &  out,
OFString value 
)
static

Print either null if empty or a Number as normelized IntegerDecimal.

Parameters
outoutput stream to which the Value prefix is written
valueString that should be printed
static void DcmJsonFormat::printNumberInteger ( STD_NAMESPACE ostream &  out,
OFString value 
)
static

Print either null if empty or a Number as normelized IntegerString.

Parameters
outoutput stream to which the Value prefix is written
valueString that should be printed
static void DcmJsonFormat::printString ( STD_NAMESPACE ostream &  out,
const OFString value 
)
static

Prints either null if empty or the string value (with all illegal characters escaped).

Parameters
outoutput stream to which the Value prefix is written
valueString that should be printed
virtual void DcmJsonFormat::printValuePrefix ( STD_NAMESPACE ostream &  out)
virtual

Print the Prefix which for JSON Values needed with indention and newlines as in the format Variable given.

Example:

,"Value":[
Parameters
outoutput stream to which the Value prefix is written
static void DcmJsonFormat::printValueString ( STD_NAMESPACE ostream &  out,
const OFString value 
)
static

Prints either null if empty or a quoted string (with leading and ending quotation marks and all illegal characters escaped).

Parameters
outoutput stream to which the Value prefix is written
valueString that should be printed
virtual void DcmJsonFormat::printValueSuffix ( STD_NAMESPACE ostream &  out)
virtual

Print the Suffix which for JSON Values needed with indention and newlines as in the format Variable given.

Example:

]\n
Parameters
outoutput stream to which the Value prefix is written
virtual OFString DcmJsonFormat::space ( )
pure virtual

Method to return whitespace(s)

Returns
whitespace(s).

Implemented in DcmJsonFormatCompact, and DcmJsonFormatPretty.


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


Generated on Tue Feb 28 2017 for DCMTK Version 3.6.1 20170228 by Doxygen 1.8.8