VSDXFieldList.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* libvisio
00003  * Version: MPL 1.1 / GPLv2+ / LGPLv2+
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License or as specified alternatively below. You may obtain a copy of
00008  * the License at http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * Major Contributor(s):
00016  * Copyright (C) 2011 Fridrich Strba <fridrich.strba@bluewin.ch>
00017  * Copyright (C) 2011 Eilidh McAdam <tibbylickle@gmail.com>
00018  *
00019  *
00020  * All Rights Reserved.
00021  *
00022  * For minor contributions see the git repository.
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
00026  * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00027  * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
00028  * instead of those above.
00029  */
00030 
00031 #ifndef __VSDXFIELDLIST_H__
00032 #define __VSDXFIELDLIST_H__
00033 
00034 #include <vector>
00035 #include <map>
00036 #include <libwpd/libwpd.h>
00037 #include "VSDXDocumentStructure.h"
00038 #include "VSDXTypes.h"
00039 
00040 namespace libvisio
00041 {
00042 
00043 class VSDXCollector;
00044 
00045 class VSDXFieldListElement
00046 {
00047 public:
00048   VSDXFieldListElement() {}
00049   virtual ~VSDXFieldListElement() {}
00050   virtual void handle(VSDXCollector *collector) = 0;
00051   virtual VSDXFieldListElement *clone() = 0;
00052   virtual WPXString getString(const std::map<unsigned, WPXString>&) = 0;
00053   virtual void setNameId(int) = 0;
00054   virtual void setFormat(unsigned short) = 0;
00055   virtual void setValue(double) = 0;
00056 };
00057 
00058 class VSDXTextField : public VSDXFieldListElement
00059 {
00060 public:
00061   VSDXTextField(unsigned id, unsigned level, int nameId, int formatStringId)
00062     : m_id(id),
00063       m_level(level),
00064       m_nameId(nameId),
00065       m_formatStringId(formatStringId) {}
00066   ~VSDXTextField() {}
00067   void handle(VSDXCollector *collector);
00068   VSDXFieldListElement *clone();
00069   WPXString getString(const std::map<unsigned, WPXString> &strVec);
00070   void setNameId(int nameId);
00071   void setFormat(unsigned short) {}
00072   void setValue(double) {}
00073 private:
00074   unsigned m_id, m_level;
00075   int m_nameId, m_formatStringId;
00076 };
00077 
00078 class VSDXNumericField : public VSDXFieldListElement
00079 {
00080 public:
00081   VSDXNumericField(unsigned id, unsigned level, unsigned short format, double number, int formatStringId)
00082     : m_id(id),
00083       m_level(level),
00084       m_format(format),
00085       m_number(number),
00086       m_formatStringId(formatStringId) {}
00087   ~VSDXNumericField() {}
00088   void handle(VSDXCollector *collector);
00089   VSDXFieldListElement *clone();
00090   WPXString getString(const std::map<unsigned, WPXString> &);
00091   void setNameId(int) {}
00092   void setFormat(unsigned short format);
00093   void setValue(double number);
00094 private:
00095   WPXString datetimeToString(const char *format, double datetime);
00096   unsigned m_id, m_level;
00097   unsigned short m_format;
00098   double m_number;
00099   int m_formatStringId;
00100 };
00101 
00102 class VSDXFieldList
00103 {
00104 public:
00105   VSDXFieldList();
00106   VSDXFieldList(const VSDXFieldList &fieldList);
00107   ~VSDXFieldList();
00108   VSDXFieldList &operator=(const VSDXFieldList &fieldList);
00109   void setElementsOrder(const std::vector<unsigned> &m_elementsOrder);
00110   void addFieldList(unsigned id, unsigned level);
00111   void addTextField(unsigned id, unsigned level, int nameId, int formatStringId);
00112   void addNumericField(unsigned id, unsigned level, unsigned short format, double number, int formatStringId);
00113   void addClonedField(unsigned id);
00114   void handle(VSDXCollector *collector);
00115   void clear();
00116   unsigned long size() const
00117   {
00118     return (unsigned long)m_elements.size();
00119   }
00120   bool empty() const
00121   {
00122     return (!m_elements.size());
00123   }
00124   VSDXFieldListElement *getElement(unsigned index);
00125 private:
00126   std::map<unsigned, VSDXFieldListElement *> m_elements;
00127   std::vector<unsigned> m_elementsOrder;
00128   unsigned m_id, m_level;
00129 };
00130 
00131 } // namespace libvisio
00132 
00133 #endif // __VSDXFIELDLIST_H__
00134 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */