Debian Codegraph @

src/tools/file/rsrc.h

raw
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3 /* libmwaw: tools
4 * Version: MPL 2.0 / LGPLv2+
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 2.0 (the "License"); you may not use this file except in compliance with
8 * the License or as specified alternatively below. You may obtain a copy of
9 * the License at http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Major Contributor(s):
17 * Copyright (C) 2011, 2012 Alonso Laurent ([email protected])
18 *
19 *
20 * All Rights Reserved.
21 *
22 * For minor contributions see the git repository.
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
26 * in which case the provisions of the LGPLv2+ are applicable
27 * instead of those above.
28 */
29
30 #ifndef MWAW_RSRC_H
31 # define MWAW_RSRC_H
32 #include <ostream>
33 #include <map>
34 #include <string>
35 #include <vector>
36
37 namespace libmwaw_tools
38 {
39 class InputStream;
40
41 /** \brief the main class to read a resource fork ( only the version data )
42 */
43 class RSRC
44 {
45 public:
46 struct Version;
47 protected:
48 //! small internal structure used to store entry data
49 struct MapEntry {
50 //! constructor
51 MapEntry()
52 : m_type("")
53 , m_numEntry(0)
54 , m_id(-1)
55 , m_pos(-1)
56 {
57 }
58 //! the entry type
59 std::string m_type;
60 //! the number of entry (if this is a main entry )
61 int m_numEntry;
62 //! the identificator (if this is a data entry )
63 int m_id;
64 //! the file position
65 long m_pos;
66 };
67
68 public:
69 //! the constructor
70 explicit RSRC(InputStream &input)
71 : m_input(input)
72 , m_dataOffset(-1)
73 , m_typeMapEntryMap()
74 {
75 }
76 //! the destructor
77 ~RSRC() {}
78
79 //! returns a list of version
80 std::vector<Version> getVersionList();
81
82 //! returns a string correspond to an id
83 std::string getString(int id);
84
85 //! returns true if we have an entry corresponding to a type
86 bool hasEntry(std::string, int id);
87 protected:
88 //! try to parse a version entry
89 bool parseVers(Version &vers);
90
91 protected:
92 //! try to create the type to map entry
93 bool createMapEntries();
94
95 //! return a list of data entry corresponding to a type
96 std::vector<MapEntry> getMapEntries(std::string const &type);
97
98 //! the input stream
99 InputStream &m_input;
100
101 //! the first offset of the data map
102 long m_dataOffset;
103
104 //! the map type->MapEntry
105 std::map<std::string, MapEntry> m_typeMapEntryMap;
106
107 private:
108 RSRC(RSRC const &orig) = delete;
109 RSRC &operator=(RSRC const &orig) = delete;
110
111 public:
112 /** a public structure used to return the version */
113 struct Version {
114 Version()
115 : m_id(-1)
116 , m_begin(-1)
117 , m_majorVersion(-1)
118 , m_minorVersion(0)
119 , m_countryCode(0)
120 , m_string("")
121 , m_versionString("")
122 , m_extra("")
123 {
124 }
125 bool ok() const
126 {
127 return m_id >= 0;
128 }
129 //! operator<<
130 friend std::ostream &operator<< (std::ostream &o, Version const &vers);
131
132 static std::string makePretty(std::string const &orig);
133
134 /** the rsrc id */
135 int m_id;
136 /** the beginning of rsrc in the data file (the end of the entry is too complicated to get, so...) */
137 long m_begin;
138
139 /** the major number */
140 int m_majorVersion;
141 /** the minor number */
142 int m_minorVersion;
143 /** the country code */
144 int m_countryCode;
145 /** the major string */
146 std::string m_string;
147 /** the version string */
148 std::string m_versionString;
149 /** extra data */
150 std::string m_extra;
151 };
152
153 };
154
155 }
156 #endif
157 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: