FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
libdiffpy/src/diffpy/srreal/PythonStructureAdapter.cpp at develop · cfarrow/libdiffpy · GitHub
cfarrow
libdiffpy
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
libdiffpy
/
src
/
diffpy
/
srreal
/
PythonStructureAdapter.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
88 lines (73 loc) · 2.47 KB
Breadcrumbs
libdiffpy
/
src
/
diffpy
/
srreal
/
PythonStructureAdapter.cpp
Copy path
File metadata and controls
88 lines (73 loc) · 2.47 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
****************************************************************************
*
* diffpy.srreal by DANSE Diffraction group
* Simon J. L. Billinge
* (c) 2009 Trustees of the Columbia University
* in the City of New York. All rights reserved.
*
* File coded by: Pavol Juhas
*
* See AUTHORS.txt for a list of people who contributed.
* See LICENSE.txt for license information.
*
******************************************************************************
*
* createStructureAdapter - a factory for creating StructureAdapter
* for recognized Python objects
*
****************************************************************************
*/
#
include
<
diffpy/srreal/PythonStructureAdapter.hpp
>
#
include
<
stdexcept
>
#
include
<
sstream
>
#
include
<
string
>
#
include
<
set
>
using
namespace
boost
;
using
namespace
std
;
namespace
diffpy
{
namespace
srreal
{
//
Local Helpers -------------------------------------------------------------
namespace
{
typedef
set<PythonStructureAdapterFactory> PSAFactorySet;
PSAFactorySet&
getPSAFactorySet
()
{
static
PSAFactorySet factories;
return
factories;
}
}
//
namespace
//
Routines ------------------------------------------------------------------
StructureAdapterPtr
createStructureAdapter
(
const
boost::python::object stru)
{
StructureAdapterPtr rv;
//
First check if stru is already a wrapped StructureAdapterPtr
python::extract<StructureAdapterPtr>
getadapter
(stru);
if
(getadapter.
check
())
{
rv =
getadapter
();
if
(rv.
get
())
return
rv;
}
//
Loop over all registered factories. They should return
//
a new StructureAdapter instance or NULL on failure.
PSAFactorySet::iterator factory =
getPSAFactorySet
().
begin
();
PSAFactorySet::iterator last =
getPSAFactorySet
().
end
();
for
(; factory != last; ++factory)
{
rv = (*factory)(stru);
if
(rv.
get
())
return
rv;
}
//
We get here only if nothing worked.
python::object emsg =
"
Cannot create structure adapter for %r.
"
%
python::make_tuple
(stru);
PyErr_SetObject
(PyExc_TypeError, emsg.
ptr
());
python::throw_error_already_set
();
//
This should be never reached
return
rv;
}
//
Factory functions registration --------------------------------------------
bool
registerPythonStructureAdapterFactory
(PythonStructureAdapterFactory fctr)
{
getPSAFactorySet
().
insert
(fctr);
return
true
;
}
}
//
namespace srreal
}
//
namespace diffpy
//
End of file
Back
|
FazBrowse Home
|
New Git URL