19 const std::size_t defaultBufferSize = 10;
20 const std::string s_uri =
"://";
28 PyObject* py_repr = PyObject_Repr( o );
29 if ( !py_repr || !PyUnicode_Check(py_repr) ) {
30 Py_XDECREF( py_repr );
34 std::string cpp_repr = PyUnicode_AsUTF8(py_repr);
47 m_bufSize( defaultBufferSize ),
48 m_store ( PyDict_New() )
53 m_store ( PyDict_New() )
94 Py_XDECREF( buffers );
98 for (
int i = 0, iMax = PyList_GET_SIZE( buffers );
i < iMax; ++
i ) {
99 PyObject* buf = PyList_GET_ITEM( buffers,
i );
102 const int len = PyList_GET_SIZE( buf );
105 if ( PyList_SetSlice( buf, 0, len, (
PyObject *) NULL ) != 0 ) {
115 Py_DECREF( buffers );
124 const std::string& dataName,
130 std::cerr <<
"Store::book : Could not allocate a buffer for ["
131 <<
key << s_uri << dataName <<
"] !!\n";
139 std::cerr <<
"Store::book : Could not reset allocated buffer ["
140 <<
key << s_uri << dataName <<
"] !!\n"
141 <<
" buf: " <<
Py::repr( buf ) <<
"\n";
147 if ( PyDict_SetItemString(
m_store,
148 const_cast<char*
>((
key+s_uri+dataName).c_str()),
151 std::cerr <<
"Store::book : Could not create buffer at ["
152 <<
key << s_uri << dataName <<
"]\n"
153 <<
" buf: " <<
Py::repr( buf ) <<
"\n";
160 const std::string& dataName,
165 const_cast<char*
>((
key+s_uri+dataName).c_str()) );
168 std::cerr <<
"Store::fill : Could not retrieve key ["
169 <<
key << s_uri << dataName <<
"] from store !!\n";
178 if ( !PyList_Check( buf ) ) {
179 std::cerr <<
"Store::fill : buffer at ["
180 <<
key << s_uri << dataName <<
"] is NOT a python array !!\n"
181 <<
" buf: " <<
Py::repr( buf ) <<
"\n";
190 if ( 0 != PyList_Append( buf,
data ) ) {
192 std::cerr <<
"Store::fill : could not fill buffer at ["
193 <<
key << s_uri << dataName <<
"] !!\n"
194 <<
" buf: " <<
Py::repr( buf ) <<
"\n"
215 s.book<
bool>(
"f",
"b" );
216 s.fill<
bool>(
"f",
"b", true );
218 s.book<
double>(
"f",
"d" );
219 s.fill<
double>(
"f",
"d", 1.2 );
221 s.book<
float>(
"f",
"f" );
222 s.fill<
float>(
"f",
"f", 1.2 );
224 s.book<
int>(
"f",
"i" );
225 s.fill<
int>(
"f",
"i", 1 );
227 s.book<
short int>(
"f",
"h" );
228 s.fill<
short int>(
"f",
"h", 1 );
230 s.book<
unsigned int>(
"f",
"I" );
231 s.fill<
unsigned int>(
"f",
"I", 10 );
233 s.book<
long int>(
"f",
"l" );
234 s.fill<
long int>(
"f",
"l", 100 );
236 s.book<
unsigned long int>(
"f",
"k" );
237 s.fill<
unsigned long int>(
"f",
"k", 1000 );
240 std::vector<double>
data(10);
241 s.book<std::vector<double> >(
"f",
"vd" );
242 s.fill<std::vector<double> >(
"f",
"vd",
data );
246 std::list<double>
data(10);
247 s.book<std::list<double> >(
"f",
"ld" );
248 s.fill<std::list<double> >(
"f",
"ld",
data );
252 std::pair<double,float>
data;
data.first = 10.;
data.second = 20.;
253 s.book<std::pair<double,float> >(
"f",
"p" );
254 s.fill<std::pair<double,float> >(
"f",
"p",
data );