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