memory leak fix
[platform/framework/native/uix.git] / src / FUixSensorTiltSensorData.cpp
1 // 
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd. 
4 // 
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file     FUixSensorTiltSensorData.cpp
20  * @brief    This is the implementation file for the %TiltSensorData class.
21  *
22  * This files contains implementation of the %TiltSensorData class.
23  */
24
25 // Includes
26 #include <FBaseErrors.h>
27 #include <FBaseSysLog.h>
28 #include <FBaseFloat.h>
29 #include <FBaseLongLong.h>
30
31 #include <FUixSensorTiltSensorData.h>
32 #include "FUixSensor_SensorUtil.h"
33
34 using namespace Tizen::Base;
35
36 namespace Tizen { namespace Uix { namespace Sensor
37 {
38 namespace
39 {
40 static const wchar_t W_MSG_INVALID_SENSOR_DATA_KEY[] = L"A data matching the specified key and data type cannot be found.";
41 } // Anonymous
42
43 TiltSensorData::TiltSensorData(void)
44         : roll(0.0F)
45         , pitch(0.0F)
46         , azimuth(0.0F)
47 {
48
49 }
50
51 TiltSensorData::~TiltSensorData(void)
52 {
53
54 }
55
56 TiltSensorData::TiltSensorData(const TiltSensorData& rhs)
57         :azimuth(rhs.azimuth)
58         ,roll(rhs.roll)
59         ,pitch(rhs.pitch)
60 {
61
62 }
63
64 TiltSensorData&
65 TiltSensorData::operator =(const TiltSensorData& rhs)
66 {
67         // check for self-assignment
68         if (this != &rhs)
69         {
70                 timestamp = rhs.timestamp;
71                 azimuth = rhs.azimuth;
72                 roll = rhs.roll;
73                 pitch = rhs.pitch;
74         }
75
76         return *this;
77 }
78
79 int
80 TiltSensorData::GetHashCode(void) const
81 {
82         int hash = 0;
83
84                 hash += LongLong::GetHashCode(this->timestamp);
85                 hash += Float::GetHashCode(this->azimuth);
86                 hash += Float::GetHashCode(this->roll);
87                 hash += Float::GetHashCode(this->pitch);
88
89                 return hash;
90 }
91
92 bool
93 TiltSensorData::Equals(const Object& rhs) const
94 {
95         const TiltSensorData* pRhs = dynamic_cast <const TiltSensorData*>(&rhs);
96         if (pRhs == null)
97         {
98                 return false;
99         }
100
101         if (this->timestamp != pRhs->timestamp)
102         {
103                 return false;
104         }
105
106         if (this->azimuth != pRhs->azimuth)
107         {
108                 return false;
109         }
110
111         if (this->roll != pRhs->roll)
112         {
113                 return false;
114         }
115
116         if (this->pitch != pRhs->pitch)
117         {
118                 return false;
119         }
120
121
122         return true;
123 }
124
125 result
126 TiltSensorData::GetValue(SensorDataKey dataKey, long& value) const
127 {
128         switch (static_cast<TiltDataKey>(dataKey))
129         {
130         case TILT_DATA_KEY_TIMESTAMP:
131                 value = _SensorUtil::CutTimestamp(timestamp);
132                 break;
133         default:
134                 SysLogException(NID_UIX, E_INVALID_ARG, "[%s] %ls", GetErrorMessage(E_INVALID_ARG), W_MSG_INVALID_SENSOR_DATA_KEY);
135                 return E_INVALID_ARG;
136         }
137
138         return E_SUCCESS;
139 }
140
141 result
142 TiltSensorData::GetValue(SensorDataKey dataKey, float& value) const
143 {
144         switch (static_cast<TiltDataKey>(dataKey))
145         {
146         case TILT_DATA_KEY_ROLL:
147                 value = roll;
148                 break;
149         case TILT_DATA_KEY_PITCH:
150                 value = pitch;
151                 break;
152         case TILT_DATA_KEY_AZIMUTH:
153                 value = azimuth;
154                 break;
155         default:
156                 SysLogException(NID_UIX, E_INVALID_ARG, "[%s] %ls", GetErrorMessage(E_INVALID_ARG), W_MSG_INVALID_SENSOR_DATA_KEY);
157                 return E_INVALID_ARG;
158         }
159
160         return E_SUCCESS;
161 }
162
163 result
164 TiltSensorData::GetValue(SensorDataKey dataKey, bool& value) const
165 {
166         SysLogException(NID_UIX, E_INVALID_ARG, "[%s] %ls", GetErrorMessage(E_INVALID_ARG), W_MSG_INVALID_SENSOR_DATA_KEY);
167         return E_INVALID_ARG;
168 }
169 } } }// Tizen::Uix::Sensor