WPS8Struct.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2/* libwps
3 * Version: MPL 2.0 / LGPLv2.1+
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * Major Contributor(s):
10 * Copyright (C) 2009, 2011 Alonso Laurent (alonso@loria.fr)
11 * Copyright (C) 2006, 2007 Andrew Ziem
12 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
13 * Copyright (C) 2004 Marc Maurer (uwog@uwog.net)
14 * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
15 *
16 * For minor contributions see the git repository.
17 *
18 * Alternatively, the contents of this file may be used under the terms
19 * of the GNU Lesser General Public License Version 2.1 or later
20 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
21 * applicable instead of those above.
22 *
23 * For further information visit http://libwps.sourceforge.net
24 */
25
26#ifndef WPS8_STRUCT_H
27#define WPS8_STRUCT_H
28
29#include <string>
30#include <vector>
31
32#include "libwps_internal.h"
33
35// Internal structure
37
39 namespace WPS8Struct
40{
41 struct FileData;
43 bool readData(RVNGInputStreamPtr input, long endPos, FileData &dt, std::string &error);
45 bool readBlockData(RVNGInputStreamPtr input, long endPos, FileData &dt, std::string &error);
47std::ostream &operator<< (std::ostream &o, FileData const &dt);
48
63 struct FileData
64{
66 FileData()
67 : m_value(0)
68 , m_text("")
69 , m_recursData()
70 , m_type(-1)
71 , m_id(-1)
72 , m_beginOffset(-1)
73 , m_endOffset(-1)
74 , m_input() {}
75
76 bool isBad() const
77 {
78 return m_type==-1;
79 }
80
81 bool hasStr() const
82 {
83 return !m_text.empty();
84 }
85
86 bool isNumber() const
87 {
88 return !hasStr() && (m_type & 0x30) != 0;
89 }
90
91 WPSColor getRGBColor() const
92 {
93 auto col = uint32_t(m_value&0xFFFFFF);
94 return WPSColor(col&0xFF, (col>>8)&0xFF, (col>>16)&0xFF);
95 }
96
97 bool getBorderStyles(WPSBorder::Style &style, WPSBorder::Type &type, std::string &mess) const;
98
100 bool isBool() const
101 {
102 return !hasStr() && (m_type & 0xb0)==0;
103 }
104
105 bool isTrue() const
106 {
107 return m_type == 0xa;
108 }
109
110 bool isFalse() const
111 {
112 return m_type == 0x2;
113 }
114
115 bool isArray() const
116 {
117 return !hasStr() && (m_type & 0x80)==0x80;
118 }
119
120 bool isRead() const
121 {
122 return (m_type & 0x80) !=0x80 || !(m_input.get() && m_beginOffset > 0 && m_endOffset >= m_beginOffset+2);
123 }
124
126 int type() const
127 {
128 if (m_type == 0xa) return 2;
129 return m_type;
130 }
131
132 int id() const
133 {
134 return m_id;
135 }
136
138 bool readArrayBlock() const;
139
141 long m_value;
143 std::string m_text;
145 std::vector<FileData> m_recursData;
146
148 long begin() const
149 {
150 return m_beginOffset;
151 }
152
153 long end() const
154 {
155 return m_endOffset;
156 }
157 protected:
159 static std::string createErrorString(RVNGInputStreamPtr input, long endPos);
160
162 int m_type;
164 int m_id;
165
166 long m_beginOffset , m_endOffset ;
168 RVNGInputStreamPtr m_input;
169
171 friend std::ostream &operator<< (std::ostream &o, FileData const &dt);
173 friend bool readData(RVNGInputStreamPtr input, long endPos, FileData &dt, std::string &error);
175 friend bool readBlockData(RVNGInputStreamPtr input, long endPos, FileData &dt, std::string &error);
176};
177}
178
179#endif
180/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
libwps_internal.h
RVNGInputStreamPtr
std::shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr
shared pointer to librevenge::RVNGInputStream
Definition libwps_internal.h:87
WPS8Struct
namespace used to read the structures stored in a WPS8 files
Definition WPS8Struct.cpp:31
WPS8Struct::readBlockData
bool readBlockData(RVNGInputStreamPtr input, long endPos, FileData &dt, std::string &error)
tries to read a block zone as a list of Data
Definition WPS8Struct.cpp:168
WPS8Struct::operator<<
std::ostream & operator<<(std::ostream &o, FileData const &dt)
operator<< which allows to print for debugging the content of a Data
Definition WPS8Struct.cpp:110
WPS8Struct::readData
bool readData(RVNGInputStreamPtr input, long endPos, FileData &dt, std::string &)
tries to read a block zone as a Data
Definition WPS8Struct.cpp:216
WPS8Struct::FileData
A recursif structure which seems generally used to store complex memory structures in a file.
Definition WPS8Struct.h:64
WPS8Struct::FileData::readData
friend bool readData(RVNGInputStreamPtr input, long endPos, FileData &dt, std::string &error)
function which parses an element
Definition WPS8Struct.cpp:216
WPS8Struct::FileData::end
long end() const
end of data position
Definition WPS8Struct.h:153
WPS8Struct::FileData::id
int id() const
returns the identificator
Definition WPS8Struct.h:132
WPS8Struct::FileData::operator<<
friend std::ostream & operator<<(std::ostream &o, FileData const &dt)
operator<<
Definition WPS8Struct.cpp:110
WPS8Struct::FileData::getRGBColor
WPSColor getRGBColor() const
returns a rgb color by converting the integer value field
Definition WPS8Struct.h:91
WPS8Struct::FileData::readArrayBlock
bool readArrayBlock() const
forces reading the data as a list of block
Definition WPS8Struct.cpp:33
WPS8Struct::FileData::m_endOffset
long m_endOffset
the final position of the data of this field
Definition WPS8Struct.h:166
WPS8Struct::FileData::isBad
bool isBad() const
returns true if the field was not read
Definition WPS8Struct.h:76
WPS8Struct::FileData::isBool
bool isBool() const
returns true if it is a bool data
Definition WPS8Struct.h:100
WPS8Struct::FileData::createErrorString
static std::string createErrorString(RVNGInputStreamPtr input, long endPos)
creates a string used to store the unparsed data
Definition WPS8Struct.cpp:45
WPS8Struct::FileData::isNumber
bool isNumber() const
returns true if it is a number data
Definition WPS8Struct.h:86
WPS8Struct::FileData::m_type
int m_type
an int which indicates the data type
Definition WPS8Struct.h:162
WPS8Struct::FileData::isArray
bool isArray() const
returns true if this is a list of block or an unstructured list
Definition WPS8Struct.h:115
WPS8Struct::FileData::m_input
RVNGInputStreamPtr m_input
the input
Definition WPS8Struct.h:168
WPS8Struct::FileData::FileData
FileData()
constructor
Definition WPS8Struct.h:66
WPS8Struct::FileData::type
int type() const
returns the data type (low level)
Definition WPS8Struct.h:126
WPS8Struct::FileData::isFalse
bool isFalse() const
returns true if this is a bool and the val is false
Definition WPS8Struct.h:110
WPS8Struct::FileData::readBlockData
friend bool readBlockData(RVNGInputStreamPtr input, long endPos, FileData &dt, std::string &error)
function which parses a set of elements
Definition WPS8Struct.cpp:168
WPS8Struct::FileData::m_text
std::string m_text
the string values
Definition WPS8Struct.h:143
WPS8Struct::FileData::m_id
int m_id
an identificator
Definition WPS8Struct.h:164
WPS8Struct::FileData::m_value
long m_value
an int value, filled if the data store an val
Definition WPS8Struct.h:141
WPS8Struct::FileData::m_recursData
std::vector< FileData > m_recursData
the list of children
Definition WPS8Struct.h:145
WPS8Struct::FileData::hasStr
bool hasStr() const
returns true if it is a string data
Definition WPS8Struct.h:81
WPS8Struct::FileData::isRead
bool isRead() const
returns true if the data are read
Definition WPS8Struct.h:120
WPS8Struct::FileData::m_beginOffset
long m_beginOffset
the initial position of the data of this field
Definition WPS8Struct.h:166
WPS8Struct::FileData::getBorderStyles
bool getBorderStyles(WPSBorder::Style &style, WPSBorder::Type &type, std::string &mess) const
returns the border, type style using the integer value field
Definition WPS8Struct.cpp:56
WPS8Struct::FileData::isTrue
bool isTrue() const
returns true if this is a bool and the val is true
Definition WPS8Struct.h:105
WPS8Struct::FileData::begin
long begin() const
beginning of data position
Definition WPS8Struct.h:148
WPSBorder::Style
Style
the line style
Definition libwps_internal.h:397
WPSBorder::Type
Type
the line repetition
Definition libwps_internal.h:399
WPSColor
the class to store a color
Definition libwps_internal.h:281