Changeset 62

Show
Ignore:
Timestamp:
02/12/04 19:45:01 (4 years ago)
Author:
ug
Message:

Create encoding property for class Cursor

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 05/devel/sgfpars.cc

    r42 r62  
    2222 
    2323 
    24 #include <cstring> 
     24 
    2525#include "sgfpars.h" 
    26  
     26// #include <cstring> 
    2727 
    2828intN::intN(int i, intN* p) {  
     
    319319  currentN = root->next; 
    320320  setFlags();        
     321 
     322  if (!currentN->parsed) currentN->parseNode(); 
     323 
     324  PyObject* val = PyDict_GetItemString(currentN->data, "CA"); 
     325  PyObject* v = 0; 
     326 
     327  if (PyList_Check(val) && PyList_Size(val)) v = PyList_GetItem(val, 0);  
     328 
     329  if (v and PyString_Check(v)) { 
     330    char* s = PyString_AsString(v); 
     331    encoding = new char[strlen(s)+1]; 
     332    strcpy(encoding, s); 
     333  } 
     334  else { 
     335    encoding = new char[1]; 
     336    encoding[0] = 0; 
     337  } 
    321338} 
    322339 
     
    325342Cursor::~Cursor() { 
    326343  deltree(root); 
     344  delete [] encoding; 
    327345} 
    328346 
  • 05/devel/sgfpars.h

    r42 r62  
    6767  int posy; 
    6868 
     69  char* encoding; 
     70 
    6971  int noChildren(); 
    7072  PyObject* currentNode(); 
  • 05/devel/sgfpars.py

    r40 r62  
    144144    __swig_getmethods__["posy"] = _sgfpars.Cursor_posy_get 
    145145    if _newclass:posy = property(_sgfpars.Cursor_posy_get,_sgfpars.Cursor_posy_set) 
     146    __swig_setmethods__["encoding"] = _sgfpars.Cursor_encoding_set 
     147    __swig_getmethods__["encoding"] = _sgfpars.Cursor_encoding_get 
     148    if _newclass:encoding = property(_sgfpars.Cursor_encoding_get,_sgfpars.Cursor_encoding_set) 
    146149    def noChildren(*args): return apply(_sgfpars.Cursor_noChildren,args) 
    147150    def currentNode(*args): return apply(_sgfpars.Cursor_currentNode,args) 
  • 05/devel/sgfpars_wrap.cxx

    r40 r62  
    16261626     
    16271627    resultobj = PyInt_FromLong((long)result); 
     1628    return resultobj; 
     1629    fail: 
     1630    return NULL; 
     1631} 
     1632 
     1633 
     1634static PyObject *_wrap_Cursor_encoding_set(PyObject *self, PyObject *args) { 
     1635    PyObject *resultobj; 
     1636    Cursor *arg1 = (Cursor *) 0 ; 
     1637    char *arg2 ; 
     1638    PyObject * obj0 = 0 ; 
     1639     
     1640    if(!PyArg_ParseTuple(args,(char *)"Os:Cursor_encoding_set",&obj0,&arg2)) goto fail; 
     1641    if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_Cursor,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; 
     1642    { 
     1643        if (arg1->encoding) delete [] arg1->encoding; 
     1644        if (arg2) { 
     1645            arg1->encoding = (char *) (new char[strlen(arg2)+1]); 
     1646            strcpy((char *) arg1->encoding,arg2); 
     1647        }else { 
     1648            arg1->encoding = 0; 
     1649        } 
     1650    } 
     1651    Py_INCREF(Py_None); resultobj = Py_None; 
     1652    return resultobj; 
     1653    fail: 
     1654    return NULL; 
     1655} 
     1656 
     1657 
     1658static PyObject *_wrap_Cursor_encoding_get(PyObject *self, PyObject *args) { 
     1659    PyObject *resultobj; 
     1660    Cursor *arg1 = (Cursor *) 0 ; 
     1661    char *result; 
     1662    PyObject * obj0 = 0 ; 
     1663     
     1664    if(!PyArg_ParseTuple(args,(char *)"O:Cursor_encoding_get",&obj0)) goto fail; 
     1665    if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_Cursor,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; 
     1666    result = (char *) ((arg1)->encoding); 
     1667     
     1668    resultobj = result ? PyString_FromString(result) : Py_BuildValue((char*)""); 
    16281669    return resultobj; 
    16291670    fail: 
     
    28582899         { (char *)"Cursor_posy_set", _wrap_Cursor_posy_set, METH_VARARGS }, 
    28592900         { (char *)"Cursor_posy_get", _wrap_Cursor_posy_get, METH_VARARGS }, 
     2901         { (char *)"Cursor_encoding_set", _wrap_Cursor_encoding_set, METH_VARARGS }, 
     2902         { (char *)"Cursor_encoding_get", _wrap_Cursor_encoding_get, METH_VARARGS }, 
    28602903         { (char *)"Cursor_noChildren", _wrap_Cursor_noChildren, METH_VARARGS }, 
    28612904         { (char *)"Cursor_currentNode", _wrap_Cursor_currentNode, METH_VARARGS }, 
  • 05/devel/sgfparser.py

    r42 r62  
    183183 
    184184 
    185     def __init__(self, sgf, sloppy = 1): 
     185    def __init__(self, sgf, sloppy): 
    186186        Node.sloppy = sloppy 
    187187 
     
    196196        self.currentN = self.root.next 
    197197        self.setFlags() 
     198 
     199        if self.currentNode().has_key('CA') and self.currentNode()['CA']: 
     200            self.encoding = self.currentNode()['CA'][0] 
     201        else: 
     202            self.encoding = '' 
     203 
    198204         
    199205    def setFlags(self):