Skip to content

Commit c168d85

Browse files
committed
Use common wrappers for the class registry methods.
1 parent 3891d92 commit c168d85

6 files changed

Lines changed: 18 additions & 344 deletions

File tree

srrealmodule/wrap_AtomRadiiTable.cpp

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -51,41 +51,6 @@ Derived class can be added to the global registry of AtomRadiiTable\n\
5151
types by calling the _registerThisType method with any instance.\n\
5252
";
5353

54-
const char* doc_AtomRadiiTable_create = "\
55-
Return a new instance of the same type as this AtomRadiiTable object.\n\
56-
This method must be overloaded in a derived class.\n\
57-
";
58-
59-
const char* doc_AtomRadiiTable_clone = "\
60-
Return a duplicate of this AtomRadiiTable instance.\n\
61-
This method must be overloaded in a derived class.\n\
62-
";
63-
64-
const char* doc_AtomRadiiTable_type = "\
65-
Return a unique string name for this AtomRadiiTable class.\n\
66-
This method must be overloaded in a derived class.\n\
67-
";
68-
69-
const char* doc_AtomRadiiTable__registerThisType = "\
70-
Add this instance to the global registry of AtomRadiiTable types.\n\
71-
\n\
72-
No return value. Cannot be overloaded in Python.\n\
73-
";
74-
75-
const char* doc_AtomRadiiTable_createByType = "\
76-
Create a new AtomRadiiTable object of the specified type.\n\
77-
\n\
78-
tp -- string identifier for a registered AtomRadiiTable class.\n\
79-
Use getRegisteredTypes for a set of allowed values.\n\
80-
\n\
81-
Return new AtomRadiiTable instance.\n\
82-
";
83-
84-
const char* doc_AtomRadiiTable_getRegisteredTypes = "\
85-
Return a set of string names for the registered AtomRadiiTable\n\
86-
types. These are the supported arguments for the createByType method.\n\
87-
";
88-
8954
const char* doc_AtomRadiiTable_lookup = "\
9055
Return empirical radius of an atom in Angstroms.\n\
9156
\n\
@@ -182,8 +147,6 @@ Return the value of the default atom radius.\n\
182147
// wrappers ------------------------------------------------------------------
183148

184149
DECLARE_PYDICT_METHOD_WRAPPER(getAllCustom, getAllCustom_asdict)
185-
DECLARE_PYSET_FUNCTION_WRAPPER(AtomRadiiTable::getRegisteredTypes,
186-
getAtomRadiiTableTypes_asset)
187150

188151
// Helper class for overloads of AtomRadiiTable methods from Python
189152

@@ -254,23 +217,9 @@ void wrap_AtomRadiiTable()
254217
using namespace nswrap_AtomRadiiTable;
255218
using boost::noncopyable;
256219

257-
class_<AtomRadiiTableWrap, noncopyable>(
258-
"AtomRadiiTable", doc_AtomRadiiTable)
259-
.def("create", &AtomRadiiTable::create,
260-
doc_AtomRadiiTable_create)
261-
.def("clone", &AtomRadiiTable::clone,
262-
doc_AtomRadiiTable_clone)
263-
.def("type", &AtomRadiiTable::type,
264-
return_value_policy<copy_const_reference>(),
265-
doc_AtomRadiiTable_type)
266-
.def("_registerThisType", &AtomRadiiTable::registerThisType,
267-
doc_AtomRadiiTable__registerThisType)
268-
.def("createByType", &AtomRadiiTable::createByType,
269-
arg("tp"), doc_AtomRadiiTable_createByType)
270-
.staticmethod("createByType")
271-
.def("getRegisteredTypes", getAtomRadiiTableTypes_asset,
272-
doc_AtomRadiiTable_getRegisteredTypes)
273-
.staticmethod("getRegisteredTypes")
220+
class_<AtomRadiiTableWrap, noncopyable>
221+
atomradiitable("AtomRadiiTable", doc_AtomRadiiTable);
222+
wrap_registry_methods(atomradiitable)
274223
.def("lookup",
275224
&AtomRadiiTable::lookup, arg("smbl"),
276225
doc_AtomRadiiTable_lookup)

srrealmodule/wrap_PDFBaseline.cpp

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,6 @@ const char* doc_PDFBaseline = "\
5050
Base class and registry for functions that calculate PDF baseline.\n\
5151
";
5252

53-
const char* doc_PDFBaseline_create = "\
54-
Return a new instance of the same type as self.\n\
55-
\n\
56-
This method must be overloaded in a derived class.\n\
57-
";
58-
59-
const char* doc_PDFBaseline_clone = "\
60-
Return a new instance that is a copy of self.\n\
61-
\n\
62-
This method must be overloaded in a derived class.\n\
63-
";
64-
65-
const char* doc_PDFBaseline_type = "\
66-
Return a unique string type that identifies a PDFBaseline-derived class.\n\
67-
The string type is used for class registration and in the createByType\n\
68-
function.\n\
69-
\n\
70-
This method must be overloaded in a derived class.\n\
71-
";
72-
7353
const char* doc_PDFBaseline___call__ = "\
7454
Calculate PDF baseline at the specified r.\n\
7555
\n\
@@ -79,27 +59,6 @@ r -- atom distance in Angstroms where the baseline is calculated.\n\
7959
Return float or NumPy array.\n\
8060
";
8161

82-
const char* doc_PDFBaseline__registerThisType = "\
83-
Add this class to the global registry of PDFBaseline types.\n\
84-
\n\
85-
This method must be called once after definition of the derived\n\
86-
class to support pickling and the createByType factory.\n\
87-
";
88-
89-
const char* doc_PDFBaseline_createByType = "\
90-
Return a new PDFBaseline instance of the specified string type.\n\
91-
\n\
92-
tp -- string type identifying a registered PDFBaseline class\n\
93-
See getRegisteredTypes for the allowed values.\n\
94-
\n\
95-
Return a new instance of the PDFBaseline-derived class.\n\
96-
";
97-
98-
const char* doc_PDFBaseline_getRegisteredTypes = "\
99-
Return a set of string types of the registered PDFBaseline classes.\n\
100-
These are the allowed arguments for the createByType factory.\n\
101-
";
102-
10362
const char* doc_ZeroBaseline = "\
10463
Trivial baseline function that is always zero, no baseline.\n\
10564
";
@@ -110,9 +69,6 @@ PDF baseline function equal to (slope * r).\n\
11069

11170
// wrappers ------------------------------------------------------------------
11271

113-
DECLARE_PYSET_FUNCTION_WRAPPER(PDFBaseline::getRegisteredTypes,
114-
getPDFBaselineTypes_asset)
115-
11672
// Helper class allows overload of the PDFBaseline methods from Python.
11773

11874
class PDFBaselineWrap :
@@ -200,27 +156,13 @@ void wrap_PDFBaseline()
200156
using diffpy::Attributes;
201157
namespace bp = boost::python;
202158

203-
class_<PDFBaselineWrap, bases<Attributes>,
204-
noncopyable>("PDFBaseline", doc_PDFBaseline)
205-
.def("create", &PDFBaseline::create,
206-
doc_PDFBaseline_create)
207-
.def("clone", &PDFBaseline::clone,
208-
doc_PDFBaseline_clone)
209-
.def("type", &PDFBaseline::type,
210-
return_value_policy<copy_const_reference>(),
211-
doc_PDFBaseline_type)
159+
class_<PDFBaselineWrap, bases<Attributes>, noncopyable>
160+
pdfbaseline("PDFBaseline", doc_PDFBaseline);
161+
wrap_registry_methods(pdfbaseline)
212162
.def("__call__", callnparray,
213163
bp::arg("r_array"))
214164
.def("__call__", &PDFBaseline::operator(),
215165
bp::arg("r"), doc_PDFBaseline___call__)
216-
.def("_registerThisType", &PDFBaseline::registerThisType,
217-
doc_PDFBaseline__registerThisType)
218-
.def("createByType", &PDFBaseline::createByType,
219-
bp::arg("tp"), doc_PDFBaseline_createByType)
220-
.staticmethod("createByType")
221-
.def("getRegisteredTypes", getPDFBaselineTypes_asset,
222-
doc_PDFBaseline_getRegisteredTypes)
223-
.staticmethod("getRegisteredTypes")
224166
.enable_pickling()
225167
;
226168

srrealmodule/wrap_PDFEnvelope.cpp

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,6 @@ const char* doc_PDFEnvelope = "\
5252
Base class and registry for functions that return PDF scaling envelopes.\n\
5353
";
5454

55-
const char* doc_PDFEnvelope_create = "\
56-
Return a new instance of the same type as self.\n\
57-
\n\
58-
This method must be overloaded in a derived class.\n\
59-
";
60-
61-
const char* doc_PDFEnvelope_clone = "\
62-
Return a new instance that is a copy of self.\n\
63-
\n\
64-
This method must be overloaded in a derived class.\n\
65-
";
66-
67-
const char* doc_PDFEnvelope_type = "\
68-
Return a unique string type that identifies a PDFEnvelope-derived class.\n\
69-
The string type is used for class registration and in the createByType\n\
70-
function.\n\
71-
\n\
72-
This method must be overloaded in a derived class.\n\
73-
";
74-
7555
const char* doc_PDFEnvelope___call__ = "\
7656
Calculate PDF envelope at the specified r.\n\
7757
\n\
@@ -81,27 +61,6 @@ r -- atom distance in Angstroms where the scale envelope is evaluated.\n\
8161
Return float or NumPy array.\n\
8262
";
8363

84-
const char* doc_PDFEnvelope__registerThisType = "\
85-
Add this class to the global registry of PDFEnvelope types.\n\
86-
\n\
87-
This method must be called once after definition of the derived\n\
88-
class to support pickling and the createByType factory.\n\
89-
";
90-
91-
const char* doc_PDFEnvelope_createByType = "\
92-
Return a new PDFEnvelope instance of the specified string type.\n\
93-
\n\
94-
tp -- string type identifying a registered PDFEnvelope class\n\
95-
See getRegisteredTypes for the allowed values.\n\
96-
\n\
97-
Return a new instance of the PDFEnvelope-derived class.\n\
98-
";
99-
100-
const char* doc_PDFEnvelope_getRegisteredTypes = "\
101-
Return a set of string types of the registered PDFEnvelope classes.\n\
102-
These are the allowed arguments for the createByType factory.\n\
103-
";
104-
10564
const char* doc_QResolutionEnvelope = "\
10665
Gaussian dampening envelope function due to limited Q-resolution.\n\
10766
\n\
@@ -131,9 +90,6 @@ Returns 0 when x > stepcut.\n\
13190

13291
// wrappers ------------------------------------------------------------------
13392

134-
DECLARE_PYSET_FUNCTION_WRAPPER(PDFEnvelope::getRegisteredTypes,
135-
getPDFEnvelopeTypes_asset)
136-
13793
// Helper class allows overload of the PDFEnvelope methods from Python.
13894

13995
class PDFEnvelopeWrap :
@@ -221,27 +177,13 @@ void wrap_PDFEnvelope()
221177
using diffpy::Attributes;
222178
namespace bp = boost::python;
223179

224-
class_<PDFEnvelopeWrap, bases<Attributes>,
225-
noncopyable>("PDFEnvelope", doc_PDFEnvelope)
226-
.def("create", &PDFEnvelope::create,
227-
doc_PDFEnvelope_create)
228-
.def("clone", &PDFEnvelope::clone,
229-
doc_PDFEnvelope_clone)
230-
.def("type", &PDFEnvelope::type,
231-
return_value_policy<copy_const_reference>(),
232-
doc_PDFEnvelope_type)
180+
class_<PDFEnvelopeWrap, bases<Attributes>, noncopyable>
181+
pdfenvelope("PDFEnvelope", doc_PDFEnvelope);
182+
wrap_registry_methods(pdfenvelope)
233183
.def("__call__", callnparray,
234184
bp::arg("r_array"))
235185
.def("__call__", &PDFEnvelope::operator(),
236186
bp::arg("r"), doc_PDFEnvelope___call__)
237-
.def("_registerThisType", &PDFEnvelope::registerThisType,
238-
doc_PDFEnvelope__registerThisType)
239-
.def("createByType", &PDFEnvelope::createByType,
240-
bp::arg("tp"), doc_PDFEnvelope_createByType)
241-
.staticmethod("createByType")
242-
.def("getRegisteredTypes", getPDFEnvelopeTypes_asset,
243-
doc_PDFEnvelope_getRegisteredTypes)
244-
.staticmethod("getRegisteredTypes")
245187
.enable_pickling()
246188
;
247189

srrealmodule/wrap_PeakProfile.cpp

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,6 @@ The peak profile functions must be centered at 0 and their integrated\n\
4747
area must be 1.\n\
4848
";
4949

50-
const char* doc_PeakProfile_create = "\
51-
Return a new default instance of the same type as self.\n\
52-
\n\
53-
This method must be overridden in a derived class.\n\
54-
";
55-
56-
const char* doc_PeakProfile_clone = "\
57-
Return a new instance that is a copy of self.\n\
58-
\n\
59-
This method must be overridden in a derived class.\n\
60-
";
61-
62-
const char* doc_PeakProfile_type = "\
63-
Return a unique string type that identifies a PeakProfile-derived class.\n\
64-
The string type is used for class registration and in the createByType\n\
65-
function.\n\
66-
\n\
67-
This method must be overridden in a derived class.\n\
68-
";
69-
7050
const char* doc_PeakProfile___call__ = "\
7151
Evaluate peak profile function for a given position and peak width.\n\
7252
\n\
@@ -115,20 +95,6 @@ This method must be called once after definition of the derived\n\
11595
class to support pickling and the createByType factory.\n\
11696
";
11797

118-
const char* doc_PeakProfile_createByType = "\
119-
Return a new PeakProfile instance of the specified string type.\n\
120-
\n\
121-
tp -- string type identifying a registered PeakProfile class\n\
122-
See getRegisteredTypes for the allowed values.\n\
123-
\n\
124-
Return a new instance of the PeakProfile-derived class.\n\
125-
";
126-
127-
const char* doc_PeakProfile_getRegisteredTypes = "\
128-
Set of string identifiers for registered PeakProfile classes.\n\
129-
These are allowed arguments for the createByType static method.\n\
130-
";
131-
13298
const char* doc_GaussianProfile = "\
13399
Gaussian profile function.\n\
134100
";
@@ -141,9 +107,6 @@ The profile is also rescaled to keep the integrated area of 1.\n\
141107

142108
// wrappers ------------------------------------------------------------------
143109

144-
DECLARE_PYSET_FUNCTION_WRAPPER(PeakProfile::getRegisteredTypes,
145-
getPeakProfileTypes_asset)
146-
147110
// Support for override of PeakProfile methods from Python.
148111

149112
class PeakProfileWrap :
@@ -250,13 +213,9 @@ void wrap_PeakProfile()
250213
using diffpy::Attributes;
251214
namespace bp = boost::python;
252215

253-
class_<PeakProfileWrap, bases<Attributes>,
254-
noncopyable>("PeakProfile", doc_PeakProfile)
255-
.def("create", &PeakProfile::create, doc_PeakProfile_create)
256-
.def("clone", &PeakProfile::clone, doc_PeakProfile_clone)
257-
.def("type", &PeakProfile::type,
258-
return_value_policy<copy_const_reference>(),
259-
doc_PeakProfile_type)
216+
class_<PeakProfileWrap, bases<Attributes>, noncopyable>
217+
peakprofile("PeakProfile", doc_PeakProfile);
218+
wrap_registry_methods(peakprofile)
260219
.def("__call__", &PeakProfile::operator(),
261220
(bp::arg("x"), bp::arg("fwhm")), doc_PeakProfile___call__)
262221
.def("xboundlo", &PeakProfile::xboundlo,
@@ -268,14 +227,6 @@ void wrap_PeakProfile()
268227
&PeakProfileWrap::default_ticker,
269228
return_internal_reference<>(),
270229
doc_PeakProfile_ticker)
271-
.def("_registerThisType", &PeakProfile::registerThisType,
272-
doc_PeakProfile__registerThisType)
273-
.def("createByType", &PeakProfile::createByType,
274-
bp::arg("tp"), doc_PeakProfile_createByType)
275-
.staticmethod("createByType")
276-
.def("getRegisteredTypes", getPeakProfileTypes_asset,
277-
doc_PeakProfile_getRegisteredTypes)
278-
.staticmethod("getRegisteredTypes")
279230
.enable_pickling()
280231
;
281232

0 commit comments

Comments
 (0)