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