/*
_______________________________________________________________________________

                              TableGenerator v1.3

-------------------------------------------------------------------------------
Copyright (c) 2007-2010 Kai Braaten

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-------------------------------------------------------------------------------
*/

#include <iostream>
#include <list>
#include "tablegenerator.hpp"

struct Person
{
  Person( const std::string&, int a, const std::string& );
  ~Person();
  std::string name;
  int age;
  std::string hobby;
};

Person::Person( const std::string &n, int a, const std::string &h )
  : name( n ), age( a ), hobby( h )
{

}

Person::~Person()
{

}

TableGen::TableRow &operator<<( TableGen::TableRow &row, const Person &p )
{
  row << p.name << p.age << p.hobby;
  return row;
}

std::list< Person > personList;

void fillList();

int main()
{
  std::cout << TableGen::version() << '\n';

  fillList();
  TableGen::SimpleTable stbl;
  TableGen::TableGenerator table( &stbl );
  TableGen::TableRow header;
  header << "Name:" << "Age:" << "Hobby:";
  table << header;
  //table << "Name:\tAge:\tHobby:";
  for( std::list< Person >::iterator i = personList.begin();
       i != personList.end(); ++i )
    {
      const Person &p = *i;
      TableGen::TableRow row;
      //row << p.name << p.age << p.hobby;
      row << p; // Use the lovely insertion operator defined above
      table << row;
    }

  // A totally plain table
  std::cout << table << '\n';

  // Standard framed table
  TableGen::FramedTable ftbl( 1, 1 );
  table << &ftbl;
  std::cout << '\n' << table << '\n';

  // With custom frame graphics
  TableGen::FramedTable ftblcust( 1, 1, "", "", "", "#=+" );
  table << &ftblcust;
  std::cout << '\n' << table << '\n';

  // Plain table, but stacked horizontally
  // Note that the SimpleTable strategy doesn't use headers,
  // So our headers from above becomes data instead here.
  TableGen::SimpleTable st2( 1, 2, 2 );
  table << &st2;
  std::cout << '\n' << table << '\n';

  // Fancy table with drop shadow
  TableGen::ShadowTable shadow( "Shadow Table",
				"<c f=\"yellow\">",  // text
				"<c b=\"blue\">",  // back fill
				"<c b=\"dark grey\">",  // shadow
				"<c s=\"reset\">",  // stop colour (black)
				1,           // side padding
				3,           // column padding
				0,           // indentation
				"</c>", "<br/>" );
  table << &shadow;

  std::cout << '\n' << table << '\n';

  std::cout << "\033[0m"; // reset colour

  // HTML table
  TableGen::HtmlTable html( true, // Treat first row as table header
			    0,    // Border width
			    "TableGenerator Test" ); // Page title
  table << &html;

  std::cout << '\n' << table << '\n';
}

void fillList()
{
  personList.push_back( Person( "Billy", 25, "Swimming in the lake." ) );
  personList.push_back( Person( "Bob", 65, "Puffing my pipe." ) );
  personList.push_back( Person( "Donald Duck", 70, "Quack, quack!" ) );
  personList.push_back( Person( "Jane", 24, "Screaming for help." ) );
  personList.push_back( Person( "Tarzan", 35, "Saving Jane" ) );
}