1 #pragma once
2 
3 /** @file the_Foundation/fileinfo.h  File information.
4 
5 @authors Copyright (c) 2017 Jaakko Keränen <jaakko.keranen@iki.fi>
6 
7 @par License
8 
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
11 
12 1. Redistributions of source code must retain the above copyright notice, this
13    list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright notice,
15    this list of conditions and the following disclaimer in the documentation
16    and/or other materials provided with the distribution.
17 
18 <small>THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
22 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</small>
28 */
29 
30 #include "defs.h"
31 #include "string.h"
32 #include "object.h"
33 
34 iBeginPublic
35 
36 iDeclareClass(FileInfo)
37 iDeclareClass(DirFileInfo)
38 
39 iDeclareType(File)
40 iDeclareType(Time)
41 
42 iDeclareObjectConstructionArgs(FileInfo, const iString *path)
43 
44 iFileInfo * newCStr_FileInfo(const char *path);
45 
46 iBool       exists_FileInfo         (const iFileInfo *);
47 const iString * path_FileInfo       (const iFileInfo *);
48 size_t      size_FileInfo           (const iFileInfo *);
49 iBool       isDirectory_FileInfo    (const iFileInfo *);
50 iTime       lastModified_FileInfo   (const iFileInfo *);
51 
52 iBool       fileExists_FileInfo     (const iString *path);
53 iBool       fileExistsCStr_FileInfo (const char *path);
54 size_t      fileSize_FileInfo       (const iString *path);
55 size_t      fileSizeCStr_FileInfo   (const char *path);
56 
57 iDirFileInfo *  directoryContents_FileInfo  (const iFileInfo *);
58 
59 iFile *     open_FileInfo   (const iFileInfo *, int mode);
60 
cstrPath_FileInfo(const iFileInfo * d)61 iLocalDef const char *cstrPath_FileInfo(const iFileInfo *d) {
62     return cstr_String(path_FileInfo(d));
63 }
64 
cstrLocalPath_FileInfo(const iFileInfo * d)65 iLocalDef const char *cstrLocalPath_FileInfo(const iFileInfo *d) {
66     return cstrLocal_String(path_FileInfo(d));
67 }
68 
69 /*-------------------------------------------------------------------------------------*/
70 
71 iDeclareObjectConstructionArgs(DirFileInfo, const iString *path)
72 
73 iDirFileInfo *  newCStr_DirFileInfo     (const char *path);
74 
75 void            initInfo_DirFileInfo    (iDirFileInfo *, const iFileInfo *d);
76 
77 /** @name Iterators */
78 ///@{
79 iDeclareIterator(DirFileInfo, iDirFileInfo *)
80 struct IteratorImpl_DirFileInfo {
81     const iFileInfo *value;
82     iDirFileInfo *dir;
83 };
84 ///@}
85 
86 iEndPublic
87