VSDFieldList.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /*
00003  * This file is part of the libvisio project.
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 
00010 #ifndef __VSDFIELDLIST_H__
00011 #define __VSDFIELDLIST_H__
00012 
00013 #include <vector>
00014 #include <map>
00015 #include <librevenge/librevenge.h>
00016 #include "VSDDocumentStructure.h"
00017 #include "VSDTypes.h"
00018 
00019 namespace libvisio
00020 {
00021 
00022 class VSDCollector;
00023 
00024 class VSDFieldListElement
00025 {
00026 public:
00027   VSDFieldListElement() {}
00028   virtual ~VSDFieldListElement() {}
00029   virtual void handle(VSDCollector *collector) const = 0;
00030   virtual VSDFieldListElement *clone() = 0;
00031   virtual librevenge::RVNGString getString(const std::map<unsigned, librevenge::RVNGString> &) = 0;
00032   virtual void setNameId(int) = 0;
00033   virtual void setFormat(unsigned short) = 0;
00034   virtual void setValue(double) = 0;
00035 };
00036 
00037 class VSDTextField : public VSDFieldListElement
00038 {
00039 public:
00040   VSDTextField(unsigned id, unsigned level, int nameId, int formatStringId)
00041     : m_id(id),
00042       m_level(level),
00043       m_nameId(nameId),
00044       m_formatStringId(formatStringId) {}
00045   ~VSDTextField() {}
00046   void handle(VSDCollector *collector) const;
00047   VSDFieldListElement *clone();
00048   librevenge::RVNGString getString(const std::map<unsigned, librevenge::RVNGString> &strVec);
00049   void setNameId(int nameId);
00050   void setFormat(unsigned short) {}
00051   void setValue(double) {}
00052 private:
00053   unsigned m_id, m_level;
00054   int m_nameId, m_formatStringId;
00055 };
00056 
00057 class VSDNumericField : public VSDFieldListElement
00058 {
00059 public:
00060   VSDNumericField(unsigned id, unsigned level, unsigned short format, double number, int formatStringId)
00061     : m_id(id),
00062       m_level(level),
00063       m_format(format),
00064       m_number(number),
00065       m_formatStringId(formatStringId) {}
00066   ~VSDNumericField() {}
00067   void handle(VSDCollector *collector) const;
00068   VSDFieldListElement *clone();
00069   librevenge::RVNGString getString(const std::map<unsigned, librevenge::RVNGString> &);
00070   void setNameId(int) {}
00071   void setFormat(unsigned short format);
00072   void setValue(double number);
00073 private:
00074   librevenge::RVNGString datetimeToString(const char *format, double datetime);
00075   unsigned m_id, m_level;
00076   unsigned short m_format;
00077   double m_number;
00078   int m_formatStringId;
00079 };
00080 
00081 class VSDFieldList
00082 {
00083 public:
00084   VSDFieldList();
00085   VSDFieldList(const VSDFieldList &fieldList);
00086   ~VSDFieldList();
00087   VSDFieldList &operator=(const VSDFieldList &fieldList);
00088   void setElementsOrder(const std::vector<unsigned> &m_elementsOrder);
00089   void addFieldList(unsigned id, unsigned level);
00090   void addTextField(unsigned id, unsigned level, int nameId, int formatStringId);
00091   void addNumericField(unsigned id, unsigned level, unsigned short format, double number, int formatStringId);
00092   void addClonedField(unsigned id);
00093   void handle(VSDCollector *collector) const;
00094   void clear();
00095   unsigned long size() const
00096   {
00097     return (unsigned long)m_elements.size();
00098   }
00099   bool empty() const
00100   {
00101     return (m_elements.empty());
00102   }
00103   VSDFieldListElement *getElement(unsigned index);
00104 private:
00105   std::map<unsigned, VSDFieldListElement *> m_elements;
00106   std::vector<unsigned> m_elementsOrder;
00107   unsigned m_id, m_level;
00108 };
00109 
00110 } // namespace libvisio
00111 
00112 #endif // __VSDFIELDLIST_H__
00113 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */