Merge "Fixed Klocworks issues" into devel_3.0_main
[platform/framework/native/appfw.git] / src / io / FIo_DirEntryImpl.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file        FIo_DirEntryImpl.cpp
19  * @brief       This is the implementation file for _DirEntryImpl class.
20  */
21
22 #include <unique_ptr.h>
23 #include <FBaseString.h>
24 #include <FBaseDateTime.h>
25 #include <FIoDirEntry.h>
26 #include <FBaseSysLog.h>
27
28 #include <FBase_NativeError.h>
29 #include <FIo_DirEntryImpl.h>
30
31 using namespace Tizen::Base;
32
33 namespace Tizen { namespace Io
34 {
35
36 _DirEntryImpl::_DirEntryImpl(void)
37         : __fileSize(0)
38         , __directory(false)
39         , __hidden(false)
40         , __readOnly(false)
41 {
42 }
43
44 _DirEntryImpl::~_DirEntryImpl(void)
45 {
46 }
47
48 _DirEntryImpl*
49 _DirEntryImpl::GetInstance(DirEntry* pDirEntry)
50 {
51         if (pDirEntry)
52         {
53                 return pDirEntry->__pDirEntryImpl;
54         }
55
56         return null;
57 }
58
59 const _DirEntryImpl*
60 _DirEntryImpl::GetInstance(const DirEntry* pDirEntry)
61 {
62         if (pDirEntry)
63         {
64                 return pDirEntry->__pDirEntryImpl;
65         }
66
67         return null;
68 }
69
70 _DirEntryImpl::_DirEntryImpl(const _DirEntryImpl& dirEntryImpl)
71         : __directory(false)
72         , __hidden(false)
73         , __readOnly(false)
74 {
75         __dateTime = dirEntryImpl.__dateTime;
76         __fileSize = dirEntryImpl.__fileSize;
77         __name = dirEntryImpl.__name;
78         __directory = dirEntryImpl.__directory;
79         __hidden = dirEntryImpl.__hidden;
80         __readOnly = dirEntryImpl.__readOnly;
81 }
82
83 _DirEntryImpl&
84 _DirEntryImpl::operator =(const _DirEntryImpl& dirEntryImpl)
85 {
86         if (&dirEntryImpl != this)
87         {
88                 __dateTime = dirEntryImpl.__dateTime;
89                 __fileSize = dirEntryImpl.__fileSize;
90                 __name = dirEntryImpl.__name;
91                 __directory = dirEntryImpl.__directory;
92                 __hidden = dirEntryImpl.__hidden;
93                 __readOnly = dirEntryImpl.__readOnly;
94         }
95
96         return *this;
97 }
98
99 bool
100 _DirEntryImpl::Equals(const Object& object) const
101 {
102         const _DirEntryImpl* pOther = dynamic_cast< const _DirEntryImpl* >(&object);
103         if (pOther == null)
104         {
105                 return false;
106         }
107
108         if (__dateTime == pOther->__dateTime && __fileSize == pOther->__fileSize &&
109                         __name == pOther->__name && __directory == pOther->__directory &&
110                         __hidden == pOther->__hidden && __readOnly == pOther->__readOnly)
111         {
112                 return true;
113         }
114
115         return false;
116 }
117
118 int
119 _DirEntryImpl::GetHashCode(void) const
120 {
121         String hashCode;
122
123         hashCode.Append(__dateTime.ToString());
124         hashCode.Append(static_cast< long >(__fileSize));
125         hashCode.Append(__name);
126         hashCode.Append(static_cast< int >(__directory));
127         hashCode.Append(static_cast< int >(__hidden));
128         hashCode.Append(static_cast< int >(__readOnly));
129
130         return hashCode.GetHashCode();
131 }
132
133 const Tizen::Base::String
134 _DirEntryImpl::GetName(void) const
135 {
136         SetLastResult(E_SUCCESS);
137         return __name;
138 }
139
140 unsigned long
141 _DirEntryImpl::GetFileSize(void) const
142 {
143         SetLastResult(E_SUCCESS);
144         return static_cast< unsigned long >(__fileSize);
145 }
146
147 bool
148 _DirEntryImpl::IsDirectory(void) const
149 {
150         SetLastResult(E_SUCCESS);
151         return __directory;
152 }
153
154 bool
155 _DirEntryImpl::IsHidden(void) const
156 {
157         SetLastResult(E_SUCCESS);
158         return __hidden;
159 }
160
161 bool
162 _DirEntryImpl::IsReadOnly(void) const
163 {
164         SetLastResult(E_SUCCESS);
165         return __readOnly;
166 }
167
168 Tizen::Base::DateTime
169 _DirEntryImpl::GetDateTime(void) const
170 {
171         SetLastResult(E_SUCCESS);
172         return __dateTime;
173 }
174
175 void
176 _DirEntryImpl::Set(DateTime dateTime, off64_t fileSize, String name,
177                 bool dir, bool readOnly, bool hidden)
178 {
179         __dateTime = dateTime;
180         __fileSize = fileSize;
181         __name = name;
182         __directory = dir;
183         __readOnly = readOnly;
184         __hidden = hidden;
185 }
186
187 DirEntry*
188 _DirEntryImpl::CreateDirEntryInstanceN(void)
189 {
190         std::unique_ptr<DirEntry> pDirEntry(new (std::nothrow) DirEntry());
191         SysTryReturn(NID_IO, pDirEntry != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
192         return pDirEntry.release();
193 }
194
195 }} // Tizen::Io
196