1 /*************************************************************************
2 ** SpecialManager.h                                                     **
3 **                                                                      **
4 ** This file is part of dvisvgm -- the DVI to SVG converter             **
5 ** Copyright (C) 2005-2015 Martin Gieseking <martin.gieseking@uos.de>   **
6 **                                                                      **
7 ** This program is free software; you can redistribute it and/or        **
8 ** modify it under the terms of the GNU General Public License as       **
9 ** published by the Free Software Foundation; either version 3 of       **
10 ** the License, or (at your option) any later version.                  **
11 **                                                                      **
12 ** This program is distributed in the hope that it will be useful, but  **
13 ** WITHOUT ANY WARRANTY; without even the implied warranty of           **
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the         **
15 ** GNU General Public License for more details.                         **
16 **                                                                      **
17 ** You should have received a copy of the GNU General Public License    **
18 ** along with this program; if not, see <http://www.gnu.org/licenses/>. **
19 *************************************************************************/
20 
21 #ifndef DVISVGM_SPECIALMANAGER_H
22 #define DVISVGM_SPECIALMANAGER_H
23 
24 #include <map>
25 #include <ostream>
26 #include <string>
27 #include <vector>
28 #include "SpecialHandler.h"
29 
30 struct SpecialActions;
31 
32 class SpecialManager
33 {
34 	private:
35 		typedef std::vector<SpecialHandler*> HandlerPool;
36 		typedef std::map<std::string,SpecialHandler*> HandlerMap;
37 		typedef HandlerMap::iterator Iterator;
38 		typedef HandlerMap::const_iterator ConstIterator;
39 
40 	public:
41 		~SpecialManager ();
42 		static SpecialManager& instance ();
43 		void registerHandler (SpecialHandler *handler);
44 		void registerHandlers (SpecialHandler **handlers, const char *ignorelist);
45 		void unregisterHandlers ();
46 		void preprocess (const std::string &special, SpecialActions *actions) const;
47 		bool process (const std::string &special, double dvi2bp, SpecialActions *actions) const;
48 		void notifyPreprocessingFinished () const;
49 		void notifyEndPage (unsigned pageno) const;
50 		void notifyPositionChange (double x, double y) const;
51 		void writeHandlerInfo (std::ostream &os) const;
52 
53 	protected:
SpecialManager()54 		SpecialManager () {}
SpecialManager(const SpecialManager &)55 		SpecialManager (const SpecialManager &) {}
56 		SpecialHandler* findHandler (const std::string &prefix) const;
57 
58 	private:
59 		HandlerPool _pool;     ///< stores pointers to all handlers
60 		HandlerMap _handlers;  ///< pointers to handlers for corresponding prefixes
61 		std::vector<DVIPreprocessingListener*> _preprocListeners;
62 		std::vector<DVIEndPageListener*> _endPageListeners;
63 		std::vector<DVIPositionListener*> _positionListeners;
64 };
65 
66 #endif
67