MatN work for versatile appimage creation for all types of os
[goodguy/cinelerra.git] / cinelerra-5.1 / tools / makeappimagetool / includes / desktopfile.h
1 // system includes
2 #include <unordered_map>
3
4 // local includes
5 #include "desktopfileentry.h"
6
7 #pragma once
8
9 namespace linuxdeploy {
10     namespace desktopfile {
11         /*
12          * Parse and read desktop files.
13          */
14         class DesktopFile {
15         public:
16             // describes a single section
17             typedef std::unordered_map<std::string, DesktopFileEntry> section_t;
18
19             // describes all sections in the desktop file
20             typedef std::unordered_map<std::string, section_t> sections_t;
21
22         private:
23                 // private data class pattern
24                 class PrivateData;
25                 std::shared_ptr<PrivateData> d;
26
27                 // (in)equality operators are implemented outside this class
28                 friend bool operator==(const DesktopFile& first, const DesktopFile& second);
29                 friend bool operator!=(const DesktopFile& first, const DesktopFile& second);
30
31             public:
32                 // default constructor
33                 DesktopFile();
34
35                 // construct from existing desktop file
36                 // if the file exists, it will be read using DesktopFileReader
37                 // if reading fails, exceptions will be thrown (see DesktopFileReader for more information)
38                 explicit DesktopFile(const std::string& path);
39
40                 // construct by reading an existing stream
41                 // file must exist, otherwise std::runtime_error is thrown
42                 explicit DesktopFile(std::istream& is);
43
44                 // copy constructor
45                 DesktopFile(const DesktopFile& other);
46
47                 // copy assignment constructor
48                 DesktopFile& operator=(const DesktopFile& other);
49
50                 // move assignment operator
51                 DesktopFile& operator=(DesktopFile&& other) noexcept;
52
53         public:
54                 // returns true if a file has been loaded, false otherwise
55                 bool isEmpty() const;
56
57                 // read desktop file
58                 // sets path associated with this file
59                 // throws exceptions in case of issues, see DesktopFileReader for more information
60                 void read(const std::string& path);
61
62                 // read desktop file from existing stream
63                 // throws exceptions in case of issues, see DesktopFileReader for more information
64                 void read(std::istream& is);
65
66                 // get path associated with this file
67                 std::string path() const;
68
69                 // sets the path associated with this desktop file
70                 // used to e.g., save the desktop file
71                 void setPath(const std::string& path);
72
73                 // clear contents of desktop file
74                 void clear();
75
76                 // save desktop file
77                 bool save() const;
78
79                 // save desktop file to path
80                 // does not change path associated with desktop file
81                 // throws exceptions in case of errors, see DesktopFileWriter::save(...) for more information
82                 bool save(const std::string& path) const;
83
84                 // save desktop file to ostream
85                 // does not change path associated with desktop file
86                 // throws exceptions in case of errors, see DesktopFileWriter::save(...) for more information
87                 bool save(std::ostream& os) const;
88
89                 // check if entry exists in given section and key
90                 bool entryExists(const std::string& section, const std::string& key) const;
91
92                 // get key from desktop file
93                 // an std::string passed as value parameter will be populated with the contents
94                 // returns true (and populates value) if the key exists, false otherwise
95                 bool getEntry(const std::string& section, const std::string& key, DesktopFileEntry& value) const;
96
97                 // add key to section in desktop file
98                 // the section will be created if it doesn't exist already
99                 // returns true if an existing key was overwritten, false otherwise
100                 bool setEntry(const std::string& section, const DesktopFileEntry& entry);
101
102                 // add key to section in desktop file
103                 // the section will be created if it doesn't exist already
104                 // returns true if an existing key was overwritten, false otherwise
105                 bool setEntry(const std::string& section, DesktopFileEntry&& entry);
106
107                 // validate desktop file
108                 bool validate() const;
109         };
110
111         // DesktopFile equality operator
112         bool operator==(const DesktopFile& first, const DesktopFile& second);
113
114         // DesktopFile inequality operator
115         bool operator!=(const DesktopFile& first, const DesktopFile& second);
116     }
117 }