WPS8Struct.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /* libwps
00003  * Version: MPL 2.0 / LGPLv2.1+
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  *
00009  * Major Contributor(s):
00010  * Copyright (C) 2009, 2011 Alonso Laurent (alonso@loria.fr)
00011  * Copyright (C) 2006, 2007 Andrew Ziem
00012  * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00013  * Copyright (C) 2004 Marc Maurer (uwog@uwog.net)
00014  * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
00015  *
00016  * For minor contributions see the git repository.
00017  *
00018  * Alternatively, the contents of this file may be used under the terms
00019  * of the GNU Lesser General Public License Version 2.1 or later
00020  * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
00021  * applicable instead of those above.
00022  *
00023  * For further information visit http://libwps.sourceforge.net
00024  */
00025 
00026 #ifndef WPS8_STRUCT_H
00027 #define WPS8_STRUCT_H
00028 
00029 #include <string>
00030 #include <vector>
00031 
00032 #include "libwps_internal.h"
00033 
00035 //    Internal structure
00037 
00039 namespace WPS8Struct
00040 {
00041 struct FileData;
00043 bool readData(RVNGInputStreamPtr input, long endPos, FileData &dt, std::string &error);
00045 bool readBlockData(RVNGInputStreamPtr input, long endPos, FileData &dt, std::string &error);
00047 std::ostream &operator<< (std::ostream &o, FileData const &dt);
00048 
00063 struct FileData
00064 {
00066         FileData() : m_value(0), m_text(""), m_recursData(), m_type(-1), m_id(-1), m_beginOffset(-1), m_endOffset(-1), m_input() {}
00068         bool isBad() const
00069         {
00070                 return m_type==-1;
00071         }
00073         bool hasStr() const
00074         {
00075                 return m_text.size() != 0;
00076         }
00078         bool isNumber() const
00079         {
00080                 return !hasStr() && (m_type & 0x30) != 0;
00081         }
00083         uint32_t getRGBColor() const
00084         {
00085                 uint32_t col = (uint32_t)(m_value&0xFFFFFF);
00086                 return (((col>>16)&0xFF) |(col&0xFF00)|((col&0xFF)<<16));
00087         }
00089         WPSBorder::Style getBorderStyle(std::string &mess) const;
00090 
00092         bool isBool() const
00093         {
00094                 return !hasStr() && (m_type & 0xb0)==0;
00095         }
00097         bool isTrue() const
00098         {
00099                 return m_type == 0xa;
00100         }
00102         bool isFalse() const
00103         {
00104                 return m_type == 0x2;
00105         }
00107         bool isArray() const
00108         {
00109                 return !hasStr() && (m_type & 0x80)==0x80;
00110         }
00112         bool isRead() const
00113         {
00114                 return (m_type & 0x80) !=0x80 || !(m_input.get() && m_beginOffset > 0 && m_endOffset >= m_beginOffset+2);
00115         }
00116 
00118         int type() const
00119         {
00120                 if (m_type == 0xa) return 2;
00121                 return m_type;
00122         }
00124         int id() const
00125         {
00126                 return m_id;
00127         }
00128 
00130         bool readArrayBlock() const;
00131 
00133         long m_value;
00135         std::string m_text;
00137         std::vector<FileData> m_recursData;
00138 
00140         long begin() const
00141         {
00142                 return m_beginOffset;
00143         }
00145         long end() const
00146         {
00147                 return m_endOffset;
00148         }
00149 protected:
00151         static std::string createErrorString(RVNGInputStreamPtr input, long endPos);
00152 
00154         int m_type;
00156         int m_id;
00157 
00158         long m_beginOffset , m_endOffset ;
00160         RVNGInputStreamPtr m_input;
00161 
00163         friend std::ostream &operator<< (std::ostream &o, FileData const &dt);
00165         friend bool readData(RVNGInputStreamPtr input, long endPos, FileData &dt, std::string &error);
00167         friend bool readBlockData(RVNGInputStreamPtr input, long endPos, FileData &dt, std::string &error);
00168 };
00169 }
00170 
00171 #endif
00172 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */