/* Copyright (c) 1997-2004
   Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
   http://www.math.tu-berlin.de/polymake,  mailto:polymake@math.tu-berlin.de

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version: http://www.gnu.org/licenses/gpl.txt.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
*/

#ident "$Project: polymake $$Id: is_manifold.cc,v 1.13 2005/05/12 10:32:07 witte Exp $"

#include <Poly.h>
#include <Array.h>
#include <complex_tools.h>
#include <argv_options.h>

#include <string>

namespace polymake {
namespace topaz {
  
namespace {

enum { quiet };

}

void is_manifold(std::ostream& os, Poly& p, const argv_option *options)
{
   const Array< Set<int> > C = p.give("FACETS");
   const int d = p.give("DIM");
   
   bool is_manifold = true;
   if (d>3)
      throw std::runtime_error("is_manifold: Dimension of the complex must be smaller 4.");
   
   else if (d==1)
      is_manifold = C1_is_manifold(C);
   
   else if (d==2)
      is_manifold = C2_is_manifold(C);
   
   else if (d==3)
      is_manifold = C3_is_manifold(os,C,options[quiet]);
   
   p.take("MANIFOLD") << is_manifold;
}
   
} }

using namespace polymake;

/** @file is_manifold
 *
 *  Check whether a complex is a manifold.
 *  The client works for manifolds of dim 3 or smaller only.
 *
 *  @synopsis is_manifold <file> [ -quiet ]
 *
 *  @reading  FACETS, DIM
 *  @writing  MANIFOLD
 */

int main(int argc, const char* argv[])
{
   argv_option options[]={ {"-quiet"} };
   if (!extract_options(argc,argv,1,options) || argc!=2) {
      cerr << "usage: " << argv[0] << " <file> [ -quiet ]" << endl;
      return 1;
   }
   try {
      Poly p(argv[1], ios::in | ios::out);
      topaz::is_manifold(std::cout, p, options);
   }
   catch (const std::exception& e) {
      cerr << e.what() << endl;
      return 1;
   }
   return 0;
}


// Local Variables:
// mode:C++
// c-basic-offset:3
// End:
