Atrinik Server  4.0
Typedefs | Enumerations | Functions | Variables
attr_list.c File Reference
#include <plugin_python.h>
#include <plugin.h>
#include <toolkit/packet.h>
#include <player.h>

Go to the source code of this file.

Typedefs

typedef enum attr_list_oper attr_list_oper_t
 

Enumerations

enum  attr_list_oper {
  AL_OPER_SET, AL_OPER_GET, AL_OPER_REMOVE, AL_OPER_APPEND,
  AL_OPER_CONTAINS, AL_OPER_CLEAR, AL_OPER_ITEMS, AL_OPER_ITER,
  AL_OPER_DELETE
}
 

Functions

static Py_ssize_t attr_list_len (Atrinik_AttrList *al)
 
static bool attr_list_oper_cmd_permissions (Atrinik_AttrList *al, attr_list_oper_t oper, PyObject *key, PyObject **value)
 
static bool attr_list_oper_factions (Atrinik_AttrList *al, attr_list_oper_t oper, PyObject *key, PyObject **value)
 
static bool attr_list_oper_packets (Atrinik_AttrList *al, attr_list_oper_t oper, PyObject *key, PyObject **value)
 
static bool attr_list_oper (Atrinik_AttrList *al, attr_list_oper_t oper, PyObject *key, PyObject **value)
 
static PyObject * append (Atrinik_AttrList *al, PyObject *value)
 
static PyObject * attr_list_remove (Atrinik_AttrList *al, PyObject *value)
 
static PyObject * attr_list_clear (Atrinik_AttrList *al)
 
static PyObject * attr_list_items (Atrinik_AttrList *al)
 
static PyObject * iter (PyObject *seq)
 
static PyObject * iternext (Atrinik_AttrList *al)
 
static Py_ssize_t __len__ (Atrinik_AttrList *al)
 
static PyObject * __getitem__ (Atrinik_AttrList *al, PyObject *key)
 
static int __setitem__ (Atrinik_AttrList *al, PyObject *key, PyObject *value)
 
static int __contains__ (Atrinik_AttrList *al, PyObject *value)
 
int Atrinik_AttrList_init (PyObject *module)
 
PyObject * wrap_attr_list (void *ptr, size_t offset, field_type field)
 

Variables

static PyMethodDef methods []
 
static PySequenceMethods SequenceMethods
 
static PyMappingMethods MappingMethods
 
PyTypeObject Atrinik_AttrListType
 

Detailed Description

Implements AttrList Python object; this is a class similar to Python lists/dictionaries, but with more limited functionality (it does not implement many methods normal lists do; however, the AttrList object can be converted to a list).

These objects are used to wrap an array of data, for example, player::cmd_permissions array, which holds the command permissions the player has access to. When Python requests to get player.cmd_permissions, the code generates an AttrList object, which "wraps" the actual array of command permissions - it holds a pointer to the structure, the offset in the structure, etc. Thus, it is possible for Python to use setitem() and getitem() methods on this AttrList object to change/extract the array data in the most efficient way possible; all of the data of the array is never held in memory (unless you implicitly convert it to a list, of course).

The code uses many castings and performs exhaustive error checking of passed arguments, as the smallest imperfection could cause a memory corruption, most likely resulting in a crash.

Author
Alex Tokar

Definition in file attr_list.c.

Typedef Documentation

Operations supported by attr_list_oper().

Enumeration Type Documentation

Operations supported by attr_list_oper().

Enumerator
AL_OPER_SET 

setitem()

AL_OPER_GET 

getitem()

AL_OPER_REMOVE 

remove()

AL_OPER_CONTAINS 

contains()

AL_OPER_CLEAR 

clear()

AL_OPER_ITEMS 

items()

AL_OPER_ITER 

iter()

AL_OPER_DELETE 

del()

Definition at line 58 of file attr_list.c.

Function Documentation

static int __contains__ ( Atrinik_AttrList al,
PyObject *  value 
)
static

Implements the contains() method for attribute list.

Parameters
alAttrList instance.
valueValue to find.
Returns
1 if the value is in the attribute list, 0 otherwise.

Definition at line 713 of file attr_list.c.

static PyObject* __getitem__ ( Atrinik_AttrList al,
PyObject *  key 
)
static

Implements the getitem() method.

Parameters
alAttrList instance.
keyIndex to try and find.
Returns
The object from the AttrList at the specified index, NULL on failure.

Definition at line 676 of file attr_list.c.

static Py_ssize_t __len__ ( Atrinik_AttrList al)
static

Implements the len() method.

Parameters
alAttrList instance.
Returns
Length of the attribute list.

Definition at line 661 of file attr_list.c.

static int __setitem__ ( Atrinik_AttrList al,
PyObject *  key,
PyObject *  value 
)
static

Implements the setitem() method.

Parameters
alAttrList instance.
keyKey/index.
valueValue to set.
Returns
0 on success, -1 on failure.

Definition at line 694 of file attr_list.c.

static PyObject* append ( Atrinik_AttrList al,
PyObject *  value 
)
static

Implements the append() method.

Parameters
alThe AttrList object.
valueValue to append.
Returns
None.

Definition at line 547 of file attr_list.c.

int Atrinik_AttrList_init ( PyObject *  module)

Initializes the AttrList module.

Parameters
moduleThe main Atrinik module.
Returns
1 on success, 0 on failure.

Definition at line 784 of file attr_list.c.

static PyObject* attr_list_clear ( Atrinik_AttrList al)
static

Implements the clear() method.

Parameters
alThe AttrList object.
Returns
None.

Definition at line 583 of file attr_list.c.

static PyObject* attr_list_items ( Atrinik_AttrList al)
static

Implements the items() method.

Parameters
alThe AttrList object.
Returns
List of the items in the AttrList.

Definition at line 600 of file attr_list.c.

static Py_ssize_t attr_list_len ( Atrinik_AttrList al)
static

Calculate length of the specified AttrList instance.

Parameters
alAttrList being used.
Returns
The length of the provided AttrList.

Definition at line 77 of file attr_list.c.

static bool attr_list_oper ( Atrinik_AttrList al,
attr_list_oper_t  oper,
PyObject *  key,
PyObject **  value 
)
static

Perform specified operation on the attribute list.

Parameters
alThe attribute list.
operOperation to perform.
keyKey.
valueValue.
Returns
True on success, false on failure.

Definition at line 519 of file attr_list.c.

static bool attr_list_oper_cmd_permissions ( Atrinik_AttrList al,
attr_list_oper_t  oper,
PyObject *  key,
PyObject **  value 
)
static

Perform specified operation on a command permissions attribute list.

Parameters
alThe attribute list.
operOperation to perform.
keyKey.
valueValue.
Returns
True on success, false on failure.

Definition at line 113 of file attr_list.c.

static bool attr_list_oper_factions ( Atrinik_AttrList al,
attr_list_oper_t  oper,
PyObject *  key,
PyObject **  value 
)
static

Perform specified operation on a factions attribute list.

Parameters
alThe attribute list.
operOperation to perform.
keyKey.
valueValue.
Returns
True on success, false on failure.

Definition at line 247 of file attr_list.c.

static bool attr_list_oper_packets ( Atrinik_AttrList al,
attr_list_oper_t  oper,
PyObject *  key,
PyObject **  value 
)
static

Perform specified operation on a packets attribute list.

Parameters
alThe attribute list.
operOperation to perform.
keyKey.
valueValue.
Returns
True on success, false on failure.

Definition at line 398 of file attr_list.c.

static PyObject* attr_list_remove ( Atrinik_AttrList al,
PyObject *  value 
)
static

Implements the remove() method.

Parameters
alThe AttrList object.
valueValue to remove.
Returns
None.

Definition at line 566 of file attr_list.c.

static PyObject* iter ( PyObject *  seq)
static

Start iterating.

Parameters
seqWhat to iterate through.
Returns
New iteration object.

Definition at line 626 of file attr_list.c.

static PyObject* iternext ( Atrinik_AttrList al)
static

Keep iterating over an iteration object.

Parameters
alThe iteration object.
Returns
Next object from attribute list, NULL if the end was reached.

Definition at line 647 of file attr_list.c.

PyObject* wrap_attr_list ( void *  ptr,
size_t  offset,
field_type  field 
)

Creates a new AttrList wrapping an array.

Parameters
ptrPointer to the structure the array is in.
offsetWhere the array is in the structure.
fieldType of the array being handled; for example, FIELDTYPE_FACTIONS.
Returns
The new wrapper object.

Definition at line 810 of file attr_list.c.

Variable Documentation

PyTypeObject Atrinik_AttrListType

AttrListType definition.

Definition at line 737 of file attr_list.c.

PyMappingMethods MappingMethods
static
Initial value:
= {
(lenfunc) __len__,
(binaryfunc) __getitem__,
(objobjargproc) __setitem__,
}
static int __setitem__(Atrinik_AttrList *al, PyObject *key, PyObject *value)
Definition: attr_list.c:694
static Py_ssize_t __len__(Atrinik_AttrList *al)
Definition: attr_list.c:661
static PyObject * __getitem__(Atrinik_AttrList *al, PyObject *key)
Definition: attr_list.c:676

Defines what to map some common methods (len(), setitem() and getitem()) to.

Definition at line 730 of file attr_list.c.

PyMethodDef methods[]
static
Initial value:
= {
{"append", (PyCFunction) append, METH_O, 0},
{"remove", (PyCFunction) attr_list_remove, METH_O, 0},
{"clear", (PyCFunction) attr_list_clear, METH_NOARGS, 0},
{"items", (PyCFunction) attr_list_items, METH_NOARGS, 0},
{NULL, NULL, 0, 0}
}
static PyObject * append(Atrinik_AttrList *al, PyObject *value)
Definition: attr_list.c:547
static PyObject * attr_list_remove(Atrinik_AttrList *al, PyObject *value)
Definition: attr_list.c:566
static PyObject * attr_list_clear(Atrinik_AttrList *al)
Definition: attr_list.c:583
static PyObject * attr_list_items(Atrinik_AttrList *al)
Definition: attr_list.c:600

Available Python methods for the AtrinikAttrList type.

Definition at line 611 of file attr_list.c.

PySequenceMethods SequenceMethods
static
Initial value:
= {
(lenfunc) __len__,
NULL, NULL, NULL, NULL, NULL, NULL,
(objobjproc) __contains__,
NULL, NULL
}
static int __contains__(Atrinik_AttrList *al, PyObject *value)
Definition: attr_list.c:713
static Py_ssize_t __len__(Atrinik_AttrList *al)
Definition: attr_list.c:661

Common sequence methods.

Definition at line 719 of file attr_list.c.