nis-util  1.0.D108
lib/configuration/section.cc
Go to the documentation of this file.
00001 //
00002 // nis-util - NIS Administration Utilities
00003 // Copyright (C) 2012 Peter Miller
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 as published by
00007 // the Free Software Foundation; either version 2 of the License, or (at
00008 // your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License along
00016 // with this program. If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 
00019 #include <lib/configuration/section.h>
00020 
00021 
00022 configuration_section::~configuration_section()
00023 {
00024 }
00025 
00026 
00027 configuration_section::configuration_section(const rcstring &a_name) :
00028     name(a_name)
00029 {
00030 }
00031 
00032 
00033 configuration_section::pointer
00034 configuration_section::create(const rcstring &a_name)
00035 {
00036     return pointer(new configuration_section(a_name));
00037 }
00038 
00039 
00040 bool
00041 configuration_section::is_set(const rcstring &item_name)
00042     const
00043 {
00044     return (items.find(item_name) != items.end());
00045 }
00046 
00047 
00048 rcstring
00049 configuration_section::get_string_value(const rcstring &item_name)
00050     const
00051 {
00052     items_t::const_iterator it = items.find(item_name);
00053     if (it == items.end())
00054         return rcstring();
00055     assert(it->second);
00056     return it->second->get_string_value();
00057 }
00058 
00059 
00060 bool
00061 configuration_section::get_bool_value(const rcstring &item_name)
00062     const
00063 {
00064     items_t::const_iterator it = items.find(item_name);
00065     if (it == items.end())
00066         return false;
00067     assert(it->second);
00068     return it->second->get_bool_value();
00069 }
00070 
00071 
00072 long
00073 configuration_section::get_long_value(const rcstring &item_name)
00074     const
00075 {
00076     items_t::const_iterator it = items.find(item_name);
00077     if (it == items.end())
00078         return 0;
00079     assert(it->second);
00080     return it->second->get_long_value();
00081 }
00082 
00083 
00084 void
00085 configuration_section::set(const configuration_item::pointer &item)
00086 {
00087     assert(item);
00088     items_t::iterator it = items.find(item->get_name());
00089     if (it == items.end())
00090     {
00091         items.insert(items_t::value_type(item->get_name(), item));
00092     }
00093     else
00094     {
00095         assert(it->second);
00096 #if 0
00097         fprintf(stderr, "%s: %d: new level = %s (%d)\n", __FILE__, __LINE__,
00098             configuration_item::level_name(item->get_level()),
00099             item->get_level());
00100         fprintf(stderr, "%s: %d: old level = %s (%d)\n", __FILE__, __LINE__,
00101             configuration_item::level_name(it->second->get_level()),
00102             it->second->get_level());
00103 #endif
00104         if (item->get_level() > it->second->get_level())
00105             it->second = item;
00106     }
00107 }
00108 
00109 
00110 // vim: set ts=8 sw=4 et :