File indexing completed on 2024-04-28 05:32:12

0001 #ifndef oxygenoptionmap_h
0002 #define oxygenoptionmap_h
0003 /*
0004 * this file is part of the oxygen gtk engine
0005 * SPDX-FileCopyrightText: 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0006 *
0007 * inspired notably from kdelibs/kdeui/color/kcolorutils.h
0008 * SPDX-FileCopyrightText: 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
0009 * SPDX-FileCopyrightText: 2007 Thomas Zander <zander@kde.org>
0010 * SPDX-FileCopyrightText: 2007 Zack Rusin <zack@kde.org>
0011 *
0012 * SPDX-License-Identifier: LGPL-2.0-or-later
0013 */
0014 
0015 #include "oxygenoption.h"
0016 
0017 #include <map>
0018 #include <set>
0019 #include <string>
0020 
0021 namespace Oxygen
0022 {
0023     // all options from kde globals
0024     class OptionMap: public std::map<std::string, Option::Set>
0025     {
0026         public:
0027 
0028         //! constructor
0029         OptionMap( void )
0030         {}
0031 
0032         //! constructor from filename
0033         OptionMap( const std::string& );
0034 
0035         //! destructor
0036         virtual ~OptionMap( void )
0037         {}
0038 
0039         //! equal to operator
0040         bool operator == ( const OptionMap& ) const;
0041 
0042         //! differ from operator
0043         bool operator != (const OptionMap& other ) const
0044         { return !(*this == other ); }
0045 
0046         //! merge with other map
0047         /*! when options are duplicated between two maps, the second overwrite the first */
0048         OptionMap& merge( const OptionMap& );
0049 
0050         //! true if option is in map
0051         bool hasOption( const std::string& section, const std::string& tag ) const;
0052 
0053         //! find option in map
0054         Option getOption( const std::string& section, const std::string& tag ) const;
0055 
0056         //! find option in map
0057         std::string getValue( const std::string& section, const std::string& tag, const std::string& defaultValue = "" ) const
0058         {
0059             Option option( getOption( section, tag ) );
0060             return option == tag ? option.value():defaultValue;
0061         }
0062 
0063         //! streamer
0064         friend std::ostream& operator << (std::ostream& out, const OptionMap& options )
0065         {
0066             for( OptionMap::const_iterator iter = options.begin(); iter != options.end(); ++iter )
0067             {
0068                 out << iter->first << std::endl;
0069                 out << iter->second << std::endl;
0070             }
0071             return out;
0072         }
0073 
0074     };
0075 
0076 }
0077 
0078 #endif