2012-05-10 12:06:41 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
|
|
|
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
2012-05-11 13:33:57 +02:00
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
2012-05-10 12:06:41 +02:00
|
|
|
******************************************************************************/
|
|
|
|
|
2012-04-02 08:56:30 +02:00
|
|
|
#ifndef CONFIGOBJECT_H
|
|
|
|
#define CONFIGOBJECT_H
|
2012-03-31 15:18:09 +02:00
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
2012-06-12 09:36:18 +02:00
|
|
|
class I2_BASE_API ConfigObject : public Object
|
2012-03-31 15:18:09 +02:00
|
|
|
{
|
|
|
|
public:
|
2012-04-02 20:50:35 +02:00
|
|
|
typedef shared_ptr<ConfigObject> Ptr;
|
|
|
|
typedef weak_ptr<ConfigObject> WeakPtr;
|
2012-03-31 15:18:09 +02:00
|
|
|
|
2012-06-12 09:36:18 +02:00
|
|
|
typedef ObjectMap<pair<string, string>, ConfigObject::Ptr> TNMap;
|
|
|
|
typedef ObjectMap<string, ConfigObject::Ptr> TMap;
|
|
|
|
typedef ObjectSet<ConfigObject::Ptr> Set;
|
2012-04-04 10:04:38 +02:00
|
|
|
|
2012-06-13 13:42:55 +02:00
|
|
|
ConfigObject(Dictionary::Ptr properties, const Set::Ptr& container = Set::Ptr());
|
|
|
|
ConfigObject(string type, string name, const Set::Ptr& container = Set::Ptr());
|
2012-03-31 15:18:09 +02:00
|
|
|
|
2012-06-12 09:36:18 +02:00
|
|
|
void SetProperties(Dictionary::Ptr config);
|
|
|
|
Dictionary::Ptr GetProperties(void) const;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void SetProperty(const string& key, const T& value)
|
|
|
|
{
|
|
|
|
GetProperties()->SetProperty(key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
bool GetProperty(const string& key, T *value) const
|
|
|
|
{
|
|
|
|
return GetProperties()->GetProperty(key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
Dictionary::Ptr GetTags(void) const;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void SetTag(const string& key, const T& value)
|
|
|
|
{
|
|
|
|
GetTags()->SetProperty(key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
bool GetTag(const string& key, T *value) const
|
|
|
|
{
|
|
|
|
return GetTags()->GetProperty(key, value);
|
|
|
|
}
|
2012-03-31 15:18:09 +02:00
|
|
|
|
|
|
|
string GetType(void) const;
|
2012-06-12 09:36:18 +02:00
|
|
|
string GetName(void) const;
|
|
|
|
|
|
|
|
void SetLocal(bool value);
|
|
|
|
bool IsLocal(void) const;
|
2012-04-20 14:20:25 +02:00
|
|
|
|
2012-06-27 18:43:34 +02:00
|
|
|
void SetTemporary(bool value);
|
|
|
|
bool IsTemporary(void) const;
|
|
|
|
|
2012-06-12 09:36:18 +02:00
|
|
|
void SetAbstract(bool value);
|
|
|
|
bool IsAbstract(void) const;
|
2012-05-09 10:15:51 +02:00
|
|
|
|
|
|
|
void Commit(void);
|
2012-06-12 09:36:18 +02:00
|
|
|
void Unregister(void);
|
|
|
|
|
|
|
|
static ObjectSet<ConfigObject::Ptr>::Ptr GetAllObjects(void);
|
|
|
|
|
|
|
|
static TNMap::Ptr GetObjectsByTypeAndName(void);
|
|
|
|
static TMap::Ptr GetObjectsByType(void);
|
|
|
|
|
|
|
|
static ConfigObject::Ptr GetObject(string type, string name);
|
|
|
|
|
|
|
|
static TMap::Range GetObjects(string type);
|
|
|
|
|
|
|
|
static function<bool (ConfigObject::Ptr)> MakeTypePredicate(string type);
|
2012-05-21 23:42:54 +02:00
|
|
|
|
|
|
|
private:
|
2012-06-13 13:42:55 +02:00
|
|
|
Set::Ptr m_Container;
|
2012-06-12 09:36:18 +02:00
|
|
|
Dictionary::Ptr m_Properties;
|
|
|
|
Dictionary::Ptr m_Tags;
|
|
|
|
|
|
|
|
static bool TypeAndNameGetter(const ConfigObject::Ptr& object, pair<string, string> *key);
|
|
|
|
static bool TypePredicate(const ConfigObject::Ptr& object, string type);
|
2012-05-21 23:42:54 +02:00
|
|
|
|
2012-06-12 09:36:18 +02:00
|
|
|
static bool TypeGetter(const ConfigObject::Ptr& object, string *key);
|
2012-03-31 15:18:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-04-02 08:56:30 +02:00
|
|
|
#endif /* CONFIGOBJECT_H */
|