1
/*****************************************************************************
3
* utouch-frame - Touch Frame Library
5
* Copyright (C) 2011 Canonical Ltd.
7
* This program is free software: you can redistribute it and/or modify it
8
* under the terms of the GNU General Public License as published by the
9
* Free Software Foundation, either version 3 of the License, or (at your
10
* option) any later version.
12
* This program is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* General Public License for more details.
17
* You should have received a copy of the GNU General Public License along
18
* with this program. If not, see <http://www.gnu.org/licenses/>.
20
****************************************************************************/
27
#include "v2/device.h"
33
Value::Value(bool value) : type_(kBool), bool_(value) {
36
Value::Value(int value) : type_(kInt), int_(value) {
39
Value::Value(unsigned int value) : type_(kUnsignedInt), unsigned_int_(value) {
42
Value::Value(float value) : type_(kFloat), float_(value) {
45
#ifdef HAVE_LONG_UNSIGNED_VALUE
46
Value::Value(long unsigned int value)
47
: type_(kLongUnsignedInt),
48
long_unsigned_int_(value) {
50
#endif // HAVE_LONG_UNSIGNED_VALUE
52
Value::Value(uint64_t value) : type_(kuint64_t), uint64_t_(value) {
55
Value::Value(const char* value) : type_(kString), string_(strdup(value)) {
58
Value::Value(const SharedUFDevice& device)
59
: type_(kSharedDevice),
60
device_(new SharedUFDevice(device)) {
63
Value::Value(const SharedUFFrame& frame)
64
: type_(kSharedFrame),
65
frame_(new SharedUFFrame(frame)) {
68
Value::Value(const Value& value)
73
string_ = strdup(value.string_);
77
device_ = new SharedUFDevice(*value.device_);
81
frame_ = new SharedUFFrame(*value.frame_);
89
void Value::GetValue(void* data) const {
92
*reinterpret_cast<int*>(data) = bool_;
96
*reinterpret_cast<int*>(data) = int_;
100
*reinterpret_cast<unsigned int*>(data) = unsigned_int_;
104
*reinterpret_cast<float*>(data) = float_;
107
#ifdef HAVE_LONG_UNSIGNED_VALUE
108
case kLongUnsignedInt:
109
*reinterpret_cast<long unsigned int*>(data) = long_unsigned_int_;
111
#endif // HAVE_LONG_UNSIGNED_VALUE
114
*reinterpret_cast<uint64_t*>(data) = uint64_t_;
118
*reinterpret_cast<const char**>(data) = string_;
122
*reinterpret_cast< ::UFDevice*>(data) = device_->get();
126
*reinterpret_cast< ::UFFrame*>(data) = frame_->get();
134
free(const_cast<char*>(string_));
151
} // namespace utouch