Merge "fix memory leak" into tizen_2.1
[platform/framework/native/appfw.git] / src / io / FIo_DirEntryImpl.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        FIo_DirEntryImpl.cpp
20  * @brief       This is the implementation file for _DirEntryImpl class.
21  */
22
23 #include <unique_ptr.h>
24 #include <FBaseString.h>
25 #include <FBaseDateTime.h>
26 #include <FIoDirEntry.h>
27 #include <FBaseSysLog.h>
28
29 #include <FBase_NativeError.h>
30 #include <FIo_DirEntryImpl.h>
31
32 using namespace Tizen::Base;
33
34 namespace Tizen { namespace Io
35 {
36
37 _DirEntryImpl::_DirEntryImpl(void)
38         : __fileSize(0)
39         , __directory(false)
40         , __hidden(false)
41         , __readOnly(false)
42 {
43 }
44
45 _DirEntryImpl::~_DirEntryImpl(void)
46 {
47 }
48
49 _DirEntryImpl*
50 _DirEntryImpl::GetInstance(DirEntry* pDirEntry)
51 {
52         if (pDirEntry)
53         {
54                 return pDirEntry->__pDirEntryImpl;
55         }
56
57         return null;
58 }
59
60 const _DirEntryImpl*
61 _DirEntryImpl::GetInstance(const DirEntry* pDirEntry)
62 {
63         if (pDirEntry)
64         {
65                 return pDirEntry->__pDirEntryImpl;
66         }
67
68         return null;
69 }
70
71 _DirEntryImpl::_DirEntryImpl(const _DirEntryImpl& dirEntryImpl)
72         : __directory(false)
73         , __hidden(false)
74         , __readOnly(false)
75 {
76         __dateTime = dirEntryImpl.__dateTime;
77         __fileSize = dirEntryImpl.__fileSize;
78         __name = dirEntryImpl.__name;
79         __directory = dirEntryImpl.__directory;
80         __hidden = dirEntryImpl.__hidden;
81         __readOnly = dirEntryImpl.__readOnly;
82 }
83
84 _DirEntryImpl&
85 _DirEntryImpl::operator =(const _DirEntryImpl& dirEntryImpl)
86 {
87         if (&dirEntryImpl != this)
88         {
89                 __dateTime = dirEntryImpl.__dateTime;
90                 __fileSize = dirEntryImpl.__fileSize;
91                 __name = dirEntryImpl.__name;
92                 __directory = dirEntryImpl.__directory;
93                 __hidden = dirEntryImpl.__hidden;
94                 __readOnly = dirEntryImpl.__readOnly;
95         }
96
97         return *this;
98 }
99
100 bool
101 _DirEntryImpl::Equals(const Object& object) const
102 {
103         const _DirEntryImpl* pOther = dynamic_cast< const _DirEntryImpl* >(&object);
104         if (pOther == null)
105         {
106                 return false;
107         }
108
109         if (__dateTime == pOther->__dateTime && __fileSize == pOther->__fileSize &&
110                         __name == pOther->__name && __directory == pOther->__directory &&
111                         __hidden == pOther->__hidden && __readOnly == pOther->__readOnly)
112         {
113                 return true;
114         }
115
116         return false;
117 }
118
119 int
120 _DirEntryImpl::GetHashCode(void) const
121 {
122         String hashCode;
123
124         hashCode.Append(__dateTime.ToString());
125         hashCode.Append(static_cast< long >(__fileSize));
126         hashCode.Append(__name);
127         hashCode.Append(static_cast< int >(__directory));
128         hashCode.Append(static_cast< int >(__hidden));
129         hashCode.Append(static_cast< int >(__readOnly));
130
131         return hashCode.GetHashCode();
132 }
133
134 const Tizen::Base::String
135 _DirEntryImpl::GetName(void) const
136 {
137         SetLastResult(E_SUCCESS);
138         return __name;
139 }
140
141 unsigned long
142 _DirEntryImpl::GetFileSize(void) const
143 {
144         SetLastResult(E_SUCCESS);
145         return static_cast< unsigned long >(__fileSize);
146 }
147
148 bool
149 _DirEntryImpl::IsDirectory(void) const
150 {
151         SetLastResult(E_SUCCESS);
152         return __directory;
153 }
154
155 bool
156 _DirEntryImpl::IsHidden(void) const
157 {
158         SetLastResult(E_SUCCESS);
159         return __hidden;
160 }
161
162 bool
163 _DirEntryImpl::IsReadOnly(void) const
164 {
165         SetLastResult(E_SUCCESS);
166         return __readOnly;
167 }
168
169 Tizen::Base::DateTime
170 _DirEntryImpl::GetDateTime(void) const
171 {
172         SetLastResult(E_SUCCESS);
173         return __dateTime;
174 }
175
176 void
177 _DirEntryImpl::Set(DateTime dateTime, off64_t fileSize, String name,
178                 bool dir, bool readOnly, bool hidden)
179 {
180         __dateTime = dateTime;
181         __fileSize = fileSize;
182         __name = name;
183         __directory = dir;
184         __readOnly = readOnly;
185         __hidden = hidden;
186 }
187
188 DirEntry*
189 _DirEntryImpl::CreateDirEntryInstanceN(void)
190 {
191         std::unique_ptr<DirEntry> pDirEntry(new (std::nothrow) DirEntry());
192         SysTryReturn(NID_IO, pDirEntry != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
193         return pDirEntry.release();
194 }
195
196 }} // Tizen::Io
197