4980938d46607e9ecb130809980d193462ce6c5b
[platform/framework/native/appfw.git] / inc / FIoDirEntry.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        FIoDirEntry.h
19  * @brief       This is the header file for the %DirEntry class.
20  *
21  * This header file contains the declarations of the %DirEntry class.
22  */
23
24 #ifndef _FIO_DIR_ENTRY_H_
25 #define _FIO_DIR_ENTRY_H_
26
27 #include <FBaseObject.h>
28
29 namespace Tizen { namespace Base
30 {
31 class String;
32 class DateTime;
33 }}
34
35 namespace Tizen { namespace Io
36 {
37
38 /**
39  * @class       DirEntry
40  * @brief       This class stores the information about each directory entry.
41  *
42  * @since       2.0
43  *
44  * @final       This class is not intended for extension.
45  *
46  * The %DirEntry class stores the information about each directory entry.
47  *
48  * For more information on the class features,
49  * see <a href="../org.tizen.native.appprogramming/html/guide/io/io_namespace.htm">Io Guide</a>.
50  *
51  * @see         Tizen::Io::Directory
52  * @see     Tizen::Io::File
53  *
54  * The following example demonstrates how to use the %DirEntry class.
55  *
56  * @code
57
58 #include <FBase.h>
59 #include <FIo.h>
60
61 using namespace Tizen::Base;
62 using namespace Tizen::Io;
63
64 int main(void)
65 {
66         String dirName(L"test");
67         Directory dir;
68         DirEnumerator *pDirEnum = null;
69         String name;
70         Tizen::Base::DateTime dt;
71         result r = E_SUCCESS;
72
73         // Open the directory
74         r = dir.Construct(App::GetInstance()->GetAppDataPath() + dirName);
75         if (IsFailed(r))
76         {
77                 goto CATCH;
78         }
79
80         // Read all the directory entries
81         pDirEnum = dir.ReadN();
82         if (!pDirEnum)
83         {
84                 goto CATCH;
85         }
86
87         // Loop through all the directory entries
88         while (pDirEnum->MoveNext() == E_SUCCESS)
89         {
90                 DirEntry dirEntry = pDirEnum->GetCurrentDirEntry();
91
92                 // Get several properties of each directory entry.
93                 name = dirEntry.GetName();
94
95                 name += L": size=";
96                 name += Long((long) dirEntry.GetFileSize()).ToString();
97
98                 if (dirEntry.IsDirectory())
99                 {
100                         name += L", [directory]";
101                 }
102                 if (dirEntry.IsReadOnly())
103                 {
104                         name += L", [read-only]";
105                 }
106                 if (dirEntry.IsHidden())
107                 {
108                         name += L", [hidden]";
109                 }
110
111                 dt = dirEntry.GetDateTime();
112
113                 name += L", year=";
114                 name += dt.GetYear();
115
116                 name += L", month=";
117                 name += dt.GetMonth();
118
119                 name += L", day=";
120                 name += dt.GetDay();
121
122                 name += L", hour=";
123                 name += dt.GetHour();
124
125                 name += L", min=";
126                 name += dt.GetMinute();
127
128                 name += L", second=";
129                 name += dt.GetSecond();
130
131                 // Print out message...
132         }
133
134         // Delete the enumerator
135         delete pDirEnum;
136
137         AppLog("Succeeded");
138
139         // The opened directory is closed automatically when the destructor of Directory class is invoked
140         return 0;
141
142 CATCH:
143         if (pDirEnum)
144         {
145                 delete pDirEnum;
146         }
147         AppLog("Failed...");
148         return -1;
149 }
150  * @endcode
151  */
152 class _OSP_EXPORT_ DirEntry
153         : public Tizen::Base::Object
154 {
155
156 public:
157         /**
158         * This destructor overrides Tizen::Base::Object::~Object().
159         *
160         * @since        2.0
161         */
162         virtual ~DirEntry(void);
163
164         /**
165         * Copying of objects using this copy constructor is allowed.
166         *
167         * @since                2.0
168         *
169         * @param[in]    rhs             An instance of %DirEntry
170         */
171         DirEntry(const DirEntry& rhs);
172
173         /**
174         * Assigns the value of the specified instance to the current instance of %DirEntry.
175         *
176         * @since                2.0
177         *
178         * @return               A reference to the calling instance
179         * @param[in]    rhs             An instance of %DirEntry
180         */
181         DirEntry& operator =(const DirEntry& rhs);
182
183         /**
184         * Compares the specified instance of Object to the calling instance of %DirEntry.
185         *
186         * @since                2.0
187         *
188         * @return               @c true if the values of the specified instance equals the values of the current instance, @n
189         *                               else @c false
190         * @param[in]    object          The object to compare with the current instance
191         */
192         virtual bool Equals(const Object& object) const;
193
194         /**
195         * Gets the hash value of the current instance.
196         *
197         * @since                2.0
198         *
199         * @return               An integer value indicating the hash value of the current instance
200         */
201         virtual int GetHashCode(void) const;
202
203         /**
204         * Gets the name of this directory entry.
205         *
206         * @since                2.0
207         *
208         * @return               The name of this directory entry
209         */
210         const Tizen::Base::String GetName(void) const;
211
212         /**
213         * Gets the file size of this directory entry.
214         *
215         * @since                2.0
216         *
217         * @return               The file size of this directory entry
218         */
219         unsigned long GetFileSize(void) const;
220
221         /**
222         * Checks whether the current %DirEntry instance is a directory.
223         *
224         * @since                2.0
225         *
226         * @return               @c true if it is a directory, @n
227         *                               else @c false
228         */
229         bool IsDirectory(void) const;
230
231         /**
232         * Checks whether a file has a hidden attribute.
233         *
234         * @since                2.0
235         *
236         * @return               @c true if the file has a hidden attribute, @n
237         *                               else @c false
238         */
239         bool IsHidden(void) const;
240
241         /**
242         * Checks whether a file has a read-only attribute.
243         *
244         * @since                2.0
245         *
246         * @return               @c true if the file has a read-only attribute, @n
247         *                               else @c false
248         */
249         bool IsReadOnly(void) const;
250
251         /**
252         * Gets the date and time of the last modification of the directory entry.
253         *
254         * @since                2.0
255         *
256         * @return               The date and time of the last modification
257         */
258         Tizen::Base::DateTime GetDateTime(void) const;
259
260 private:
261         /**
262         * This default constructor is intentionally declared as private so that only the platform can create an instance.
263         *
264         * @since    2.0
265         */
266         DirEntry(void);
267
268         class _DirEntryImpl* __pDirEntryImpl;
269
270         friend class _DirEntryImpl;
271
272 }; // DirEntry
273
274 }} // Tizen::Io
275
276 #endif // _FIO_DIR_ENTRY_H_
277