File: wrap_info.cc

package info (click to toggle)
openstructure 2.9.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 205,228 kB
  • sloc: cpp: 188,129; python: 35,361; ansic: 34,298; fortran: 3,275; sh: 286; xml: 146; makefile: 29
file content (321 lines) | stat: -rw-r--r-- 10,595 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
//------------------------------------------------------------------------------
// This file is part of the OpenStructure project <www.openstructure.org>
//
// Copyright (C) 2008-2020 by the OpenStructure authors
// Copyright (C) 2003-2010 by the IPLT authors
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 3.0 of the License, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//------------------------------------------------------------------------------

/*
  info wrapper

  Author: Ansgar Philippsen
*/

#include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <ost/info/info.hh>
#include <ost/info/info_visitor.hh>
#include <ost/info/info_verbose_visitor.hh>
#include <ost/info/geom_info_conversion.hh>
using namespace boost::python;
using namespace ost;
using namespace ost::info;


InfoHandle (*CreateInfoPtr1)()=CreateInfo;
InfoHandle (*CreateInfoPtr2)(const String&)=CreateInfo;

void info_group_apply1a(InfoGroup* g, InfoVisitor& v)
{
  g->Apply(v);
}

void info_group_apply1b(InfoGroup* g, InfoVisitor& v, bool b)
{
  g->Apply(v,b);
}

void info_group_apply2a(InfoGroup* g, InfoConstVisitor& v)
{
  g->Apply(v);
}

void info_group_apply2b(InfoGroup* g, InfoConstVisitor& v, bool b)
{
  g->Apply(v,b);
}

void info_group_remove1(InfoGroup* g, const String& path )
{
  g->Remove(path);
}

void info_group_remove2(InfoGroup* g, InfoGroup& group )
{
  g->Remove(group);
}
void info_group_remove3(InfoGroup* g, const String& path, bool use_defaults )
{
  g->Remove(path,use_defaults);
}

void info_handle_apply1a(InfoHandle* h, InfoVisitor& v)
{
  h->Apply(v);
}

void info_handle_apply1b(InfoHandle* h, InfoVisitor& v, bool b)
{
  h->Apply(v,b);
}

void info_handle_apply2a(InfoHandle* h, InfoConstVisitor& v)
{
  h->Apply(v);
}

void info_handle_apply2b(InfoHandle* h, InfoConstVisitor& v, bool b)
{
  h->Apply(v,b);
}

void info_handle_remove1(InfoHandle* h, const String& path )
{
  h->Remove(path);
}

void info_handle_remove2(InfoHandle* h, InfoGroup& group )
{
  h->Remove(group);
}
void info_handle_remove3(InfoHandle* h, const String& path, bool use_defaults )
{
  h->Remove(path,use_defaults);
}


class InfoVisitorProxy : public InfoVisitor {
public:
  InfoVisitorProxy(PyObject *p)
      : self(p) {}

  InfoVisitorProxy(PyObject *p, const InfoVisitor& i)
      : InfoVisitor(i), self(p) {}
  
  virtual bool VisitGroup(InfoGroup& group)
  {
    return call_method<bool, InfoGroup>(self, "VisitGroup", group);
  }
  
  virtual void VisitItem(InfoItem& item)
  {
    call_method<void, InfoItem>(self, "VisitItem", item);
  }  
  
  bool VisitItemDefault(const InfoItem&) 
  {
    return true;
  }
  
  bool VisitGroupDefault(const InfoGroup&) 
  {
    return true;
  }  

  virtual void VisitGroupFinish(InfoGroup& group)
 {
    call_method<void, InfoGroup>(self, "VisitGroupFinish", group);
 }

 void VisitGroupFinishDefault(const InfoGroup&) 
 {
 }  
private:
  PyObject* self;
};

InfoItem (InfoGroup::*create_item_a)(const String&, const String&)=&InfoGroup::CreateItem;
InfoItem (InfoGroup::*create_item_b)(const String&, int)=&InfoGroup::CreateItem;
InfoItem (InfoGroup::*create_item_c)(const String&, bool)=&InfoGroup::CreateItem;
InfoItem (InfoGroup::*create_item_d)(const String&, Real)=&InfoGroup::CreateItem;


BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getgroup_overloads, GetGroup, 1, 2)
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(retrievegroup_overloads, RetrieveGroup, 1, 2)
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(hasgroup_overloads, HasGroup, 1, 2)
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getitem_overloads, GetItem, 1, 2)
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(hasitem_overloads, HasItem, 1, 2)
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(retrieveitem_overloads, RetrieveItem, 1, 2)


BOOST_PYTHON_MODULE(_ost_info)
{

  enum_<Type>("ItemType")
    .value("STRING",IT_STRING)
    .value("INT",IT_INT)
    .value("FLOAT",IT_FLOAT)
    .value("BOOL",IT_BOOL)
    .value("VECTOR",IT_VECTOR)
    ;

  void (InfoItem::*set_type1)(int type)=&InfoItem::SetType;
  
  class_<InfoItem>("InfoItem",no_init)
    .def("GetParent",&InfoItem::GetParent)
    .def("GetName",&InfoItem::GetName)
    .add_property("name",&InfoItem::GetName)
    .def("GetValue",&InfoItem::GetValue)
    .def("SetValue",&InfoItem::SetValue)
    .add_property("value",&InfoItem::GetValue,&InfoItem::SetValue)
    .def("GetAttribute",&InfoItem::GetAttribute)
    .def("SetAttribute",&InfoItem::SetAttribute)
    .def("HasAttribute",&InfoItem::HasAttribute)
    .def("GetAttributeList",&InfoItem::GetAttributeList)
    .def("AsFloat",&InfoItem::AsFloat)
    .def("AsInt",&InfoItem::AsInt)
    .def("AsBool",&InfoItem::AsBool)
    .def("AsVector",&InfoItem::AsVector)
    .def("SetType",set_type1)
    .def("GetType",&InfoItem::GetType)
    .def("SetFloat",&InfoItem::SetFloat)
    .def("SetInt",&InfoItem::SetInt)
    .def("SetBool",&InfoItem::SetBool)
    .def("SetVector",&InfoItem::SetVector)
    .add_property("attribute",&InfoItem::GetAttribute,&InfoItem::SetAttribute)
    .def("GetComment",&InfoItem::GetComment)
    ;
  class_<InfoGroupList>("InfoGroupList", no_init)
    .def(vector_indexing_suite<InfoGroupList>())
  ;
  class_<InfoItemList>("InfoItemList", no_init)
    .def(vector_indexing_suite<InfoItemList>())
  ;  
  class_<InfoGroup>("InfoGroup",no_init)
    .def("GetParent",&InfoGroup::GetParent)
    .def("GetName",&InfoGroup::GetName)
    .def("SetName",&InfoGroup::SetName)
    .add_property("name",&InfoGroup::GetName,&InfoGroup::SetName)
    .def("GetGroup",&InfoGroup::GetGroup,getgroup_overloads())
    .def("GetGroups", &InfoGroup::GetGroups)
    .def("GetItems", &InfoGroup::GetItems)
    .def("CreateGroup",&InfoGroup::CreateGroup)
    .def("RetrieveGroup",&InfoGroup::RetrieveGroup,retrievegroup_overloads())
    .def("HasGroup",&InfoGroup::HasGroup,hasgroup_overloads())
    .def("GetItem",&InfoGroup::GetItem,getitem_overloads())
    .def("CreateItem",create_item_a)
    .def("CreateItem",create_item_b)
    .def("CreateItem",create_item_c)
    .def("CreateItem",create_item_d)            
    .def("HasItem",&InfoGroup::HasItem,hasitem_overloads())
    .def("RetrieveItem",&InfoGroup::RetrieveItem,retrieveitem_overloads())
    .def("Remove",info_group_remove1)
    .def("Remove",info_group_remove2)
    .def("Remove",info_group_remove3)
    .def("GetAttribute",&InfoGroup::GetAttribute)
    .def("SetAttribute",&InfoGroup::SetAttribute)
    .def("HasAttribute",&InfoGroup::HasAttribute)
    .def("GetAttributeList",&InfoGroup::GetAttributeList)
    .def("SetTextData", &InfoGroup::SetTextData)
    .def("Apply",info_group_apply1a)
    .def("Apply",info_group_apply1b)
    .def("Apply",info_group_apply2a)
    .def("Apply",info_group_apply2b)
    .def("GetTextData",&InfoGroup::GetTextData)
    .def("GetComment",&InfoGroup::GetComment)
    .def("GetPath",&InfoGroup::GetPath)
    ;

  class_<InfoHandle>("InfoHandle",no_init)
    .def("Import",&InfoHandle::Import)
    .def("Export",&InfoHandle::Export)
    .def("Root",&InfoHandle::Root)
    .def("AddDefault",&InfoHandle::AddDefault)
    .def("Copy",&InfoHandle::Copy)
    .def("HasDefaultGroup",&InfoHandle::HasDefaultGroup)
    .def("GetDefaultGroup",&InfoHandle::GetDefaultGroup)
    .def("HasDefaultItem",&InfoHandle::HasDefaultItem)
    .def("GetDefaultItem",&InfoHandle::GetDefaultItem)
    .def("GetParent",&InfoHandle::GetParent)
    .def("GetName",&InfoHandle::GetName)
    .def("SetName",&InfoHandle::SetName)
    .add_property("name",&InfoHandle::GetName,&InfoHandle::SetName)
    .def("GetGroup",&InfoHandle::GetGroup,getgroup_overloads())
    .def("CreateGroup",&InfoHandle::CreateGroup)
    .def("RetrieveGroup",&InfoHandle::RetrieveGroup,retrievegroup_overloads())
    .def("HasGroup",&InfoHandle::HasGroup,hasgroup_overloads())
    .def("GetItem",&InfoHandle::GetItem,getitem_overloads())
    .def("CreateItem",&InfoHandle::CreateItem)
    .def("HasItem",&InfoHandle::HasItem,hasitem_overloads())
    .def("RetrieveItem",&InfoHandle::RetrieveItem,retrieveitem_overloads())
    .def("Remove",info_handle_remove1)
    .def("Remove",info_handle_remove2)
    .def("Remove",info_handle_remove3)
    .def("GetAttribute",&InfoHandle::GetAttribute)
    .def("SetAttribute",&InfoHandle::SetAttribute)
    .def("HasAttribute",&InfoHandle::HasAttribute)
    .def("GetAttributeList",&InfoHandle::GetAttributeList)
    .def("Apply",info_handle_apply1a)
    .def("Apply",info_handle_apply1b)
    .def("Apply",info_handle_apply2a)
    .def("Apply",info_handle_apply2b)
    .def("GetTextData",&InfoHandle::GetTextData)
    ;

  def("CreateInfo",CreateInfoPtr1);
  def("CreateInfo",CreateInfoPtr2);
  def("LoadInfo",&LoadInfo);

  class_<InfoPath>("InfoPath",init<const String&>())
    .def("GetList",&InfoPath::GetList)
    .def("IsRelative",&InfoPath::IsRelative)
    .def(self_ns::str(self))
    ;

  def("GetFloatInfoItem",GetFloatInfoItem);
  def("GetIntInfoItem",GetIntInfoItem);
  def("GetBoolInfoItem",GetBoolInfoItem);
  def("GetVectorInfoItem",GetVectorInfoItem);
  def("GetStringInfoItem",GetStringInfoItem);

  def("SetFloatInfoItem",SetFloatInfoItem);
  def("SetIntInfoItem",SetIntInfoItem);
  def("SetBoolInfoItem",SetBoolInfoItem);
  def("SetVectorInfoItem",SetVectorInfoItem);
  def("SetStringInfoItem",SetStringInfoItem);

  def("Mat2ToInfo", &Mat2ToInfo);
  def("Mat3ToInfo", &Mat3ToInfo);  
  def("Mat4ToInfo", &Mat4ToInfo);  
  
  def("Mat2FromInfo", &Mat2FromInfo);
  def("Mat3FromInfo", &Mat3FromInfo);  
  def("Mat4FromInfo", &Mat4FromInfo);  
  implicitly_convertible<String,InfoPath>();

  class_<InfoVisitor, InfoVisitorProxy>("InfoVisitor",init<>())
    .def("VisitGroup", &InfoVisitorProxy::VisitGroupDefault)
    .def("VisitItem", &InfoVisitorProxy::VisitItemDefault)
    .def("VisitGroupFinish", &InfoVisitorProxy::VisitGroupFinishDefault)
  ;

  class_<VerboseInfoVisitor, bases<InfoVisitor> >("VerboseInfoVisitor",init<>())
  ;

  def("TransformToInfo", &TransformToInfo);
  def("TransformFromInfo", &TransformFromInfo);

}