My Project
Public Types | Public Member Functions | Static Public Member Functions | List of all members
NPL::CNPLWriterT< StringBufferType > Class Template Reference

a simple class for creating NPL script code, especially data table code. More...

#include <NPLWriter.h>

Public Types

typedef StringBufferType Buffer_Type
 

Public Member Functions

 CNPLWriterT (int nReservedSize=-1)
 the internal buffer reserved size. More...
 
 CNPLWriterT (Buffer_Type &buff_, int nReservedSize=-1)
 into which buff_ to write the
 
void Reset (int nReservedSize=-1)
 reset the writer
 
void BeginTable ()
 write begin table "{"
 
void WriteName (const char *name, bool bUseBrackets=false)
 write a parameter name More...
 
void WriteValue (const char *value, bool bInQuotation=true)
 if bInQuotation is true, it writes a parameter text value. More...
 
void WriteValue (const char *buffer, int nSize, bool bInQuotation=true)
 if bInQuotation is true, it writes a parameter text value. More...
 
void WriteValue (const string &sStr, bool bInQuotation=true)
 
void WriteValue (double value)
 write a parameter value
 
void WriteNil ()
 write a parameter nil
 
void EndTable ()
 write end table "}"
 
void Append (const char *text)
 append any text
 
void Append (const char *pData, int nSize)
 
void Append (const string &sText)
 
char * AddMemBlock (int nSize)
 add a mem block of size nSize and return the address of the block. More...
 
void WriteParamDelimiter ()
 write ";"
 
const Buffer_Type & ToString ()
 get the current NPL code. More...
 

Static Public Member Functions

static const Buffer_Type & GetNilMessage ()
 return "msg=nil;"
 
static const Buffer_Type & GetEmptyMessage ()
 return "msg={};"
 

Detailed Description

template<typename StringBufferType>
class NPL::CNPLWriterT< StringBufferType >

a simple class for creating NPL script code, especially data table code.

this class is reentrant (thread-safe). Please note that this class does not ensure that the code is a pure table. See Example: to generate the string : msg={name=1,2,{"3"="4",},}; CNPLWriter writer; // if you can estimate the buffer size, use CNPLWriter writer(nReservedSize) writer.WriteName("msg"); writer.BeginTable(); writer.WriteName("name"); writer.WriteValue(1); writer.WriteValue(2); writer.BeginTable(); writer.WriteName("3", true); writer.WriteValue("4"); writer.EndTable(); writer.EndTable(); writer.WriteParamDelimiter(); log(writer.ToString().c_str());

One can also provide their own string buffer to write to, like below. std::string buff; buff.reserve(100); CNPLWriter writer(buff);

Constructor & Destructor Documentation

§ CNPLWriterT()

template<typename StringBufferType >
NPL::CNPLWriterT< StringBufferType >::CNPLWriterT ( int  nReservedSize = -1)

the internal buffer reserved size.

Member Function Documentation

§ AddMemBlock()

template<typename StringBufferType >
char * NPL::CNPLWriterT< StringBufferType >::AddMemBlock ( int  nSize)

add a mem block of size nSize and return the address of the block.

we may fill the block at a latter time.

Parameters
nSizesize in bytes.

§ ToString()

template<typename StringBufferType >
const Buffer_Type& NPL::CNPLWriterT< StringBufferType >::ToString ( )
inline

get the current NPL code.

§ WriteName()

template<typename StringBufferType >
void NPL::CNPLWriterT< StringBufferType >::WriteName ( const char *  name,
bool  bUseBrackets = false 
)

write a parameter name

Parameters
bUseBracketsif false, one has to make sure that the name is a valid NPL name string, without special characters.

§ WriteValue() [1/2]

template<typename StringBufferType >
void NPL::CNPLWriterT< StringBufferType >::WriteValue ( const char *  value,
bool  bInQuotation = true 
)

if bInQuotation is true, it writes a parameter text value.

Otherwise it will just append the value without encoding it with quatation marks.

§ WriteValue() [2/2]

template<typename StringBufferType >
void NPL::CNPLWriterT< StringBufferType >::WriteValue ( const char *  buffer,
int  nSize,
bool  bInQuotation = true 
)

if bInQuotation is true, it writes a parameter text value.

Otherwise it will just append the value without encoding it with quatation marks.


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