2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FIo_FileAttributesImpl.cpp
19 * @brief This is the implementation file for _FileAttributesImpl class.
22 #include <sys/types.h>
26 #include <FBaseString.h>
27 #include <FBaseResult.h>
29 #include <FBaseSysLog.h>
31 #include <FBase_StringConverter.h>
32 #include <FBase_NativeError.h>
33 #include <FIo_FileAttributesImpl.h>
35 using namespace Tizen::Base;
37 namespace Tizen { namespace Io
40 _FileAttributesImpl::_FileAttributesImpl(void)
48 _FileAttributesImpl::~_FileAttributesImpl(void)
52 _FileAttributesImpl::_FileAttributesImpl(const _FileAttributesImpl& fileAttributesImpl)
58 __fileSize = fileAttributesImpl.__fileSize;
59 __directory = fileAttributesImpl.__directory;
60 __hidden = fileAttributesImpl.__hidden;
61 __readOnly = fileAttributesImpl.__readOnly;
62 __creationTime = fileAttributesImpl.__creationTime;
63 __lastModifiedTime = fileAttributesImpl.__lastModifiedTime;
67 _FileAttributesImpl::operator =(const _FileAttributesImpl& fileAttributesImpl)
69 if (&fileAttributesImpl != this)
71 __fileSize = fileAttributesImpl.__fileSize;
72 __directory = fileAttributesImpl.__directory;
73 __hidden = fileAttributesImpl.__hidden;
74 __readOnly = fileAttributesImpl.__readOnly;
75 __creationTime = fileAttributesImpl.__creationTime;
76 __lastModifiedTime = fileAttributesImpl.__lastModifiedTime;
83 _FileAttributesImpl::GetInstance(FileAttributes& fileAttributes)
85 return fileAttributes.__pFileAttributesImpl;
88 const _FileAttributesImpl*
89 _FileAttributesImpl::GetInstance(const FileAttributes& fileAttributes)
91 return fileAttributes.__pFileAttributesImpl;
95 _FileAttributesImpl::Equals(const Object& object) const
97 const _FileAttributesImpl* pOther = dynamic_cast< const _FileAttributesImpl* >(&object);
103 if (__fileSize == pOther->__fileSize && __directory == pOther->__directory &&
104 __hidden == pOther->__hidden && __readOnly == pOther->__readOnly &&
105 __creationTime == pOther->__creationTime && __lastModifiedTime == pOther->__lastModifiedTime)
114 _FileAttributesImpl::GetHashCode(void) const
118 hashCode.Append(static_cast< long >(__fileSize));
119 hashCode.Append(static_cast< int >(__directory));
120 hashCode.Append(static_cast< int >(__hidden));
121 hashCode.Append(static_cast< int >(__readOnly));
122 hashCode.Append(__creationTime.ToString());
123 hashCode.Append(__lastModifiedTime.ToString());
125 return hashCode.GetHashCode();
129 _FileAttributesImpl::GetFileSize(void) const
131 SetLastResult(E_SUCCESS);
136 _FileAttributesImpl::GetDateTime(void) const
138 SetLastResult(E_SUCCESS);
139 return __creationTime;
143 _FileAttributesImpl::GetLastModifiedTime(void) const
145 SetLastResult(E_SUCCESS);
146 return __lastModifiedTime;
150 _FileAttributesImpl::IsDirectory(void) const
152 SetLastResult(E_SUCCESS);
157 _FileAttributesImpl::IsHidden(void) const
159 SetLastResult(E_SUCCESS);
164 _FileAttributesImpl::IsReadOnly(void) const
166 SetLastResult(E_SUCCESS);
171 _FileAttributesImpl::Set(const DateTime& dateTime, const DateTime& modifiedTime, off64_t fileSize,
172 unsigned long attribute, bool hidden)
174 __fileSize = fileSize;
175 __directory = S_ISDIR(attribute) ? true : false;
177 __readOnly = (attribute & (S_IWUSR)) ? false : true;
179 __creationTime = dateTime;
180 __lastModifiedTime = modifiedTime;
182 SetLastResult(E_SUCCESS);