Merge "Beautified source code of appfw/inc" into tizen_2.2
[platform/framework/native/appfw.git] / inc / FIoFileAttributes.h
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        FIoFileAttributes.h
19  * @brief       This is the header file for the %FileAttributes class.
20  *
21  * This header file contains the declarations of the %FileAttributes class.
22  */
23
24 #ifndef _FIO_FILE_ATTRIBUTES_H_
25 #define _FIO_FILE_ATTRIBUTES_H_
26
27 #include <FBaseObject.h>
28
29 namespace Tizen { namespace Base
30 {
31 class DateTime;
32 }}
33
34 namespace Tizen { namespace Io
35 {
36
37 /**
38  * @class       FileAttributes
39  * @brief       This class provides a collection of basic file attributes.
40  *
41  * @since       2.0
42  *
43  * @final       This class is not intended for extension.
44  *
45  * The %FileAttributes class provides the attributes of a file or directory.
46  * It can be used to determine the various file properties such as file attributes
47  * (read-only, hidden, system, or directory), creation time, last modified time, and file size.
48  *
49  * For more information on the class features,
50  * see <a href="../org.tizen.native.appprogramming/html/guide/io/io_namespace.htm">Io Guide</a>.
51  *
52  * The following example demonstrates how to use the %FileAttributes class.
53  *
54  * @code
55 #include <FBase.h>
56 #include <FIo.h>
57
58 using namespace Tizen::Base;
59 using namespace Tizen::Io;
60
61 int main(void)
62 {
63         String fileName(L"test.txt");
64         File file;
65         FileAttributes attr;
66         long long size;
67         DateTime dtCreate ;
68         DateTime dtModified ;
69         result r = E_SUCCESS;
70
71         r = File::GetAttributes(App::GetInstance()->GetAppDataPath() + fileName, attr);
72         if (IsFailed(r))
73         {
74                 goto CATCH;
75         }
76
77         size = attr.GetFileSize();
78         AppLog("* size=%d", size);
79
80         dtCreate = attr.GetDateTime();
81         AppLog("* creation time: %d year, %d month, %d day, %d hour, %d min, %d sec.\n",
82                 dtCreate.GetYear(),
83                 dtCreate.GetMonth(),
84                 dtCreate.GetDay(),
85                 dtCreate.GetHour(),
86                 dtCreate.GetMinute(),
87                 dtCreate.GetSecond()
88         );
89
90         dtModified = attr.GetLastModifiedTime();
91         AppLog("* last modified time: %d year, %d month, %d day, %d hour, %d min, %d sec.\n",
92                 dtModified.GetYear(),
93                 dtModified.GetMonth(),
94                 dtModified.GetDay(),
95                 dtModified.GetHour(),
96                 dtModified.GetMinute(),
97                 dtModified.GetSecond()
98         );
99
100         if (attr.IsDirectory())
101         {
102                 AppLog("* This is a directory.");
103         }
104         if (attr.IsHidden())
105         {
106                 AppLog("* This is a hidden file.");
107         }
108         if (attr.IsReadOnly())
109         {
110                 AppLog("* This is a read-only file.");
111         }
112
113         AppLog("Succeeded!");
114         return 0;
115
116 CATCH:
117         AppLog("Failed...");
118         return -1;
119 }
120  * @endcode
121  */
122 class _OSP_EXPORT_ FileAttributes
123         : public Tizen::Base::Object
124 {
125
126 public:
127         /**
128         * This is the default constructor for this class.
129         *
130         * @since                2.0
131         */
132         FileAttributes(void);
133
134         /**
135         * This destructor overrides Tizen::Base::Object::~Object().
136         *
137         * @since                2.0
138         */
139         virtual ~FileAttributes(void);
140
141         /**
142         * Copying of objects using this copy constructor is allowed.
143         *
144         * @since                2.0
145         *
146         * @param[in]    rhs             An instance of %FileAttributes
147         */
148         FileAttributes(const FileAttributes& rhs);
149
150         /**
151         * Assigns the value of the specified instance to the current instance of %FileAttributes.
152         *
153         * @since                2.0
154         *
155         * @return               The reference of this instance
156         * @param[in]    rhs             An instance of %FileAttributes
157         */
158         FileAttributes& operator =(const FileAttributes& rhs);
159
160         /**
161         * Compares the specified instance of Object to the calling instance of %FileAttributes.
162         *
163         * @since                2.0
164         *
165         * @return               @c true if the values of the specified instance equals the values of the current instance, @n
166         *                               else @c false
167         * @param[in]    object          The object to compare with the current instance
168         */
169         virtual bool Equals(const Tizen::Base::Object& object) const;
170
171         /**
172         * Gets the hash value of the current instance.
173         *
174         * @since                2.0
175         *
176         * @return               An integer value indicating the hash value of the current instance
177         */
178         virtual int GetHashCode(void) const;
179
180         /**
181         * Gets the file size.
182         *
183         * @since                2.0
184         *
185         * @return               The file size in bytes
186         */
187         long long GetFileSize(void) const;
188
189         /**
190         * Checks whether the current file is a directory.
191         *
192         * @since                2.0
193         *
194         * @return               @c true if the file is a directory, @n
195         *                               else @c false
196         */
197         bool IsDirectory(void) const;
198
199         /**
200         * Checks whether the file has a hidden attribute.
201         *
202         * @since                2.0
203         *
204         * @return               @c true if the file has a hidden attribute, @n
205         *                               else @c false
206         */
207         bool IsHidden(void) const;
208
209         /**
210         * Checks whether the file has a read-only attribute.
211         *
212         * @since                2.0
213         *
214         * @return               @c true if the file has a read-only attribute, @n
215         *                               else @c false
216         */
217         bool IsReadOnly(void) const;
218
219         /**
220         * Gets the date and time of the last modification to the file.
221         *
222         * @since                2.0
223         *
224         * @return               The date and time of the last modification to the file
225         */
226         Tizen::Base::DateTime GetDateTime(void) const;
227
228         /**
229         * Gets the date and time of the last modification to the file.
230         *
231         * @since                2.0
232         *
233         * @return               The date and time of the last modification to the file
234         */
235         Tizen::Base::DateTime GetLastModifiedTime(void) const;
236
237 private:
238         class _FileAttributesImpl* __pFileAttributesImpl;
239
240         friend class _FileAttributesImpl;
241
242 }; // FileAttributes
243
244 }} // Tizen::Io
245
246 #endif //_FIO_FILE_ATTRIBUTES_H_
247