1 #ifndef _GLIBMM_QUARK_H 2 #define _GLIBMM_QUARK_H 3 4 /* quark.h 5 * 6 * Copyright 2002 The gtkmm Development Team 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 22 #include <glibmmconfig.h> 23 #include <glibmm/ustring.h> 24 #include <glib.h> 25 26 namespace Glib 27 { 28 29 /** Quarks are unique IDs in Glib for strings for use in 30 * hash table lookups. Each Quark is unique but may change 31 * between runs. 32 * 33 * QueryQuark is a converter class for looking up but not 34 * allocating an ID. An id means the quark lookup failed. 35 * 36 * Quark is used for actions for which the id should live on 37 * While QueryQuark should be used for queries. 38 * ie. 39 * void set_data (const Quark&, void * data); 40 * void* get_data (const QueryQuark&); 41 */ 42 class GLIBMM_API QueryQuark 43 { 44 public: 45 QueryQuark(const GQuark& q); 46 QueryQuark(const ustring& s); 47 QueryQuark(const char* s); ~QueryQuark()48 ~QueryQuark() noexcept {} 49 QueryQuark& operator=(const QueryQuark& q); 50 operator ustring() const; 51 GQuark()52 operator GQuark() const { return quark_; } id()53 GQuark id() const { return quark_; } 54 55 private: 56 GQuark quark_; 57 }; 58 59 class GLIBMM_API Quark : public QueryQuark 60 { 61 public: 62 Quark(const ustring& s); 63 Quark(const char* s); 64 ~Quark() noexcept; 65 }; 66 67 /** @relates Glib::QueryQuark */ 68 inline bool 69 operator==(const QueryQuark& a, const QueryQuark& b) 70 { 71 return a.id() == b.id(); 72 } 73 74 /** @relates Glib::QueryQuark */ 75 inline bool 76 operator!=(const QueryQuark& a, const QueryQuark& b) 77 { 78 return a.id() != b.id(); 79 } 80 81 #ifndef DOXYGEN_SHOULD_SKIP_THIS 82 // TODO: Put this somewhere else. 83 // (internal) The quark for C++ wrappers. 84 extern GLIBMM_API GQuark quark_; 85 extern GLIBMM_API GQuark quark_cpp_wrapper_deleted_; 86 #endif 87 88 } /* namespace Glib */ 89 90 #endif /* _GLIBMM_QUARK_H */ 91