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(WPXInputStreamPtr input, long endPos, FileData &dt, std::string &error);
45 bool readBlockData(WPXInputStreamPtr input, long endPos, FileData &dt, std::string &error);
47 std::ostream &operator<< (std::ostream &o, FileData const &dt);
48 
63 struct FileData
64 {
66  FileData() : m_value(0), m_text(""), m_recursData(), m_type(-1), m_id(-1), m_beginOffset(-1), m_endOffset(-1), m_input() {}
68  bool isBad() const
69  {
70  return m_type==-1;
71  }
73  bool hasStr() const
74  {
75  return m_text.size() != 0;
76  }
78  bool isNumber() const
79  {
80  return !hasStr() && (m_type & 0x30) != 0;
81  }
83  uint32_t getRGBColor() const
84  {
85  uint32_t col = (uint32_t) (m_value&0xFFFFFF);
86  return (((col>>16)&0xFF) |(col&0xFF00)|((col&0xFF)<<16));
87  }
89  WPSBorder::Style getBorderStyle(std::string &mess) const;
90 
92  bool isBool() const
93  {
94  return !hasStr() && (m_type & 0xb0)==0;
95  }
97  bool isTrue() const
98  {
99  return m_type == 0xa;
100  }
102  bool isFalse() const
103  {
104  return m_type == 0x2;
105  }
107  bool isArray() const
108  {
109  return !hasStr() && (m_type & 0x80)==0x80;
110  }
112  bool isRead() const
113  {
114  return (m_type & 0x80) !=0x80 || !(m_input.get() && m_beginOffset > 0 && m_endOffset >= m_beginOffset+2);
115  }
116 
118  int type() const
119  {
120  if (m_type == 0xa) return 2;
121  return m_type;
122  }
124  int id() const
125  {
126  return m_id;
127  }
128 
130  bool readArrayBlock() const;
131 
133  long m_value;
135  std::string m_text;
137  std::vector<FileData> m_recursData;
138 
140  long begin() const
141  {
142  return m_beginOffset;
143  }
145  long end() const
146  {
147  return m_endOffset;
148  }
149 protected:
151  static std::string createErrorString(WPXInputStreamPtr input, long endPos);
152 
154  int m_type;
156  int m_id;
157 
161 
163  friend std::ostream &operator<< (std::ostream &o, FileData const &dt);
165  friend bool readData(WPXInputStreamPtr input, long endPos, FileData &dt, std::string &error);
167  friend bool readBlockData(WPXInputStreamPtr input, long endPos, FileData &dt, std::string &error);
168 };
169 }
170 
171 #endif
172 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
long end() const
end of data position
Definition: WPS8Struct.h:145
long begin() const
beginning of data position
Definition: WPS8Struct.h:140
int m_type
an int which indicates the data type
Definition: WPS8Struct.h:154
shared_ptr< WPXInputStream > WPXInputStreamPtr
Definition: libwps_internal.h:74
int type() const
returns the data type (low level)
Definition: WPS8Struct.h:118
std::ostream & operator<<(std::ostream &o, FileData const &dt)
operator&lt;&lt; which allows to print for debugging the content of a Data
Definition: WPS8Struct.cpp:109
friend std::ostream & operator<<(std::ostream &o, FileData const &dt)
operator&lt;&lt;
Definition: WPS8Struct.cpp:109
uint32_t getRGBColor() const
returns a rgb color by converting the integer value field
Definition: WPS8Struct.h:83
long m_endOffset
the final position of the data of this field
Definition: WPS8Struct.h:158
friend bool readBlockData(WPXInputStreamPtr input, long endPos, FileData &dt, std::string &error)
function which parses a set of elements
Definition: WPS8Struct.cpp:168
int id() const
returns the identificator
Definition: WPS8Struct.h:124
bool isFalse() const
returns true if this is a bool and the val is false
Definition: WPS8Struct.h:102
FileData()
constructor
Definition: WPS8Struct.h:66
std::vector< FileData > m_recursData
the list of children
Definition: WPS8Struct.h:137
long m_value
an int value, filled if the data store an val
Definition: WPS8Struct.h:133
std::string m_text
the string values
Definition: WPS8Struct.h:135
static std::string createErrorString(WPXInputStreamPtr input, long endPos)
creates a string used to store the unparsed data
Definition: WPS8Struct.cpp:45
bool isTrue() const
returns true if this is a bool and the val is true
Definition: WPS8Struct.h:97
WPXInputStreamPtr m_input
the input
Definition: WPS8Struct.h:160
friend bool readData(WPXInputStreamPtr input, long endPos, FileData &dt, std::string &error)
function which parses an element
Definition: WPS8Struct.cpp:216
bool isArray() const
returns true if this is a list of block or an unstructured list
Definition: WPS8Struct.h:107
bool readData(WPXInputStreamPtr input, long endPos, FileData &dt, std::string &)
tries to read a block zone as a Data
Definition: WPS8Struct.cpp:216
int m_id
an identificator
Definition: WPS8Struct.h:156
bool isRead() const
returns true if the data are read
Definition: WPS8Struct.h:112
Style
Definition: libwps_internal.h:227
bool isBad() const
returns true if the field was not read
Definition: WPS8Struct.h:68
bool readBlockData(WPXInputStreamPtr input, long endPos, FileData &dt, std::string &error)
tries to read a block zone as a list of Data
Definition: WPS8Struct.cpp:168
bool hasStr() const
returns true if it is a string data
Definition: WPS8Struct.h:73
bool isBool() const
returns true if it is a bool data
Definition: WPS8Struct.h:92
bool readArrayBlock() const
forces reading the data as a list of block
Definition: WPS8Struct.cpp:33
WPSBorder::Style getBorderStyle(std::string &mess) const
returns the border style using the integer value field
Definition: WPS8Struct.cpp:56
bool isNumber() const
returns true if it is a number data
Definition: WPS8Struct.h:78
long m_beginOffset
the initial position of the data of this field
Definition: WPS8Struct.h:158
A recursif structure which seems generally used to store complex memory structures in a file...
Definition: WPS8Struct.h:63

Generated on Wed Jun 11 2014 02:26:01 for libwps by doxygen 1.8.5