
#include <iostream>
#include <iwear/configuration.h>
#include <iwear/iniloader.h>
#include <iwear/inisaver.h>
#include <iwear/debugstream.h>
#include <fstream>

using namespace std;
using namespace iwear;

int main ( int argc, char* argv[] )
{
    bool skipfill = false;
    if( argc == 3 && argv[2][0] == 'x' )
    {
	skipfill = true;
    }
    std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
    enable_verbose_crash();

    d_err.set_debuglevel(nonsens);
    d_err.set_debuglevel(nonsens,debugarea::iwear_config);
//    d_err.set_debuglevel(warning);
    
    string file(argv[1]);
    Configuration conf("/tmp/","./");

    IniLoader ilo(file,conf);

    try
    {
	ilo.reload();
    }
    catch( const exception& e )
    {
	cout << e << endl;
    }

    if( !skipfill )
    {


	conf.insert("iwear/sensor/temporal2","3.0","This is a comment for the temporal2 value");
	conf.insert("iwear/no-sensor/temporal1","3.0");
	conf.insert("iwear/no-sensor/temporal2","3.0");
	conf.insert("iwear/no-sensor/temporal/",std::string("This is a comment for a path value"),0);
	conf.insert("iwear/no-sensor/temporal/sub1","3.0");
	conf.insert("iwear/no-sensor/temporal/sub2","3.0");

	cout << conf.get<float>("iwear/no-sensor/temporal/sub2") << endl;
	cout << conf.get<double>("iwear/no-sensor/temporal/sub2") << endl;
	cout << conf.get<string>("iwear/no-sensor/temporal/sub2") << endl;
	//    cout << conf.get<int>("iwear/no-sensor/temporal/sub2") << endl;

	IniSaver isv(file+".ini",conf);
	try
	{
	    isv.save("iwear");
	}
	catch(const exception& e )
	{
	    cout << e << endl;
	}

	ofstream of("ini.dot");
	//    conf.dot(of);

	conf.deprecate("iwear/no-sensor/temporal1");
	conf.remove("iwear/no-sensor/temporal2");

    }
    IniSaver isvx(file+"2.ini",conf);
    try
    {
	isvx.save("/");
    }
    catch(const exception& e )
    {
	cout << e << endl;
    }


    return 0;
}
