Lagrange
Toggle main menu visibility
Main Website
Quick Links
Modules
Namespaces
Namespace List
Namespace Members
All
a
b
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
t
u
v
w
Functions
a
b
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
t
u
v
w
Typedefs
Enumerations
Enumerator
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
~
Functions
_
a
b
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
t
u
v
w
~
Variables
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
Typedefs
Enumerations
Enumerator
•
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Modules
Pages
PyAttribute.h
1
/*
2
* Copyright 2022 Adobe. All rights reserved.
3
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License. You may obtain a copy
5
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6
*
7
* Unless required by applicable law or agreed to in writing, software distributed under
8
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
* OF ANY KIND, either express or implied. See the License for the specific language
10
* governing permissions and limitations under the License.
11
*/
12
#pragma once
13
14
#include <lagrange/Attribute.h>
15
#include <lagrange/AttributeTypes.h>
16
#include <lagrange/internal/weak_ptr.h>
17
#include <lagrange/utils/Error.h>
18
19
#include <memory>
20
21
namespace
lagrange::python {
22
23
class
PyAttribute
24
{
25
public
:
26
PyAttribute
(
internal::weak_ptr<AttributeBase>
ptr)
27
: m_attr(ptr)
28
{}
29
30
public
:
31
internal::shared_ptr<AttributeBase>
operator->() {
return
ptr(); }
32
33
internal::shared_ptr<AttributeBase>
ptr()
34
{
35
auto
attr = m_attr.lock();
36
if
(attr ==
nullptr
)
throw
Error
(
"Attribute is no longer valid!"
);
37
return
attr;
38
}
39
40
template
<
typename
ValueType>
41
internal::shared_ptr<Attribute<ValueType>
> ptr()
42
{
43
auto
attr = m_attr.lock();
44
if
(attr ==
nullptr
)
throw
Error
(
"Attribute is no longer valid!"
);
45
return
internal::shared_ptr<Attribute<ValueType>
>(
46
attr,
47
dynamic_cast<
Attribute<ValueType>
*
>
(attr.get()));
48
}
49
50
template
<
typename
CallBack>
51
auto
process(CallBack&& cb)
52
{
53
#define LA_X_process(_, ValueType) \
54
{ \
55
auto attr = ptr<ValueType>(); \
56
if (attr != nullptr) { \
57
return cb(*attr); \
58
} \
59
}
60
LA_ATTRIBUTE_X
(process, 0)
61
#undef LA_X_process
62
throw
Error
(
"Cannot process attribute with unsupported type!"
);
63
}
64
65
private
:
66
::lagrange::internal::weak_ptr<AttributeBase>
m_attr;
67
};
68
69
}
// namespace lagrange::python
lagrange::Attribute< ValueType >
lagrange::internal::shared_ptr
NOT implemented: custom allocator support.
Definition:
shared_ptr.h:110
lagrange::internal::weak_ptr
Definition:
weak_ptr.h:26
lagrange::python::PyAttribute
Definition:
PyAttribute.h:24
LA_ATTRIBUTE_X
#define LA_ATTRIBUTE_X(mode, data)
X Macro arguments for the Attribute<> class.
Definition:
AttributeTypes.h:48
lagrange::Error
Base exception for errors thrown by Lagrange functions.
Definition:
Error.h:27
python
src
PyAttribute.h
Generated by
1.9.4