packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmPropertyMap.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #include "cmPropertyMap.h"
13 #include "cmSystemTools.h"
14 #include "cmake.h"
15
16 cmProperty *cmPropertyMap::GetOrCreateProperty(const char *name)
17 {
18   cmPropertyMap::iterator it = this->find(name);
19   cmProperty *prop;
20   if (it == this->end())
21     {
22     prop = &(*this)[name];
23     }
24   else
25     {
26     prop = &(it->second);
27     }
28   return prop;
29 }
30
31 void cmPropertyMap::SetProperty(const char *name, const char *value,
32                                 cmProperty::ScopeType scope)
33 {
34   if (!name)
35     {
36     return;
37     }
38   if(!value)
39     {
40     this->erase(name);
41     return;
42     }
43 #ifdef CMAKE_STRICT
44   if (!this->CMakeInstance)
45     {
46     cmSystemTools::Error("CMakeInstance not set on a property map!");
47     abort();
48     }
49   else
50     {
51     this->CMakeInstance->RecordPropertyAccess(name,scope);
52     }
53 #else
54   (void)scope;
55 #endif
56
57   cmProperty *prop = this->GetOrCreateProperty(name);
58   prop->Set(name,value);
59 }
60
61 void cmPropertyMap::AppendProperty(const char* name, const char* value,
62                                    cmProperty::ScopeType scope, bool asString)
63 {
64   // Skip if nothing to append.
65   if(!name || !value || !*value)
66     {
67     return;
68     }
69 #ifdef CMAKE_STRICT
70   if (!this->CMakeInstance)
71     {
72     cmSystemTools::Error("CMakeInstance not set on a property map!");
73     abort();
74     }
75   else
76     {
77     this->CMakeInstance->RecordPropertyAccess(name,scope);
78     }
79 #else
80   (void)scope;
81 #endif
82
83   cmProperty *prop = this->GetOrCreateProperty(name);
84   prop->Append(name,value,asString);
85 }
86
87 const char *cmPropertyMap
88 ::GetPropertyValue(const char *name,
89                    cmProperty::ScopeType scope,
90                    bool &chain) const
91 {
92   chain = false;
93   if (!name)
94     {
95     return 0;
96     }
97
98   // has the property been defined?
99 #ifdef CMAKE_STRICT
100   if (!this->CMakeInstance)
101     {
102     cmSystemTools::Error("CMakeInstance not set on a property map!");
103     abort();
104     }
105   else
106     {
107     this->CMakeInstance->RecordPropertyAccess(name,scope);
108     }
109 #endif
110
111   cmPropertyMap::const_iterator it = this->find(name);
112   if (it == this->end())
113     {
114     // should we chain up?
115     if (this->CMakeInstance)
116       {
117       chain = this->CMakeInstance->IsPropertyChained(name,scope);
118       }
119     return 0;
120     }
121   return it->second.GetValue();
122 }
123