MWAWRSRCParser.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
00002 
00003 /* libmwaw
00004 * Version: MPL 2.0 / LGPLv2+
00005 *
00006 * The contents of this file are subject to the Mozilla Public License Version
00007 * 2.0 (the "License"); you may not use this file except in compliance with
00008 * the License or as specified alternatively below. You may obtain a copy of
00009 * the License at http://www.mozilla.org/MPL/
00010 *
00011 * Software distributed under the License is distributed on an "AS IS" basis,
00012 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013 * for the specific language governing rights and limitations under the
00014 * License.
00015 *
00016 * Major Contributor(s):
00017 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
00018 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
00019 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00020 * Copyright (C) 2006, 2007 Andrew Ziem
00021 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
00022 *
00023 *
00024 * All Rights Reserved.
00025 *
00026 * For minor contributions see the git repository.
00027 *
00028 * Alternatively, the contents of this file may be used under the terms of
00029 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00030 * in which case the provisions of the LGPLv2+ are applicable
00031 * instead of those above.
00032 */
00033 
00034 #ifndef MWAW_RSRC_PARSER_H
00035 #define MWAW_RSRC_PARSER_H
00036 
00037 #include <map>
00038 #include <string>
00039 #include <vector>
00040 
00041 #include "libmwaw_internal.hxx"
00042 #include "MWAWDebug.hxx"
00043 
00044 class WPXBinaryData;
00045 
00048 class MWAWRSRCParser
00049 {
00050 public:
00051   struct Version;
00052 
00054   MWAWRSRCParser(MWAWInputStreamPtr input);
00056   ~MWAWRSRCParser();
00057 
00059   bool parse();
00060 
00062   MWAWInputStreamPtr getInput() {
00063     return m_input;
00064   }
00065 
00067   MWAWEntry getEntry(std::string type, int id) const;
00068 
00070   std::multimap<std::string, MWAWEntry> &getEntriesMap() {
00071     if (!m_parsed)
00072       parse();
00073     return m_entryMap;
00074   }
00076   std::multimap<std::string, MWAWEntry> const &getEntriesMap() const {
00077     if (!m_parsed)
00078       const_cast<MWAWRSRCParser *>(this)->parse();
00079     return m_entryMap;
00080   }
00081 
00083   bool parseSTR(MWAWEntry const &entry, std::string &str);
00084 
00086   bool parseSTRList(MWAWEntry const &entry, std::vector<std::string> &list);
00087 
00089   bool parsePICT(MWAWEntry const &entry, WPXBinaryData &pict);
00090 
00092   bool parseClut(MWAWEntry const &entry, std::vector<MWAWColor> &list);
00093 
00095   bool parseVers(MWAWEntry const &entry, Version &vers);
00096 
00098   void setAsciiName(char const *name) {
00099     m_asciiName = name;
00100   }
00102   std::string const &asciiName() const {
00103     return m_asciiName;
00104   }
00106   libmwaw::DebugFile &ascii() {
00107     return m_asciiFile;
00108   }
00109 protected:
00111   bool parseMap(MWAWEntry const &entry, long dataBegin);
00112 
00114   MWAWInputStreamPtr m_input;
00116   std::multimap<std::string, MWAWEntry> m_entryMap;
00118   bool m_parsed;
00120   libmwaw::DebugFile m_asciiFile;
00122   std::string m_asciiName;
00123 private:
00124   MWAWRSRCParser(MWAWRSRCParser const &orig);
00125   MWAWRSRCParser &operator=(MWAWRSRCParser const &orig);
00126 
00127 public:
00129   struct Version {
00130     Version() : m_majorVersion(-1), m_minorVersion(0), m_countryCode(0),
00131       m_string(""), m_versionString(""), m_extra("") {
00132     }
00134     friend std::ostream &operator<< (std::ostream &o, Version const &vers);
00136     int m_majorVersion;
00138     int m_minorVersion;
00140     int m_countryCode;
00142     std::string m_string;
00144     std::string m_versionString;
00146     std::string m_extra;
00147   };
00148 
00149 };
00150 
00151 #endif
00152 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: