From 39224b0142078376d2bd39789b4de24a18377cf0 Mon Sep 17 00:00:00 2001 From: Mark Tiefenbruck Date: Thu, 27 Dec 2007 21:52:00 -0800 Subject: move Parser to FbTk --- src/FbMenuParser.cc | 12 ++++++------ src/FbMenuParser.hh | 8 ++++---- src/FbTk/Makefile.am | 2 +- src/FbTk/Parser.cc | 26 ++++++++++++++++++++++++++ src/FbTk/Parser.hh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/Makefile.am | 2 +- src/MenuCreator.cc | 16 ++++++++-------- src/Parser.cc | 26 -------------------------- src/Parser.hh | 51 --------------------------------------------------- 9 files changed, 98 insertions(+), 97 deletions(-) create mode 100644 src/FbTk/Parser.cc create mode 100644 src/FbTk/Parser.hh delete mode 100644 src/Parser.cc delete mode 100644 src/Parser.hh diff --git a/src/FbMenuParser.cc b/src/FbMenuParser.cc index d0f5e9b..a5f52bd 100644 --- a/src/FbMenuParser.cc +++ b/src/FbMenuParser.cc @@ -34,9 +34,9 @@ bool FbMenuParser::open(const std::string &filename) { return isLoaded(); } -Parser &FbMenuParser::operator >> (Parser::Item &out) { +FbTk::Parser &FbMenuParser::operator >> (FbTk::Parser::Item &out) { if (eof()) { - out = Parser::s_empty_item; + out = FbTk::Parser::s_empty_item; return *this; } @@ -65,7 +65,7 @@ Parser &FbMenuParser::operator >> (Parser::Item &out) { break; case DONE: // get new line and call this again if (!nextLine()) { - out = Parser::s_empty_item; + out = FbTk::Parser::s_empty_item; return *this; } return (*this)>>out; @@ -86,7 +86,7 @@ Parser &FbMenuParser::operator >> (Parser::Item &out) { else if (m_curr_token == ICON) m_curr_token = DONE; - out = Parser::s_empty_item; + out = FbTk::Parser::s_empty_item; return *this; } @@ -119,8 +119,8 @@ Parser &FbMenuParser::operator >> (Parser::Item &out) { return *this; } -Parser::Item FbMenuParser::nextItem() { - Parser::Item item; +FbTk::Parser::Item FbMenuParser::nextItem() { + FbTk::Parser::Item item; (*this)>>item; return item; } diff --git a/src/FbMenuParser.hh b/src/FbMenuParser.hh index 53bb130..923347e 100644 --- a/src/FbMenuParser.hh +++ b/src/FbMenuParser.hh @@ -25,11 +25,11 @@ #ifndef FBMENUPARSER_HH #define FBMENUPARSER_HH -#include "Parser.hh" +#include "FbTk/Parser.hh" #include -class FbMenuParser: public Parser { +class FbMenuParser: public FbTk::Parser { public: FbMenuParser():m_row(0), m_curr_pos(0), m_curr_token(TYPE) {} FbMenuParser(const std::string &filename):m_row(0), m_curr_pos(0), @@ -38,8 +38,8 @@ public: bool open(const std::string &filename); void close() { m_file.close(); } - Parser &operator >> (Parser::Item &out); - Parser::Item nextItem(); + FbTk::Parser &operator >> (FbTk::Parser::Item &out); + FbTk::Parser::Item nextItem(); bool isLoaded() const { return m_file.is_open(); } bool eof() const { return m_file.eof(); } diff --git a/src/FbTk/Makefile.am b/src/FbTk/Makefile.am index b3dd277..86f8594 100644 --- a/src/FbTk/Makefile.am +++ b/src/FbTk/Makefile.am @@ -40,7 +40,7 @@ libFbTk_a_SOURCES = App.hh App.cc Color.cc Color.hh Command.hh \ Layer.hh LayerItem.hh MultLayers.cc MultLayers.hh \ XLayer.cc XLayer.hh XLayerItem.cc XLayerItem.hh \ Resource.hh Resource.cc \ - StringUtil.hh StringUtil.cc \ + StringUtil.hh StringUtil.cc Parser.hh Parser.cc \ FbString.hh FbString.cc \ Subject.hh Subject.cc Observer.hh Observer.cc \ Transparent.hh Transparent.cc \ diff --git a/src/FbTk/Parser.cc b/src/FbTk/Parser.cc new file mode 100644 index 0000000..9e08a53 --- /dev/null +++ b/src/FbTk/Parser.cc @@ -0,0 +1,26 @@ +// Parser.cc for FbTk +// Copyright (c) 2004 - 2006 Fluxbox Team (fluxgen at fluxbox dot org) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +#include "Parser.hh" + +namespace FbTk { + const Parser::Item Parser::s_empty_item("", ""); +}; diff --git a/src/FbTk/Parser.hh b/src/FbTk/Parser.hh new file mode 100644 index 0000000..8415d4a --- /dev/null +++ b/src/FbTk/Parser.hh @@ -0,0 +1,52 @@ +// Parser.hh for FbTk +// Copyright (c) 2004 Henrik Kinnunen (fluxgen at fluxbox dot org) +// and Simon Bowden (rathnor at users.sourceforge.net) +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +#ifndef FBTK_PARSER_HH +#define FBTK_PARSER_HH + +#include +#include + +namespace FbTk { + +// interface class for a generic Parser +class Parser { +public: + typedef std::pair Item; + static const Item s_empty_item; + + virtual ~Parser() { } + + virtual bool open(const std::string &filename) = 0; + virtual void close() = 0; + virtual bool eof() const = 0; + virtual bool isLoaded() const = 0; + virtual int row() const = 0; + virtual std::string line() const = 0; + virtual Parser &operator >> (Item &out) = 0; + virtual Item nextItem() = 0; + +}; + +}; // end namespace FbTk + +#endif // FBTK_PARSER_HH diff --git a/src/Makefile.am b/src/Makefile.am index d7ed54d..dfed93b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -122,7 +122,7 @@ fluxbox_SOURCES = AtomHandler.hh ArrowButton.hh ArrowButton.cc \ CommandDialog.hh CommandDialog.cc SendToMenu.hh SendToMenu.cc \ AlphaMenu.hh AlphaMenu.cc ObjectResource.hh \ CompareWindow.hh \ - Parser.hh Parser.cc FbMenuParser.hh FbMenuParser.cc \ + FbMenuParser.hh FbMenuParser.cc \ StyleMenuItem.hh StyleMenuItem.cc \ RootCmdMenuItem.hh RootCmdMenuItem.cc\ MenuCreator.hh MenuCreator.cc \ diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc index df6f829..d68b6fd 100644 --- a/src/MenuCreator.cc +++ b/src/MenuCreator.cc @@ -143,7 +143,7 @@ class ParseItem { public: explicit ParseItem(FbTk::Menu *menu):m_menu(menu) {} - inline void load(Parser &p, FbTk::StringConvertor &m_labelconvertor) { + inline void load(FbTk::Parser &p, FbTk::StringConvertor &m_labelconvertor) { p>>m_key>>m_label>>m_cmd>>m_icon; m_label.second = m_labelconvertor.recode(m_label.second); } @@ -153,7 +153,7 @@ public: inline const string &key() const { return m_key.second; } inline FbTk::Menu *menu() { return m_menu; } private: - Parser::Item m_key, m_label, m_cmd, m_icon; + FbTk::Parser::Item m_key, m_label, m_cmd, m_icon; FbTk::Menu *m_menu; }; @@ -172,10 +172,10 @@ public: }; -static void translateMenuItem(Parser &parse, ParseItem &item, FbTk::StringConvertor &labelconvertor); +static void translateMenuItem(FbTk::Parser &parse, ParseItem &item, FbTk::StringConvertor &labelconvertor); -static void parseMenu(Parser &pars, FbTk::Menu &menu, FbTk::StringConvertor &label_convertor) { +static void parseMenu(FbTk::Parser &pars, FbTk::Menu &menu, FbTk::StringConvertor &label_convertor) { ParseItem pitem(&menu); while (!pars.eof()) { pitem.load(pars, label_convertor); @@ -185,7 +185,7 @@ static void parseMenu(Parser &pars, FbTk::Menu &menu, FbTk::StringConvertor &lab } } -static void translateMenuItem(Parser &parse, ParseItem &pitem, FbTk::StringConvertor &labelconvertor) { +static void translateMenuItem(FbTk::Parser &parse, ParseItem &pitem, FbTk::StringConvertor &labelconvertor) { if (pitem.menu() == 0) throw string("translateMenuItem: We must have a menu in ParseItem!"); @@ -315,8 +315,8 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem, FbTk::StringConve } else if (str_key == "endencoding") { MenuCreator::endEncoding(); } - else { // ok, if we didn't find any special menu item we try with command parser - // we need to attach command with arguments so command parser can parse it + else { // ok, if we didn't find any special menu item we try with command FbTk::Parser + // we need to attach command with arguments so command FbTk::Parser can parse it string line = str_key + " " + str_cmd; FbTk::RefCount command(FbTk::ObjectRegistry::instance().parse(line)); if (*command != 0) { @@ -341,7 +341,7 @@ static void translateMenuItem(Parser &parse, ParseItem &pitem, FbTk::StringConve } -static void parseWindowMenu(Parser &parse, FbTk::Menu &menu, FbTk::StringConvertor &labelconvertor) { +static void parseWindowMenu(FbTk::Parser &parse, FbTk::Menu &menu, FbTk::StringConvertor &labelconvertor) { ParseItem pitem(&menu); while (!parse.eof()) { diff --git a/src/Parser.cc b/src/Parser.cc deleted file mode 100644 index 3461c0e..0000000 --- a/src/Parser.cc +++ /dev/null @@ -1,26 +0,0 @@ -// Parser.cc -// Copyright (c) 2004 - 2006 Fluxbox Team (fluxgen at fluxbox dot org) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -// $Id$ - -#include "Parser.hh" - -const Parser::Item Parser::s_empty_item("", ""); diff --git a/src/Parser.hh b/src/Parser.hh deleted file mode 100644 index 30f2a95..0000000 --- a/src/Parser.hh +++ /dev/null @@ -1,51 +0,0 @@ -// IconMenuItem.hh for Fluxbox Window Manager -// Copyright (c) 2004 Henrik Kinnunen (fluxgen at fluxbox dot org) -// and Simon Bowden (rathnor at users.sourceforge.net) -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -// $Id$ - -#ifndef PARSER_HH -#define PARSER_HH - -#include -#include - -// interface class for a generic Parser -class Parser { -public: - typedef std::pair Item; - static const Item s_empty_item; - - virtual ~Parser() { } - - virtual bool open(const std::string &filename) = 0; - virtual void close() = 0; - virtual bool eof() const = 0; - virtual bool isLoaded() const = 0; - virtual int row() const = 0; - virtual std::string line() const = 0; - virtual Parser &operator >> (Item &out) = 0; - virtual Item nextItem() = 0; - -}; - - -#endif // PARSER_HH -- cgit v0.11.2