/src/libmwaw/src/lib/MWAWPropertyHandler.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */ |
2 | | |
3 | | /* libmwaw |
4 | | * Version: MPL 2.0 / LGPLv2+ |
5 | | * |
6 | | * The contents of this file are subject to the Mozilla Public License Version |
7 | | * 2.0 (the "License"); you may not use this file except in compliance with |
8 | | * the License or as specified alternatively below. You may obtain a copy of |
9 | | * the License at http://www.mozilla.org/MPL/ |
10 | | * |
11 | | * Software distributed under the License is distributed on an "AS IS" basis, |
12 | | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
13 | | * for the specific language governing rights and limitations under the |
14 | | * License. |
15 | | * |
16 | | * Major Contributor(s): |
17 | | * Copyright (C) 2002 William Lachance (wrlach@gmail.com) |
18 | | * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net) |
19 | | * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch) |
20 | | * Copyright (C) 2006, 2007 Andrew Ziem |
21 | | * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr) |
22 | | * |
23 | | * |
24 | | * All Rights Reserved. |
25 | | * |
26 | | * For minor contributions see the git repository. |
27 | | * |
28 | | * Alternatively, the contents of this file may be used under the terms of |
29 | | * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), |
30 | | * in which case the provisions of the LGPLv2+ are applicable |
31 | | * instead of those above. |
32 | | */ |
33 | | |
34 | | #ifndef MWAW_PROPERTY_HANDLER |
35 | | # define MWAW_PROPERTY_HANDLER |
36 | | |
37 | | # include <ostream> |
38 | | # include <sstream> |
39 | | # include <string> |
40 | | |
41 | | # include <librevenge/librevenge.h> |
42 | | |
43 | | //! a generic property handler |
44 | | class MWAWPropertyHandler |
45 | | { |
46 | | public: |
47 | | //! constructor |
48 | | MWAWPropertyHandler() |
49 | 0 | { |
50 | 0 | } |
51 | | //! destructor |
52 | | virtual ~MWAWPropertyHandler(); |
53 | | |
54 | | //! inserts a simple element |
55 | | virtual void insertElement(const char *psName) = 0; |
56 | | //! inserts an element ( given a property list ) |
57 | | virtual void insertElement(const char *psName, const librevenge::RVNGPropertyList &xPropList) = 0; |
58 | | //! writes a list of characters |
59 | | virtual void characters(librevenge::RVNGString const &sCharacters) = 0; |
60 | | |
61 | | //! checks a encoded librevenge::RVNGBinaryData created by MWAWPropertyHandlerEncoder |
62 | | bool checkData(librevenge::RVNGBinaryData const &encoded); |
63 | | //! reads a encoded librevenge::RVNGBinaryData created by MWAWPropertyHandlerEncoder |
64 | | bool readData(librevenge::RVNGBinaryData const &encoded); |
65 | | }; |
66 | | |
67 | | /*! \brief write in librevenge::RVNGBinaryData a list of tags/and properties |
68 | | * |
69 | | * In order to be read by writerperfect, we must code document consisting in |
70 | | * tag and propertyList in an intermediar format: |
71 | | * - [string:s]: an int length(s) follow by the length(s) characters of string s |
72 | | * - [property:p]: a string value p.getStr() ( for a basic property ) |
73 | | * - [propertyList:pList]: a int: \#pList followed by |
74 | | * -+ 'p',pList[i].key(),pList[i] for a basic child |
75 | | * -+ 'v',pList[i].key(),*(pList.child(pList[i].key())) for a vector child |
76 | | * - [propertyListVector:v]: a int: \#v followed by v[0], v[1], ... |
77 | | * - [binaryData:d]: a int32 d.size() followed by the data content |
78 | | * |
79 | | * - [insertElement:name]: char 'E', [string] name |
80 | | * - [insertElement:name proplist:prop]: char 'S', [string] name, prop |
81 | | * - [characters:s ]: char 'T', [string] s |
82 | | * - if len(s)==0, we write nothing |
83 | | * - the string is written as is (ie. we do not escaped any characters). |
84 | | */ |
85 | | class MWAWPropertyHandlerEncoder |
86 | | { |
87 | | public: |
88 | | //! constructor |
89 | | MWAWPropertyHandlerEncoder(); |
90 | | |
91 | | //! inserts an element |
92 | | void insertElement(const char *psName); |
93 | | //! inserts an element given a property list |
94 | | void insertElement(const char *psName, const librevenge::RVNGPropertyList &xPropList); |
95 | | //! writes a list of characters |
96 | | void characters(librevenge::RVNGString const &sCharacters); |
97 | | //! retrieves the data |
98 | | bool getData(librevenge::RVNGBinaryData &data); |
99 | | |
100 | | protected: |
101 | | //! adds a long value if f |
102 | | void writeLong(long val); |
103 | | //! adds a string: size and string |
104 | | void writeString(const librevenge::RVNGString &name); |
105 | | //! adds a property: a string key, a string corresponding to value |
106 | | void writeProperty(const char *key, const librevenge::RVNGProperty &prop); |
107 | | //! adds a property list: int \#prop followed by the different properties |
108 | | void writePropertyList(const librevenge::RVNGPropertyList &prop); |
109 | | //! adds a property vector: a int: \#vect followed by vect[0], vect[1], ... |
110 | | void writePropertyListVector(const librevenge::RVNGPropertyListVector &vect); |
111 | | |
112 | | //! the streamfile |
113 | | std::stringstream m_f; |
114 | | }; |
115 | | |
116 | | #endif |
117 | | // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |