• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

pp_AttrProp.h

Go to the documentation of this file.
00001 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: t -*- */
00002 /* AbiWord
00003  * Copyright (C) 1998 AbiSource, Inc.
00004  * Copyright (c) 2016 Hubert Figuiere
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019  * 02110-1301 USA.
00020  */
00021 
00022 
00023 #ifndef PP_ATTRPROP_H
00024 #define PP_ATTRPROP_H
00025 
00026 #include <memory>
00027 #include <unordered_map>
00028 #include <utility>
00029 
00030 #include "ut_types.h"
00031 #include "ut_vector.h"
00032 #include "ut_xml.h"
00033 #include "pp_Property.h"
00034 #include "pt_Types.h"
00035 
00036 class PD_Document;
00037 
00038 // the following class holds the state of the view when we set
00039 // m_iRevisionIndex
00040 class ABI_EXPORT PP_RevisionState
00041 {
00042   public:
00043     PP_RevisionState()
00044         :m_iId(0),
00045         m_bShow(false),
00046         m_bMark(false)
00047     {
00048     }
00049 
00050     bool operator == (const PP_RevisionState & rs) const
00051          {
00052              if(rs.m_iId == m_iId && rs.m_bShow == m_bShow && rs.m_bMark == m_bMark)
00053                  return true;
00054              return false;
00055          }
00056 
00057     bool isEqual(UT_uint32 iId, bool bShow, bool bMark) const
00058          {
00059              if(m_iId == iId && m_bShow == bShow && m_bMark == bMark)
00060                  return true;
00061              return false;
00062          }
00063 
00064     UT_uint32 m_iId;
00065     bool      m_bShow;
00066     bool      m_bMark;
00067 };
00068 
00069 
00070 // PP_AttrProp captures the complete set of XML and CSS
00071 // Attributes/Properties for a piece of the document.
00072 // These are generally created by the file-reader.  Attributes
00073 // represent all of the attribute/value pairs in the XML with
00074 // the exception of the PT_PROPS_ATTRIBUTE_NAME attribute.
00075 // The value of the this attribute is parsed into CSS properties.
00076 // PP_AttrProp just provides a pair of association lists
00077 // (one for attributes and one for properties), it does not
00078 // know the meaning of any of them.
00079 
00080 class ABI_EXPORT PP_AttrProp
00081 {
00082 public:
00083     typedef std::unordered_map<std::string, std::string> attributes_t;
00084     typedef std::unordered_map<std::string, std::string> properties_t;
00085 
00086     PP_AttrProp();
00087     virtual ~PP_AttrProp();
00088 
00089     bool    setAttributes(const PP_PropertyVector & attributes);
00090     bool    setProperties(const PP_PropertyVector & properties);
00091 
00092     PP_PropertyVector getAttributes () const;
00093     PP_PropertyVector getProperties () const;
00094 
00095     bool    setAttribute(const gchar * szName, const gchar * szValue);
00096     bool    setProperty(const std::string &name, const std::string &value);
00097 
00098     bool    getNthAttribute(int ndx, const gchar *& szName, const gchar *& szValue) const;
00099     bool    getNthProperty(int ndx, const gchar *& szName, const gchar *& szValue) const;
00100 
00101     bool getAttribute(const std::string & name, const gchar *& szValue) const;
00102     bool getProperty(const std::string & name, const gchar *& szValue) const;
00103 
00104     std::unique_ptr<PP_PropertyType> getPropertyType(const gchar * szName, tProperty_type Type) const;
00105 
00106     bool hasProperties(void) const;
00107     bool hasAttributes(void) const;
00108     size_t getPropertyCount (void) const;
00109     size_t getAttributeCount (void) const;
00110     bool areAlreadyPresent(const PP_PropertyVector & attributes,
00111                            const PP_PropertyVector & properties) const;
00112     bool areAnyOfTheseNamesPresent(const PP_PropertyVector & attributes,
00113                                    const PP_PropertyVector & properties) const;
00114     bool isExactMatch(const PP_AttrProp & pMatch) const;
00115     bool isEquivalent(const PP_AttrProp * pAP2) const;
00116     bool isEquivalent(const PP_PropertyVector & attrs,
00117                       const PP_PropertyVector & props) const;
00118 
00119     static PP_AttrProp * createExactly(const PP_PropertyVector & attributes,
00120                     const PP_PropertyVector & properties);
00121 
00122 
00123     PP_AttrProp * cloneWithReplacements(const PP_PropertyVector & attributes,
00124                                         const PP_PropertyVector & properties,
00125                                         bool bClearProps) const;
00126     PP_AttrProp * cloneWithElimination(const PP_PropertyVector & attributes,
00127                                        const PP_PropertyVector & properties) const;
00128     PP_AttrProp * cloneWithEliminationIfEqual(const PP_PropertyVector & attributes,
00129                                               const PP_PropertyVector & properties) const;
00130 
00131     void markReadOnly(void);
00132     UT_uint32 getCheckSum(void) const;
00133 
00134     PP_AttrProp & operator=(const PP_AttrProp &Other);
00135     UT_uint32 getIndex(void) const; //$HACK
00136     void setIndex(UT_uint32 i); //$HACK
00137 
00138     /* m_iRevisionIndex points to a AP that has our revision attribute
00139        inflated into actual attributes and properties; since the
00140        inflation is view-dependent, we need to keep track of the view
00141        state */
00142     PT_AttrPropIndex   getRevisedIndex() const {return m_iRevisedIndex;}
00143     PP_RevisionState & getRevisionState() const {return m_RevisionState;}
00144 
00145     void               setRevisedIndex (PT_AttrPropIndex i, UT_uint32 iId, bool bShow, bool bMark, bool bHidden) const
00146                            {
00147                                m_iRevisedIndex = i; m_RevisionState.m_iId = iId;
00148                                m_RevisionState.m_bShow = bShow; m_RevisionState.m_bMark = bMark;
00149                                m_bRevisionHidden = bHidden;
00150                            }
00151 
00152     bool               getRevisionHidden() const {return m_bRevisionHidden;}
00153 
00154     void prune();
00155     bool explodeStyle(const PD_Document * pDoc, bool bOverwrite = false);
00156 
00157     void miniDump(const PD_Document * pDoc) const;
00158 
00159 protected:
00160     void _computeCheckSum(void);
00161     void _clearEmptyProperties();
00162     void _clearEmptyAttributes();
00163 
00164     attributes_t m_attributes;
00165     properties_t m_properties;
00166 
00167     bool                m_bIsReadOnly;
00168     UT_uint32           m_checkSum;
00169     UT_uint32           m_index;    //$HACK
00170 
00171     mutable PT_AttrPropIndex    m_iRevisedIndex;
00172     mutable PP_RevisionState    m_RevisionState;
00173     mutable bool                m_bRevisionHidden;
00174 };
00175 
00176 
00177 
00180 std::string PP_makePropString(const PP_PropertyVector & props);
00181 
00182 /*
00183  * Safe version of UT_setPropsToNothing. Deleted values are "".
00184  */
00185 PP_PropertyVector PP_std_setPropsToNothing(const PP_PropertyVector & props);
00186 // just copy to a std. Long term, remove this
00187 // XXX remove this
00188 ABI_EXPORT PP_PropertyVector PP_std_copyProps(const gchar ** props);
00189 // safe version of UT_setPropsToValue.
00190 PP_PropertyVector PP_std_setPropsToValue(const PP_PropertyVector & props,
00191                                          const gchar * value);
00192 
00194 PP_PropertyVector PP_cloneAndDecodeAttributes (const gchar ** attrs);
00195 
00196 // XXX ineficient
00198 ABI_EXPORT bool PP_hasAttribute(const char* name, const PP_PropertyVector & atts);
00199 
00200 // XXX ineficient
00201 ABI_EXPORT const std::string & PP_getAttribute(const char* name, const PP_PropertyVector & atts);
00202 
00203 // XXX ineficient
00206 bool PP_setAttribute(const char* name, const std::string & value, PP_PropertyVector & atts);
00207 
00208 // XXX ineficient
00210 void PP_addOrSetAttribute(const char* name, const std::string & value, PP_PropertyVector & atts);
00211 
00212 // XXX ineficient
00213 bool PP_removeAttribute(const char* name, PP_PropertyVector & atts);
00214 
00215 #endif /* PP_ATTRPROP_H */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1