YARP
Yet Another Robot Platform
NetUint16.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #include <yarp/os/NetUint16.h>
11 
12 #ifndef YARP_LITTLE_ENDIAN
13 
14 using namespace yarp;
15 using namespace yarp::os;
16 
17 
18 std::uint16_t NetUint16::swap(std::uint16_t x) const
19 {
20  return (x >> 8) | ((x << 8) & 0xff00);
21 }
22 
23 std::uint16_t NetUint16::get() const
24 {
25  return (std::uint16_t)swap(raw_value);
26 }
27 
28 void NetUint16::set(std::uint16_t v)
29 {
30  raw_value = (std::uint16_t)swap((std::uint16_t)v);
31 }
32 
34 {
35 }
36 
37 NetUint16::NetUint16(std::uint16_t val)
38 {
39  set(val);
40 }
41 
42 NetUint16::operator std::uint16_t() const
43 {
44  return get();
45 }
46 
47 std::uint16_t NetUint16::operator+(std::uint16_t v) const
48 {
49  return get() + v;
50 }
51 
52 std::uint16_t NetUint16::operator-(std::uint16_t v) const
53 {
54  return get() - v;
55 }
56 
57 std::uint16_t NetUint16::operator*(std::uint16_t v) const
58 {
59  return get() * v;
60 }
61 
62 std::uint16_t NetUint16::operator/(std::uint16_t v) const
63 {
64  return get() / v;
65 }
66 
67 void NetUint16::operator+=(std::uint16_t v)
68 {
69  set(get() + v);
70 }
71 
72 void NetUint16::operator-=(std::uint16_t v)
73 {
74  set(get() - v);
75 }
76 
77 void NetUint16::operator*=(std::uint16_t v)
78 {
79  set(get() * v);
80 }
81 
82 void NetUint16::operator/=(std::uint16_t v)
83 {
84  set(get() / v);
85 }
86 
87 void NetUint16::operator++(int)
88 {
89  set(get() + 1);
90 }
91 
92 void NetUint16::operator--(int)
93 {
94  set(get() - 1);
95 }
96 
97 
98 #endif // YARP_LITTLE_ENDIAN
operator*=
Vector & operator*=(Vector &a, double k)
Vector-scalar product operator (defined in Math.h).
Definition: math.cpp:148
operator+=
Vector & operator+=(Vector &a, const double &s)
Addition operator between a scalar and a vector (defined in Math.h).
Definition: math.cpp:41
NetUint16.h
operator/
Vector operator/(const Vector &a, const Vector &b)
Vector-vector element-wise division operator (defined in Math.h).
Definition: math.cpp:250
operator+
Vector operator+(const Vector &a, const double &s)
Mathematical operations.
Definition: math.cpp:30
operator/=
Vector & operator/=(Vector &a, const Vector &b)
Vector-vector element-wise division operator (defined in Math.h).
Definition: math.cpp:256
operator*
Vector operator*(double k, const Vector &b)
Scalar-vector product operator (defined in Math.h).
Definition: math.cpp:137
yarp::os
An interface to the operating system, including Port based communication.
Definition: AbstractCarrier.h:17
yarp::os::NetUint16
std::uint16_t NetUint16
Definition of the NetUint16 type.
Definition: NetUint16.h:33
operator-=
Vector & operator-=(Vector &a, const double &s)
Subtraction operator between a vector and a scalar (defined in Math.h).
Definition: math.cpp:96
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
operator-
Vector operator-(const Vector &a, const double &s)
Subtraction operator between a vector and a scalar (defined in Math.h).
Definition: math.cpp:81