/*-------------------------------------------------------------------------------------*/
/*  NOMAD - Nonsmooth Optimization by Mesh Adaptive Direct search - version 3.0.0      */
/*                                                                                     */
/*  Copyright (C) 2001-2008  Mark Abramson        - the Boeing Company, Seattle        */
/*                           Charles Audet        - Ecole Polytechnique, Montreal      */
/*                           Gilles Couture       - Ecole Polytechnique, Montreal      */
/*                           John Dennis          - Rice University, Houston           */
/*                           Sebastien Le Digabel - Ecole Polytechnique, Montreal      */
/*                                                                                     */
/*  funded in part by AFOSR and Exxon Mobil                                            */
/*                                                                                     */
/*  Author: Sebastien Le Digabel                                                       */
/*                                                                                     */
/*  Contact information:                                                               */
/*    Ecole Polytechnique de Montreal - GERAD                                          */
/*    C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada                  */
/*    e-mail: Sebastien.Le.Digabel@gerad.ca                                            */
/*    phone : 1-514-340-6053 #6673                                                     */
/*    fax   : 1-514-340-5665                                                           */
/*                                                                                     */
/*  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 3 of the License, or (at your option) any later         */
/*  version.                                                                           */
/*                                                                                     */
/*  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.          */
/*                                                                                     */
/*  You should have received a copy of the GNU General Public License along with this  */
/*  program. If not, see <http://www.gnu.org/licenses/>.                               */
/*                                                                                     */
/*  You can find information on the NOMAD software at www.gerad.ca/nomad               */
/*-------------------------------------------------------------------------------------*/
#ifndef __UTILS__
#define __UTILS__

#include "defines.hpp"
#include <cctype>
#include <vector>
#include <list>
#include <iomanip>
#include <cmath>

// use of 'access' or '_access' :
#ifdef _MSC_VER
#include <io.h>
#else
#include <unistd.h>
#endif

// display functions for enum types defined in 'defines.hpp':
std::ostream & operator << ( std::ostream & out , success_type       );
std::ostream & operator << ( std::ostream & out , bb_input_type      );
std::ostream & operator << ( std::ostream & out , stop_type          );
std::ostream & operator << ( std::ostream & out , bb_output_type     );
std::ostream & operator << ( std::ostream & out , hnorm_type         );
std::ostream & operator << ( std::ostream & out , search_type        );
std::ostream & operator << ( std::ostream & out , direction_type     );
std::ostream & operator << ( std::ostream & out , check_failed_type  );
std::ostream & operator << ( std::ostream & out , display_stats_type );

// to display a vector of bb-input type's :
std::ostream & operator << ( std::ostream & , const std::vector<bb_input_type> & );

// to get the keyword associated with a display_stats_type:
std::string get_display_stats_keyword ( display_stats_type dst );

// get the display_stats_type from a string:
display_stats_type get_display_stats_type ( const std::string & s );

// convert a string into a bb_input_type:
bool string_to_bb_input_type ( const std::string & , bb_input_type & );

// convert a string 'i-j' into the integers i and j
//  (if s=="*" and n is defined, then i=0 and j=*n-1):
bool string_to_index_range ( const std::string & s                  ,
			     int               & i                  ,
			     int               & j                  ,
			     int               * n           = NULL ,
			     bool                check_order = true   );

// convert a string in {"YES","NO","Y","N"} to a bool
// (returns -1 if conversion failed):
int string_to_bool ( const std::string & s );

// display a bool with format yes/no:
void display_yes_or_no ( bool b , std::ostream & out = std::cout );

// to display a size in memory:
void display_sizeof ( int size , std::ostream & out = std::cout );

// to display a display degree:
void display_display_degree ( int dd , std::ostream & out = std::cout );

// interpret a list of strings as a direction type:
bool interpret_direction_type ( const std::list<std::string> & ls ,
				direction_type               & dt   );

// if a bb_output_type corresponds to a constraint:
bool bbot_is_constraint ( bb_output_type );

// if a direction is a MADS direction:
bool dir_is_mads ( direction_type );

// if a direction is a GPS direction:
bool dir_is_gps ( direction_type );

// if a direction is a LT-MADS direction:
bool dir_is_ltmads ( direction_type dt );

// if a direction is a Ortho-MADS direction:
bool dir_is_orthomads ( direction_type dt );

// if a direction is a random direction:
bool dir_is_random ( direction_type );

// construct the first nc prime numbers :
void construct_primes ( int n , int * primes );

// custom functions:
namespace NOMAD {
  std::string itos    ( int           i );
  void        toupper ( std::string & s );
  bool        atoi    ( const std::string & s , int & i );
  bool        atoi    ( char c , int & i );

  // decompose a string (sentence) into words:
  void get_words ( const std::string & sentence , std::list<std::string> & words );

  // check if a file exists and is executable:
  bool check_exe_file  ( const std::string & file_name );

  // check if a file exists and is readable:
  bool check_read_file ( const std::string & file_name );

}

#endif
