~chasedouglas/frame/ubuntu-upstream-xi

« back to all changes in this revision

Viewing changes to src/v2/value.cpp

  • Committer: Chase Douglas
  • Date: 2011-12-09 01:36:45 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: chase.douglas@ubuntu.com-20111209013645-n24l4myiumblzsfu
* New upstream release.
  - Version 2 adds a new API built on top of XInput multitouch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 *
 
3
 * utouch-frame - Touch Frame Library
 
4
 *
 
5
 * Copyright (C) 2011 Canonical Ltd.
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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/>.
 
19
 *
 
20
 ****************************************************************************/
 
21
 
 
22
#include "v2/value.h"
 
23
 
 
24
#include <stdlib.h>
 
25
#include <string.h>
 
26
 
 
27
#include "v2/device.h"
 
28
#include "v2/frame.h"
 
29
 
 
30
namespace utouch {
 
31
namespace frame {
 
32
 
 
33
Value::Value(bool value) : type_(kBool), bool_(value) {
 
34
}
 
35
 
 
36
Value::Value(int value) : type_(kInt), int_(value) {
 
37
}
 
38
 
 
39
Value::Value(unsigned int value) : type_(kUnsignedInt), unsigned_int_(value) {
 
40
}
 
41
 
 
42
Value::Value(float value) : type_(kFloat), float_(value) {
 
43
}
 
44
 
 
45
#ifdef HAVE_LONG_UNSIGNED_VALUE
 
46
Value::Value(long unsigned int value)
 
47
    : type_(kLongUnsignedInt),
 
48
      long_unsigned_int_(value) {
 
49
}
 
50
#endif // HAVE_LONG_UNSIGNED_VALUE
 
51
 
 
52
Value::Value(uint64_t value) : type_(kuint64_t), uint64_t_(value) {
 
53
}
 
54
 
 
55
Value::Value(const char* value) : type_(kString), string_(strdup(value)) {
 
56
}
 
57
 
 
58
Value::Value(const SharedUFDevice& device)
 
59
    : type_(kSharedDevice),
 
60
      device_(new SharedUFDevice(device)) {
 
61
}
 
62
 
 
63
Value::Value(const SharedUFFrame& frame)
 
64
    : type_(kSharedFrame),
 
65
      frame_(new SharedUFFrame(frame)) {
 
66
}
 
67
 
 
68
Value::Value(const Value& value)
 
69
    : type_(value.type_),
 
70
      any_(value.any_) {
 
71
  switch (type_) {
 
72
    case kString:
 
73
      string_ = strdup(value.string_);
 
74
      break;
 
75
 
 
76
    case kSharedDevice:
 
77
      device_ = new SharedUFDevice(*value.device_);
 
78
      break;
 
79
 
 
80
    case kSharedFrame:
 
81
      frame_ = new SharedUFFrame(*value.frame_);
 
82
      break;
 
83
 
 
84
    default:
 
85
      break;
 
86
  }
 
87
}
 
88
 
 
89
void Value::GetValue(void* data) const {
 
90
  switch (type_) {
 
91
    case kBool:
 
92
      *reinterpret_cast<int*>(data) = bool_;
 
93
      break;
 
94
 
 
95
    case kInt:
 
96
      *reinterpret_cast<int*>(data) = int_;
 
97
      break;
 
98
 
 
99
    case kUnsignedInt:
 
100
      *reinterpret_cast<unsigned int*>(data) = unsigned_int_;
 
101
      break;
 
102
 
 
103
    case kFloat:
 
104
      *reinterpret_cast<float*>(data) = float_;
 
105
      break;
 
106
 
 
107
#ifdef HAVE_LONG_UNSIGNED_VALUE
 
108
    case kLongUnsignedInt:
 
109
      *reinterpret_cast<long unsigned int*>(data) = long_unsigned_int_;
 
110
      break;
 
111
#endif // HAVE_LONG_UNSIGNED_VALUE
 
112
 
 
113
    case kuint64_t:
 
114
      *reinterpret_cast<uint64_t*>(data) = uint64_t_;
 
115
      break;
 
116
 
 
117
    case kString:
 
118
      *reinterpret_cast<const char**>(data) = string_;
 
119
      break;
 
120
 
 
121
    case kSharedDevice:
 
122
      *reinterpret_cast< ::UFDevice*>(data) = device_->get();
 
123
      break;
 
124
 
 
125
    case kSharedFrame:
 
126
      *reinterpret_cast< ::UFFrame*>(data) = frame_->get();
 
127
      break;
 
128
  }
 
129
}
 
130
 
 
131
Value::~Value() {
 
132
  switch (type_) {
 
133
    case kString:
 
134
      free(const_cast<char*>(string_));
 
135
      break;
 
136
 
 
137
    case kSharedDevice:
 
138
      delete device_;
 
139
      break;
 
140
 
 
141
    case kSharedFrame:
 
142
      delete frame_;
 
143
      break;
 
144
 
 
145
    default:
 
146
      break;
 
147
  }
 
148
}
 
149
 
 
150
} // namespace frame
 
151
} // namespace utouch