Nyx Node
Toggle main menu visibility
Loading...
Searching...
No Matches
json_number.py
1
# -*- coding: utf-8 -*-
2
########################################################################################################################
3
# NyxNode
4
# Author: Jérôme ODIER <jerome.odier@lpsc.in2p3.fr>
5
# SPDX-License-Identifier: GPL-3.0+
6
########################################################################################################################
7
8
from
..
import
bind
9
from
..
import
obj
10
11
########################################################################################################################
12
13
class
NyxNumber
(
obj.NyxObject
):
14
"""!
15
@brief JSON number object.
16
"""
17
18
####################################################################################################################
19
20
def
__init__
(self, value: int | float |
None
=
None
, ptr: int |
None
=
None
):
21
"""!
22
@brief Allocates a new JSON number object or wraps one.
23
24
@param value Optional default value.
25
@param ptr Optional JSON number object pointer.
26
"""
27
28
################################################################################################################
29
30
if
ptr
is
None
:
31
32
ptr = bind.lib.nyx_number_new()
33
34
elif
bind.lib.nyx_object_get_type(ptr) != bind.NyxObjectType.NUMBER:
35
36
raise
TypeError(
'Not a pointer to a Nyx number object'
)
37
38
################################################################################################################
39
40
super().
__init__
(ptr)
41
42
################################################################################################################
43
44
if
isinstance(value, (int, float)):
45
46
self.
value
= float(value)
47
48
####################################################################################################################
49
50
@property
51
def
value(self) -> float:
52
"""!
53
@brief Gets the value of this JSON number object.
54
55
@return The current value.
56
"""
57
58
return
float(bind.lib.nyx_number_get(self.
ptr
))
59
60
####################################################################################################################
61
62
@value.setter
63
def
value(self, value: float) -> bool:
64
"""!
65
@brief Sets the value of this JSON number object.
66
67
@return @c True if the value was modified, @c False otherwise.
68
"""
69
70
return
bool(bind.lib.nyx_number_set(self.
ptr
, float(value)))
71
72
########################################################################################################################
73
74
__all__ = [
'NyxNumber'
]
75
76
########################################################################################################################
nyx.json.json_number.NyxNumber
JSON number object.
Definition
json_number.py:13
nyx.json.json_number.NyxNumber.__init__
__init__(self, int|float|None value=None, int|None ptr=None)
Allocates a new JSON number object or wraps one.
Definition
json_number.py:20
nyx.json.json_number.NyxNumber.value
value
Definition
json_number.py:46
nyx.obj.NyxObject
Base class for JSON Nyx objects.
Definition
obj.py:44
Author:
Jérôme ODIER
License:
LGPL-3.0-or-later
Copyright:
LPSC / CNRS