~focus-follows-mouse/ubuntu/oneiric/compiz/fix-883383

« back to all changes in this revision

Viewing changes to src/valueholder.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2011-07-19 08:00:29 UTC
  • mto: This revision was merged to the branch mainline in revision 235.
  • Revision ID: james.westby@ubuntu.com-20110719080029-lxt3wxch8uqkxro0
Tags: upstream-0.9.5.0
Import upstream version 0.9.5.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2010 Canonical Ltd.
 
3
 *
 
4
 * Permission to use, copy, modify, distribute, and sell this software
 
5
 * and its documentation for any purpose is hereby granted without
 
6
 * fee, provided that the above copyright notice appear in all copies
 
7
 * and that both that copyright notice and this permission notice
 
8
 * appear in supporting documentation, and that the name of
 
9
 * Canonical Ltd. not be used in advertising or publicity pertaining to
 
10
 * distribution of the software without specific, written prior permission.
 
11
 * Canonical Ltd. makes no representations about the suitability of this
 
12
 * software for any purpose. It is provided "as is" without express or
 
13
 * implied warranty.
 
14
 *
 
15
 * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
16
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
 
17
 * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
18
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
 
19
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 
20
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 
21
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
22
 *
 
23
 * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
 
24
 */
 
25
 
 
26
#include <core/valueholder.h>
 
27
#include <map>
 
28
 
 
29
namespace
 
30
{
 
31
  static ValueHolder *gDefault;
 
32
}
 
33
 
 
34
class PrivateValueHolder
 
35
{
 
36
    public:
 
37
 
 
38
        std::map<CompString, CompPrivate> valueMap;
 
39
};
 
40
 
 
41
ValueHolder::ValueHolder () :
 
42
    priv (new PrivateValueHolder)
 
43
{
 
44
}
 
45
 
 
46
ValueHolder *
 
47
ValueHolder::Default ()
 
48
{
 
49
    return gDefault;
 
50
}
 
51
 
 
52
void
 
53
ValueHolder::SetDefault (ValueHolder *v)
 
54
{
 
55
    gDefault = v;
 
56
}
 
57
 
 
58
void
 
59
ValueHolder::storeValue (CompString key, CompPrivate value)
 
60
{
 
61
    std::map<CompString,CompPrivate>::iterator it;
 
62
 
 
63
    it = priv->valueMap.find (key);
 
64
 
 
65
    if (it != priv->valueMap.end ())
 
66
    {
 
67
        it->second = value;
 
68
    }
 
69
    else
 
70
    {
 
71
        priv->valueMap.insert (std::pair<CompString,CompPrivate> (key, value));
 
72
    }
 
73
}
 
74
 
 
75
void
 
76
ValueHolder::eraseValue (CompString key)
 
77
{
 
78
    std::map<CompString,CompPrivate>::iterator it;
 
79
    it = priv->valueMap.find (key);
 
80
 
 
81
    if (it != priv->valueMap.end ())
 
82
    {
 
83
        priv->valueMap.erase (key);
 
84
    }
 
85
}
 
86
 
 
87
bool
 
88
ValueHolder::hasValue (CompString key)
 
89
{
 
90
    return (priv->valueMap.find (key) != priv->valueMap.end ());
 
91
}
 
92
 
 
93
CompPrivate
 
94
ValueHolder::getValue (CompString key)
 
95
{
 
96
    CompPrivate p;
 
97
 
 
98
    std::map<CompString,CompPrivate>::iterator it;
 
99
    it = priv->valueMap.find (key);
 
100
 
 
101
    if (it != priv->valueMap.end ())
 
102
    {
 
103
        return it->second;
 
104
    }
 
105
    else
 
106
    {
 
107
        p.uval = 0;
 
108
        return p;
 
109
    }
 
110
}