My Project
Public Member Functions | List of all members
NPL::NPLTable Class Reference

this is a pure c++ implementation of lua table. More...

#include <NPLTable.h>

Inheritance diagram for NPL::NPLTable:
NPL::NPLObjectBase ParaEngine::intrusive_ptr_single_thread_base

Public Member Functions

 NPLTable ()
 this is an empty table
 
void ToString (std::string &str)
 output table to serialized string. More...
 
void Clear ()
 clear the table object
 
void SetField (const string &sName, const NPLObjectProxy &pObject)
 Set the field. More...
 
void SetField (int nIndex, const NPLObjectProxy &pObject)
 
NPLObjectProxy GetField (const string &sName)
 get a field. More...
 
NPLObjectProxy GetField (int nIndex)
 
NPLObjectProxyCreateGetField (const string &sName)
 create or get a field. More...
 
NPLObjectProxyCreateGetField (int nIndex)
 
Iterator_Type begin ()
 
Iterator_Type end ()
 
IndexIterator_Type index_begin ()
 
IndexIterator_Type index_end ()
 
NPLObjectProxyoperator[] (const string &sName)
 this will create get field. More...
 
NPLObjectProxyoperator[] (const char *sName)
 
NPLObjectProxyoperator[] (int nIndex)
 
- Public Member Functions inherited from NPL::NPLObjectBase
NPLObjectType GetType ()
 
bool isTable ()
 
bool isNumber ()
 
bool isString ()
 
bool isNil ()
 
bool isBool ()
 

Additional Inherited Members

- Public Types inherited from NPL::NPLObjectBase
enum  NPLObjectType {
  NPLObjectType_Nil, NPLObjectType_Table, NPLObjectType_Number, NPLObjectType_String,
  NPLObjectType_Bool
}
 
typedef std::map< std::string, NPLObjectProxyTableFieldMap_Type
 
typedef std::map< int, NPLObjectProxyTableIntFieldMap_Type
 
typedef TableFieldMap_Type::iterator Iterator_Type
 
typedef TableIntFieldMap_Type::iterator IndexIterator_Type
 
- Public Attributes inherited from ParaEngine::intrusive_ptr_single_thread_base
long m_ref_count
 
- Protected Member Functions inherited from ParaEngine::intrusive_ptr_single_thread_base
 intrusive_ptr_single_thread_base (const intrusive_ptr_single_thread_base &)
 
intrusive_ptr_single_thread_baseoperator= (const intrusive_ptr_single_thread_base &)
 
- Protected Attributes inherited from NPL::NPLObjectBase
NPLObjectType m_type
 

Detailed Description

this is a pure c++ implementation of lua table.

it can convert back and force from string. only data members are supported. This class is mostly used by C++ plugin modules.

Remarks
: Use NPLObjectProxy instead of this class. Example: Example 1: Create NPLTable and serialize to string NPL::NPLObjectProxy msg; msg["nid"] = (double)10; msg["name"] = "value"; msg["tab"]["name1"] = "value1"; NPL::NPLHelper::SerializeNPLTableToString(NULL, msg, strOutput);

Example 2: deserialize NPLTable from string.

NPL::NPLObjectProxy tabMsg = NPL::NPLHelper::StringToNPLTable("{nid=10, name=\"value\", tab={name1=\"value1\"}}");
PE_ASSERT((double)tabMsg["nid"] == 10);
PE_ASSERT((tabMsg["name"]) == "value");
PE_ASSERT((tabMsg["tab"]["name1"]) == "value1");

  @note: no cyclic link is allowed. 

Member Function Documentation

§ CreateGetField()

NPLObjectProxy & NPLTable::CreateGetField ( const string &  sName)

create or get a field.

It may return null proxy

§ GetField()

NPLObjectProxy NPLTable::GetField ( const string &  sName)

get a field.

It may return null if not found.

§ operator[]()

NPLObjectProxy& NPL::NPLTable::operator[] ( const string &  sName)
inline

this will create get field.

§ SetField()

void NPLTable::SetField ( const string &  sName,
const NPLObjectProxy pObject 
)

Set the field.

Parameters
sNamethe field name
pObjectif NULL, it will remove the field, as if nil in lua.

§ ToString()

void NPLTable::ToString ( std::string &  str)

output table to serialized string.


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