OSDN Git Service

Update TranslationsStatus.*
[winmerge-jp/winmerge-jp.git] / Src / files.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /** 
3  * @file  files.h
4  *
5  * @brief Declaration file for file routines
6  */
7 #pragma once
8
9 /**
10  * @brief File-operation return-statuses
11  * Note that FileLoadResult class has no instance data or methods.
12  * It is only a namespace for static methods & constants.
13  * Everything is public.
14  */
15 class FileLoadResult
16 {
17 public:
18 // Checking results
19         /**
20          * Is result an error?
21          * @param [in] flr Return value to test.
22          * @return true if return value is an error value.
23          */
24         static bool IsError(DWORD flr) { return Main(flr) == FRESULT_ERROR; }
25         /**
26          * Is result a success?
27          * @param [in] flr Return value to test.
28          * @return true if return value is an success value.
29          */
30         static bool IsOk(DWORD flr) { return Main(flr) == FRESULT_OK; }
31         /**
32          * Is result OK but file is impure?
33          * @param [in] flr Return value to test.
34          * @return true if return value is success and file is impure.
35          */
36         static bool IsOkImpure(DWORD flr) { return Main(flr) == FRESULT_OK_IMPURE; }
37         /**
38          * Is result binary file?
39          * @param [in] flr Return value to test.
40          * @return true if return value determines binary file.
41          */
42         static bool IsBinary(DWORD flr) { return Main(flr) == FRESULT_BINARY; }
43         /**
44          * Is result unpack error?
45          * @param [in] flr Return value to test.
46          * @return true if return value determines unpacking error.
47          */
48         static bool IsErrorUnpack(DWORD flr) { return Main(flr) == FRESULT_ERROR_UNPACK; }
49         /**
50          * Was there lossy conversion involved?
51          * @param [in] flr Return value to test.
52          * @return true if return value determines lossy conversion(s) were done.
53          */
54         static bool IsLossy(DWORD flr) { return IsModifier(flr, FRESULT_LOSSY); }
55
56 // Assigning results
57         // main results
58         static void SetMainOk(DWORD & flr) { SetMain(flr, FRESULT_OK); }
59         // modifiers
60         static void AddModifier(DWORD & flr, DWORD modifier) { flr = (flr | modifier); }
61
62         // bit manipulations
63         static void SetMain(DWORD & flr, DWORD newmain) { flr = flr & ~FRESULT_MAIN_MASK; flr = flr | newmain; }
64         static DWORD Main(DWORD flr) { return flr & FRESULT_MAIN_MASK; }
65         static bool IsModifier(DWORD flr, DWORD modifier) { return (flr & modifier) != 0; }
66
67         /** @brief Return values for functions. */
68         enum FILES_RESULT
69         {
70                 /**
71                  * Mask for the main return values.
72                  * This mask defines bits used for main return values, separated from
73                  * modifier flags.
74                  */
75                 FRESULT_MAIN_MASK = 0xF,
76
77                 /**
78                  * Error.
79                  * This defines general error return value.
80                  */
81                 FRESULT_ERROR = 0x0,
82                 /**
83                  * Success.
84                  * This defines general success return value.
85                  */
86                 FRESULT_OK = 0x1,
87                 /**
88                  * Success, but impure file.
89                  * The file operation was successful. But the files was detected
90                  * to be impure file. Impure file is a file with two or three
91                  * different EOL styles.
92                  */
93                 FRESULT_OK_IMPURE = 0x2,
94                 /**
95                  * Binary file.
96                  * The file was loaded OK, and was detected to be a binary file.
97                  */
98                 FRESULT_BINARY = 0x3,
99                 /**
100                  * Unpacking plugin failed.
101                  * The file was loaded OK, but the unpacking plugin failed.
102                  */
103                 FRESULT_ERROR_UNPACK = 0x4,
104
105                 /**
106                  * Lossy conversions done.
107                  * Unicode / codepage conversions caused lossy conversions.
108                  */
109                 FRESULT_LOSSY = 0x10000,
110         };
111 };