My Project
|
a simple class for creating NPL script code, especially data table code. More...
#include <NPLInterface.hpp>
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={};" | |
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);
NPLInterface::CNPLWriterT< StringBufferType >::CNPLWriterT | ( | int | nReservedSize = -1 | ) |
the internal buffer reserved size.
char * NPLInterface::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.
nSize | size in bytes. |
|
inline |
get the current NPL code.
void NPLInterface::CNPLWriterT< StringBufferType >::WriteName | ( | const char * | name, |
bool | bUseBrackets = false |
||
) |
write a parameter name
bUseBrackets | if false, one has to make sure that the name is a valid NPL name string, without special characters. |
void NPLInterface::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.
void NPLInterface::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.