1 /* ---------------------------------------------------------------------------- 2 libconfig - A library for processing structured configuration files 3 libconfig chained - Extension for reading the configuration and defining 4 the configuration specification at once. 5 Copyright (C) 2016 Richard Schubert 6 7 This file is part of libconfig contributions. 8 9 This library is free software; you can redistribute it and/or 10 modify it under the terms of the GNU Lesser General Public License 11 as published by the Free Software Foundation; either version 2.1 of 12 the License, or (at your option) any later version. 13 14 This library is distributed in the hope that it will be useful, but 15 WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 Lesser General Public License for more details. 18 19 You should have received a copy of the GNU Library General Public 20 License along with this library; if not, see 21 <http://www.gnu.org/licenses/>. 22 ---------------------------------------------------------------------------- 23 */ 24 25 #include <iostream> 26 #include <iomanip> 27 #include <cstdlib> 28 #include <libconfig.h++> 29 30 using namespace std; 31 using namespace libconfig; 32 33 // This is the main entry point for all examples. 34 // The examples will be called consecutively. 35 36 void example1(Config& cfg); 37 void example2(Config& cfg); 38 void example3(Config& cfg); 39 main(int argc,char ** argv)40int main(int argc, char **argv) 41 { 42 Config cfg; 43 44 // Read the file. If there is an error, report it and exit. 45 try 46 { 47 cfg.readFile("../example.cfg"); 48 } 49 catch(const FileIOException&) 50 { 51 std::cerr << "I/O error while reading file. " << std::endl; 52 return(EXIT_FAILURE); 53 } 54 catch(const ParseException& pex) 55 { 56 std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine() 57 << " - " << pex.getError() << std::endl; 58 return(EXIT_FAILURE); 59 } 60 61 cout << endl << endl << "<<< Example 1 >>>" << endl << endl; 62 example1(cfg); 63 cout << endl << endl << "<<< Example 2 >>>" << endl << endl; 64 example2(cfg); 65 cout << endl << endl << "<<< Example 3 >>>" << endl << endl; 66 example3(cfg); 67 68 return(EXIT_SUCCESS); 69 } 70