Back to index

unity  6.0.0
Variant.h
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2011 Canonical Ltd
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 3 as
00007  * published by the Free Software Foundation.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  *
00017  * Authored by: Tim Penhey <tim.penhey@canonical.com>
00018  */
00019 
00020 #ifndef UNITY_VARIANT_H
00021 #define UNITY_VARIANT_H
00022 
00023 #include <string>
00024 #include <glib.h>
00025 #include <map>
00026 
00027 #include <NuxCore/Rect.h>
00028 
00029 namespace unity
00030 {
00031 namespace glib
00032 {
00033 
00034 class Variant;
00035 typedef std::map<std::string, Variant> HintsMap;
00036 
00037 struct StealRef {};
00038 
00039 class Variant
00040 {
00041 public:
00042   Variant();
00043   Variant(GVariant*);
00044   Variant(GVariant*, StealRef const&);
00045 
00046   Variant(Variant const&);
00047   ~Variant();
00048 
00049   std::string GetString() const;
00050   int GetInt() const;
00051   unsigned GetUInt() const;
00052   bool GetBool() const;
00053 
00054   bool ASVToHints(HintsMap& hints) const;
00055 
00056   Variant& operator=(GVariant*);
00057   operator GVariant*() const;
00058 private:
00059   GVariant* variant_;
00060 };
00061 
00062 }
00063 
00064 namespace variant
00065 {
00066 
00067 class BuilderWrapper
00068 {
00069 public:
00070   BuilderWrapper(GVariantBuilder* builder);
00071 
00072   BuilderWrapper& add(char const* name, bool value);
00073   BuilderWrapper& add(char const* name, char const* value);
00074   BuilderWrapper& add(char const* name, std::string const& value);
00075   BuilderWrapper& add(char const* name, int value);
00076   BuilderWrapper& add(char const* name, long int value);
00077   BuilderWrapper& add(char const* name, long long int value);
00078   BuilderWrapper& add(char const* name, unsigned int value);
00079   BuilderWrapper& add(char const* name, long unsigned int value);
00080   BuilderWrapper& add(char const* name, long long unsigned int value);
00081   BuilderWrapper& add(char const* name, float value);
00082   BuilderWrapper& add(char const* name, double value);
00083   BuilderWrapper& add(char const* name, GVariant* value);
00084   BuilderWrapper& add(nux::Rect const& value);
00085 
00086 private:
00087   GVariantBuilder* builder_;
00088 };
00089 
00090 }
00091 }
00092 
00093 #endif