1 // Copyright (C) 2006-2015 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "PyStdout.hxx"
21 #include <structmember.h>
36 PyStdOut_dealloc(PyStdOut *self)
42 PyStdOut_write(PyStdOut *self, PyObject *args)
46 if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
50 *(self->out)=*(self->out)+std::string(c);
56 static PyMethodDef PyStdOut_methods[] = {
57 {"write", (PyCFunction)PyStdOut_write, METH_VARARGS,
58 PyDoc_STR("write(string) -> None")},
59 {NULL, NULL} /* sentinel */
62 static PyMemberDef PyStdOut_memberlist[] = {
63 {(char*)"softspace", T_INT, offsetof(PyStdOut, softspace), 0,
64 (char*)"flag indicating that a space needs to be printed; used by print"},
68 static PyTypeObject PyStdOut_Type = {
69 /* The ob_type field must be initialized in the module init function
70 * to be portable to Windows without using C++. */
71 PyObject_HEAD_INIT(NULL)
74 sizeof(PyStdOut), /*tp_basicsize*/
77 (destructor)PyStdOut_dealloc, /*tp_dealloc*/
89 PyObject_GenericGetAttr, /*tp_getattro*/
90 /* softspace is writable: we must supply tp_setattro */
91 PyObject_GenericSetAttr, /* tp_setattro */
93 Py_TPFLAGS_DEFAULT, /*tp_flags*/
98 0, /*tp_weaklistoffset*/
101 PyStdOut_methods, /*tp_methods*/
102 PyStdOut_memberlist, /*tp_members*/
117 #define PyStdOut_Check(v) ((v)->ob_type == &PyStdOut_Type)
119 PyObject * newPyStdOut( std::string& out )
122 self = PyObject_New(PyStdOut, &PyStdOut_Type);
127 return (PyObject*)self;