nis-util  1.0.D108
lib/configuration/item/boolean.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 <libexplain/output.h>
00020 
00021 #include <lib/boolean.h>
00022 #include <lib/configuration/item/boolean.h>
00023 
00024 
00025 configuration_item_boolean::~configuration_item_boolean()
00026 {
00027 }
00028 
00029 
00030 configuration_item_boolean::configuration_item_boolean(
00031     const source_location &a_locn,
00032     level_t a_level,
00033     const rcstring &a_name,
00034     bool a_value
00035 ) :
00036     configuration_item(a_locn, a_level, a_name),
00037     value(a_value)
00038 {
00039 }
00040 
00041 
00042 configuration_item_boolean::pointer
00043 configuration_item_boolean::create(const source_location &a_locn,
00044     level_t a_level, const rcstring &a_name, bool a_value)
00045 {
00046     return
00047         pointer
00048         (
00049             new configuration_item_boolean(a_locn, a_level, a_name, a_value)
00050         );
00051 }
00052 
00053 
00054 bool
00055 configuration_item_boolean::candidate(const rcstring &ptext, bool &pvalue)
00056 {
00057     return boolean_from_string(ptext, pvalue);
00058 }
00059 
00060 
00061 configuration_item_boolean::pointer
00062 configuration_item_boolean::create_if_candidate(const source_location &a_locn,
00063     level_t a_level, const rcstring &a_name, const rcstring &pvalue)
00064 {
00065     bool a_value = false;
00066     if (!candidate(pvalue, a_value))
00067         return pointer();
00068     return create(a_locn, a_level, a_name, a_value);
00069 }
00070 
00071 
00072 rcstring
00073 configuration_item_boolean::get_string_value(void)
00074     const
00075 {
00076     // Don't complain, needed for the configuration_item::point method.
00077     return string_from_boolean(value);
00078 }
00079 
00080 
00081 long
00082 configuration_item_boolean::get_long_value(void)
00083     const
00084 {
00085     explain_output_error_and_die
00086     (
00087         "%s: item %s: boolean value \"%s\" supplied, integer value required",
00088         get_source_location().get_both().c_str(),
00089         get_name().quote_c().c_str(),
00090         string_from_boolean(value)
00091     );
00092     return value;
00093 }
00094 
00095 
00096 bool
00097 configuration_item_boolean::get_bool_value(void)
00098     const
00099 {
00100     return value;
00101 }
00102 
00103 
00104 // vim: set ts=8 sw=4 et :