Skip to content

Commit 42b2096

Browse files
committed
Add header for HasClassRegistry helper functions.
Move there the wrapper_registry_configurator class.
1 parent 0bfceb3 commit 42b2096

8 files changed

Lines changed: 77 additions & 44 deletions

srrealmodule/srreal_converters.hpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -406,50 +406,6 @@ class wrapper_srreal : public ::boost::python::wrapper<T>
406406
}
407407
};
408408

409-
410-
/// template class for handling Python Wrapper classes in C++ class registry
411-
template <class T>
412-
class wrapper_registry_configurator
413-
{
414-
typedef typename T::SharedPtr TSharedPtr;
415-
typedef typename T::SharedPtr::element_type* TPtr;
416-
417-
public:
418-
419-
// constructor
420-
wrapper_registry_configurator() : mcptr(0), mpyptr(0) { }
421-
422-
// methods
423-
/// the fetch method should be called only from the wrapped method
424-
/// create() to remember pointers to the last Python object and
425-
/// the C++ instance that it wraps.
426-
TSharedPtr fetch(::boost::python::object& obj) const
427-
{
428-
TSharedPtr p = ::boost::python::extract<TSharedPtr>(obj);
429-
mcptr = p.get();
430-
mpyptr = obj.ptr();
431-
return p;
432-
}
433-
434-
/// the setup function should be executed just once from the
435-
/// HasClassRegistry::setupRegisteredObject method in the wrapper
436-
/// class. This ensures the Python object in a prototype factory
437-
/// stays alive when the process is shut down.
438-
void setup(TSharedPtr ptr) const
439-
{
440-
assert(mcptr && mcptr == ptr.get());
441-
::boost::python::incref(mpyptr);
442-
mcptr = 0;
443-
mpyptr = 0;
444-
}
445-
446-
private:
447-
448-
// data
449-
mutable TPtr mcptr;
450-
mutable PyObject* mpyptr;
451-
};
452-
453409
} // namespace srrealmodule
454410

455411
// Include shared wrapper definitions ----------------------------------------

srrealmodule/srreal_registry.hpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*****************************************************************************
2+
*
3+
* diffpy.srreal Complex Modeling Initiative
4+
* (c) 2016 Brookhaven Science Associates,
5+
* Brookhaven National Laboratory.
6+
* All rights reserved.
7+
*
8+
* File coded by: Pavol Juhas
9+
*
10+
* See AUTHORS.txt for a list of people who contributed.
11+
* See LICENSE.txt for license information.
12+
*
13+
******************************************************************************
14+
*
15+
* Utilities for wrapping classes that derive from HasClassRegistry.
16+
*
17+
*****************************************************************************/
18+
19+
#ifndef SRREAL_REGISTRY_HPP_INCLUDED
20+
#define SRREAL_REGISTRY_HPP_INCLUDED
21+
22+
#include <boost/python/object.hpp>
23+
24+
namespace srrealmodule {
25+
26+
/// template class for handling Python Wrapper classes in C++ class registry
27+
template <class T>
28+
class wrapper_registry_configurator
29+
{
30+
typedef typename T::SharedPtr TSharedPtr;
31+
typedef typename T::SharedPtr::element_type* TPtr;
32+
33+
public:
34+
35+
// constructor
36+
wrapper_registry_configurator() : mcptr(0), mpyptr(0) { }
37+
38+
// methods
39+
/// the fetch method should be called only from the wrapped method
40+
/// create() to remember pointers to the last Python object and
41+
/// the C++ instance that it wraps.
42+
TSharedPtr fetch(::boost::python::object& obj) const
43+
{
44+
TSharedPtr p = ::boost::python::extract<TSharedPtr>(obj);
45+
mcptr = p.get();
46+
mpyptr = obj.ptr();
47+
return p;
48+
}
49+
50+
/// the setup function should be executed just once from the
51+
/// HasClassRegistry::setupRegisteredObject method in the wrapper
52+
/// class. This ensures the Python object in a prototype factory
53+
/// stays alive when the process is shut down.
54+
void setup(TSharedPtr ptr) const
55+
{
56+
assert(mcptr && mcptr == ptr.get());
57+
::boost::python::incref(mpyptr);
58+
mcptr = 0;
59+
mpyptr = 0;
60+
}
61+
62+
private:
63+
64+
// data
65+
mutable TPtr mcptr;
66+
mutable PyObject* mpyptr;
67+
};
68+
69+
} // namespace srrealmodule
70+
71+
#endif // SRREAL_REGISTRY_HPP_INCLUDED

srrealmodule/wrap_AtomRadiiTable.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "srreal_converters.hpp"
2525
#include "srreal_pickling.hpp"
26+
#include "srreal_registry.hpp"
2627

2728
#include <diffpy/srreal/AtomRadiiTable.hpp>
2829
#include <diffpy/srreal/ConstantRadiiTable.hpp>

srrealmodule/wrap_PDFBaseline.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
#include "srreal_converters.hpp"
3737
#include "srreal_pickling.hpp"
38+
#include "srreal_registry.hpp"
3839

3940
namespace srrealmodule {
4041
namespace nswrap_PDFBaseline {

srrealmodule/wrap_PDFEnvelope.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
#include "srreal_converters.hpp"
3939
#include "srreal_pickling.hpp"
40+
#include "srreal_registry.hpp"
4041

4142
namespace srrealmodule {
4243
namespace nswrap_PDFEnvelope {

srrealmodule/wrap_PeakProfile.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "srreal_converters.hpp"
3232
#include "srreal_pickling.hpp"
33+
#include "srreal_registry.hpp"
3334

3435
namespace srrealmodule {
3536
namespace nswrap_PeakProfile {

srrealmodule/wrap_PeakWidthModel.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <diffpy/serialization.hpp>
3232

3333
#include "srreal_converters.hpp"
34+
#include "srreal_registry.hpp"
3435

3536
namespace srrealmodule {
3637
namespace nswrap_PeakWidthModel {

srrealmodule/wrap_ScatteringFactorTable.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
#include "srreal_converters.hpp"
3939
#include "srreal_pickling.hpp"
40+
#include "srreal_registry.hpp"
4041

4142
namespace srrealmodule {
4243
namespace nswrap_ScatteringFactorTable {

0 commit comments

Comments
 (0)