FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
libdiffpy/src/diffpy/srreal/PDFEnvelope.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
/
PDFEnvelope.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
140 lines (111 loc) · 3.52 KB
Breadcrumbs
libdiffpy
/
src
/
diffpy
/
srreal
/
PDFEnvelope.cpp
Copy path
File metadata and controls
140 lines (111 loc) · 3.52 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
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
/*
****************************************************************************
*
* 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.
*
******************************************************************************
*
* class PDFEnvelope -- abstract base class for PDF envelope functions
*
****************************************************************************
*/
#
include
<
sstream
>
#
include
<
stdexcept
>
#
include
<
boost/serialization/export.hpp
>
#
include
<
diffpy/srreal/PDFEnvelope.hpp
>
#
include
<
diffpy/HasClassRegistry.ipp
>
#
include
<
diffpy/validators.hpp
>
#
include
<
diffpy/serialization.ipp
>
using
namespace
std
;
using
diffpy::validators::ensureNonNull;
namespace
diffpy
{
//
Unique instantiation of the template registry base class.
template
class
HasClassRegistry
<srreal::PDFEnvelope>;
namespace
srreal
{
//
class PDFEnvelopeOwner ----------------------------------------------------
//
public methods
QuantityType
PDFEnvelopeOwner::applyEnvelopes
(
const
QuantityType& x,
const
QuantityType& y)
const
{
assert
(x.
size
() == y.
size
());
QuantityType z = y;
EnvelopeStorage::const_iterator evit;
for
(evit = menvelope.
begin
(); evit != menvelope.
end
(); ++evit)
{
PDFEnvelope& fenvelope = *(evit->
second
);
QuantityType::const_iterator xi = x.
begin
();
QuantityType::iterator zi = z.
begin
();
for
(; xi != x.
end
(); ++xi, ++zi)
{
*zi *=
fenvelope
(*xi);
}
}
return
z;
}
void
PDFEnvelopeOwner::addEnvelope
(PDFEnvelopePtr envlp)
{
ensureNonNull
(
"
PDFEnvelope
"
, envlp);
menvelope[envlp->
type
()] = envlp;
}
void
PDFEnvelopeOwner::addEnvelopeByType
(
const
string& tp)
{
//
this throws invalid_argument for invalid type
PDFEnvelopePtr envlp =
PDFEnvelope::createByType
(tp);
//
we get here only when createByType was successful
menvelope[envlp->
type
()] = envlp;
}
void
PDFEnvelopeOwner::popEnvelope
(PDFEnvelopePtr envlp)
{
EnvelopeStorage::iterator evit = menvelope.
begin
();
for
(; evit != menvelope.
end
(); ++evit)
{
if
(evit->
second
== envlp) menvelope.
erase
(evit);
}
}
void
PDFEnvelopeOwner::popEnvelopeByType
(
const
string& tp)
{
menvelope.
erase
(tp);
}
const
PDFEnvelopePtr&
PDFEnvelopeOwner::getEnvelopeByType
(
const
string& tp)
const
{
//
call non-constant method
const
PDFEnvelopePtr& rv =
const_cast
<PDFEnvelopeOwner*>(
this
)->
getEnvelopeByType
(tp);
return
rv;
}
PDFEnvelopePtr&
PDFEnvelopeOwner::getEnvelopeByType
(
const
string& tp)
{
if
(!menvelope.
count
(tp))
{
ostringstream emsg;
emsg <<
"
Invalid or missing PDFEnvelope type '
"
<< tp <<
"
'.
"
;
throw
invalid_argument
(emsg.
str
());
}
PDFEnvelopePtr& rv = menvelope[tp];
return
rv;
}
set<string>
PDFEnvelopeOwner::usedEnvelopeTypes
()
const
{
set<string> rv;
EnvelopeStorage::const_iterator evit;
for
(evit = menvelope.
begin
(); evit != menvelope.
end
(); ++evit)
{
rv.
insert
(rv.
end
(), evit->
first
);
}
return
rv;
}
void
PDFEnvelopeOwner::clearEnvelopes
()
{
menvelope.
clear
();
}
}
//
namespace srreal
}
//
namespace diffpy
//
Serialization -------------------------------------------------------------
DIFFPY_INSTANTIATE_PTR_SERIALIZATION
(diffpy::srreal::PDFEnvelope)
//
End of file
Back
|
FazBrowse Home
|
New Git URL