Removed "using namespace std" statements from header files in EO -- "std::" identifier were added where necessary.

This commit is contained in:
okoenig 2003-02-27 19:28:07 +00:00
commit 86fa476c67
263 changed files with 2009 additions and 1976 deletions

View file

@ -5,14 +5,14 @@ File............: eo2dVector.h
Author..........: Geneura Team (this file: Victor Rivas, vrivas@ujaen.es)
Date............: 29-Sep-1999, at Fac. of Sciences, Univ. of Granada (Spain)
Description.....: Implementation of a 2-dimensional chromosome usign STL
vectors.
std::vectors.
================ Modif. 1 ================
Author........:
Date..........:
Description...:
QUEDA: Operador de asignación, lectura desde istream, escritura a ostream
QUEDA: Operador de asignación, lectura desde std::istream, escritura a std::ostream
-----------------------------------------------------------------------------
*/
//-----------------------------------------------------------------------------
@ -42,20 +42,20 @@ QUEDA: Operador de asignaci
#define _eo2dVector_H
// STL libraries
#include <vector> // For vector<int>
#include <vector> // For std::vector<int>
#include <stdexcept>
#include <strstream>
#include <iostream.h>
#include <ostream.h>
#include <eo2d.h>
#include <eoRnd.h>
/** Adaptor that turns an STL vector of vectror into an EO
/** Adaptor that turns an STL std::vector of vectror into an EO
with the same gene type as the type with which
the vector of vector has been instantiated.
the std::vector of std::vector has been instantiated.
*/
template <class T, class fitnessT>
class eo2dVector: public eo2d<T, fitnessT>, public vector< vector<T> > {
class eo2dVector: public eo2d<T, fitnessT>, public std::vector< std::vector<T> > {
public:
typedef T Type ;
@ -72,7 +72,7 @@ public:
eo2dVector( const unsigned _rows = 0,
const unsigned _cols = 0,
T _val = T() )
: eo2d<T, fitnessT>(), vector< vector<T> >( _rows, vector<T>( _cols, _val ) ){};
: eo2d<T, fitnessT>(), std::vector< std::vector<T> >( _rows, std::vector<T>( _cols, _val ) ){};
/** Ctor using a random number generator.
@param _rows Number of rows.
@ -83,23 +83,23 @@ public:
const unsigned _cols,
eoRnd<T>& _rnd );
/** Ctor from a istream. The T class should accept reading from a istream. It doesn't read fitness,
/** Ctor from a std::istream. The T class should accept reading from a std::istream. It doesn't read fitness,
which is supposed to be dynamic and dependent on environment.
@param _is the input stream; should have all values in a single line, separated by whitespace
*/
//eo2dVector( istream& _is);
//eo2dVector( std::istream& _is);
/// copy ctor
eo2dVector( const eo2dVector & _eo )
: eo2d<T, fitnessT>( _eo ), vector< vector<T> >( _eo ){ };
: eo2d<T, fitnessT>( _eo ), std::vector< std::vector<T> >( _eo ){ };
/// Assignment operator
/*
const eo2dVector& operator =( const eo2dVector & _eo ) {
if ( this != &_eo ){
eo2d<T, fitnessT>::operator=( _eo );
vector< <vector<T> >::operator=( _eo );
std::vector< <std::vector<T> >::operator=( _eo );
}
return *this;
}
@ -113,21 +113,21 @@ public:
@param _r Index for rows. Must be an unsigned less than #numOfRows()#
@param _c Index for columns. Must be an unsigned less than #numOfCols()#
@return what's inside the gene, with the correct type
@exception out_of_range if _r >=numOfRows()
@exception out_of_range if _c >=numOfCols()
@std::exception out_of_range if _r >=numOfRows()
@std::exception out_of_range if _c >=numOfCols()
*/
virtual T getGene( const unsigned _r,
const unsigned _c ) const {
if ( _r >= numOfRows() ) {
ostrstream msg;
std::ostrstream msg;
msg << "ERROR in eo2dVector::getGene: row out of range. "
<< "It should be <" << numOfRows() << '\0' << endl;
<< "It should be <" << numOfRows() << '\0' << std::endl;
throw out_of_range( msg.str() );
}
if ( _c >= numOfCols() ) {
ostrstream msg;
std::ostrstream msg;
msg << "ERROR in eo2dVector::getGene: column out of range. "
<< "It should be <" << numOfCols() << '\0' << endl;
<< "It should be <" << numOfCols() << '\0' << std::endl;
throw out_of_range( msg.str() );
}
return (*this)[_r][_c];
@ -138,22 +138,22 @@ public:
@param _r Index for rows. Must be an unsigned less than #numOfRows()#
@param _c Index for columns. Must be an unsigned less than #numOfCols()#
@return what's inside the gene, with the correct type
@exception out_of_range if _r >=numOfRows()
@exception out_of_range if _c >=numOfCols()
@std::exception out_of_range if _r >=numOfRows()
@std::exception out_of_range if _c >=numOfCols()
*/
virtual void setGene( const unsigned _r,
const unsigned _c,
const T& _value ) {
if ( _r >= numOfRows() ) {
ostrstream msg;
std::ostrstream msg;
msg << "ERROR in eo2dVector::setGene: row out of range. "
<< "It should be <" << numOfRows() << '\0' << endl;
<< "It should be <" << numOfRows() << '\0' << std::endl;
throw out_of_range( msg.str() );
}
if ( _c >= numOfCols() ) {
ostrstream msg;
std::ostrstream msg;
msg << "ERROR in eo2dVector::setGene: column out of range. "
<< "It should be <" << numOfCols() << '\0' << endl;
<< "It should be <" << numOfCols() << '\0' << std::endl;
throw out_of_range( msg.str() );
}
(*this)[_r][_c]=_value;
@ -166,47 +166,47 @@ public:
* Obviously, changes number of rows.
@param _r Position where the new row will be inserted.
@param _val Vector containing the new values to be inserted.
@exception invalid_argument If _val has not numOfCols() components.
@exception out_of_range If _r is greater than numOfRows()
@std::exception invalid_argument If _val has not numOfCols() components.
@std::exception out_of_range If _r is greater than numOfRows()
*/
virtual void insertRow( const unsigned _r,
const vector<T>& _val ) {
const std::vector<T>& _val ) {
// Test errors.
if ( _r > numOfRows() ) {
ostrstream msg;
std::ostrstream msg;
msg << "ERROR in eo2dVector::insertRow: row out of range. "
<< "It should be <=" << numOfRows() << '\0' << endl;
<< "It should be <=" << numOfRows() << '\0' << std::endl;
throw out_of_range( msg.str() );
}
if ( _val.size() != numOfCols() ) {
ostrstream msg;
std::ostrstream msg;
msg << "ERROR in eo2dVector::insertRow: "
<< "Incorrect number of values to be added. "
<< "It should be ==" << numOfCols() << '\0' << endl;
<< "It should be ==" << numOfCols() << '\0' << std::endl;
throw invalid_argument( msg.str() );
}
// Insert the row.
vector< vector<T> >::iterator ite = begin()+_r;
std::vector< std::vector<T> >::iterator ite = begin()+_r;
insert( ite, _val );
};
/** Eliminates the row at position _r; all the other genes will
be shifted up.
@param _r Number of he row to be deleted.
@exception out_of_range if _r >=numOfRows()
@std::exception out_of_range if _r >=numOfRows()
*/
virtual void deleteRow( const unsigned _r ) {
// Test error.
if ( _r >= numOfRows() ) {
ostrstream msg;
std::ostrstream msg;
msg << "ERROR in eo2dVector::deleteRow: "
<< "Row out of range. "
<< "It should be <" << numOfRows() << '\0' << endl;
<< "It should be <" << numOfRows() << '\0' << std::endl;
throw out_of_range( msg.str() );
}
// Delete row.
vector< vector<T> >::iterator ite = this->begin()+_r;
std::vector< std::vector<T> >::iterator ite = this->begin()+_r;
this->erase( ite );
};
@ -215,30 +215,30 @@ public:
* Obviously, changes number of cols.
@param _r Position where the new column will be inserted.
@param _val Vector containing the new values to be inserted.
@exception invalid_argument if _val has not numOfRows() components.
@std::exception invalid_argument if _val has not numOfRows() components.
*/
virtual void insertCol( const unsigned _c,
const vector<T>& _val ) {
const std::vector<T>& _val ) {
// Test errors.
if ( _c > numOfCols() ) {
ostrstream msg;
std::ostrstream msg;
msg << "ERROR in eo2dVector::insertCol: "
<< "Column out of range. "
<< "It should be >=" << numOfCols() << '\0' << endl;
<< "It should be >=" << numOfCols() << '\0' << std::endl;
throw out_of_range( msg.str() );
}
if ( _val.size() != numOfRows() ) {
ostrstream msg;
std::ostrstream msg;
msg << "ERROR in eo2dVector::insertCol: "
<< "Incorrect number of values to be added. "
<< "It should be ==" << numOfRows() << '\0' << endl;
<< "It should be ==" << numOfRows() << '\0' << std::endl;
throw invalid_argument( msg.str() );
}
// Insert column.
for( unsigned r=0; r<numOfRows(); ++r ) {
vector<vector<T> >::iterator it1 = begin()+r;
vector<T>::iterator it2 = (*it1).begin()+_c;
std::vector<std::vector<T> >::iterator it1 = begin()+r;
std::vector<T>::iterator it2 = (*it1).begin()+_c;
(*it1).insert( it2, _val[r] );
};
}
@ -246,21 +246,21 @@ public:
/** Eliminates the column at position _c; all the other columns will
be shifted left.
@param _c Number of he column to be deleted.
@exception out_of_range if _c >=numOfCols()
@std::exception out_of_range if _c >=numOfCols()
*/
virtual void deleteCol( const unsigned _c ) {
// Test error.
if ( _c >= numOfCols() ) {
ostrstream msg;
std::ostrstream msg;
msg << "ERROR in eo2dVector::deleteCol: "
<< "Column out of range. "
<< "It should be <" << numOfCols() << '\0' << endl;
<< "It should be <" << numOfCols() << '\0' << std::endl;
throw out_of_range( msg.str() );
}
// Delete columns.
for( unsigned r=0; r<numOfRows(); ++r ) {
vector<vector<T> >::iterator it1 = begin()+r;
vector<T>::iterator it2 = (*it1).begin()+_c;
std::vector<std::vector<T> >::iterator it1 = begin()+r;
std::vector<T>::iterator it2 = (*it1).begin()+_c;
(*it1).erase( it2 );
}
};
@ -283,7 +283,7 @@ public:
/** Inherited from eoObject
@see eoObject
*/
string className() const {return "eo2dVector";};
std::string className() const {return "eo2dVector";};
//@}
};
@ -297,9 +297,9 @@ template <class T, class fitnessT>
eo2dVector<T,fitnessT>::eo2dVector( const unsigned _rows,
const unsigned _cols,
eoRnd<T>& _rnd )
: eo2d<T, fitnessT>(), vector< vector<T> >( _rows, vector<T>( _cols, T() ) ){
for ( vector< vector<T> >::iterator i = begin(); i != end(); ++i ) {
for( vector<T>::iterator j=(*i).begin(); j!= (*i).end(); ++j ) {
: eo2d<T, fitnessT>(), std::vector< std::vector<T> >( _rows, std::vector<T>( _cols, T() ) ){
for ( std::vector< std::vector<T> >::iterator i = begin(); i != end(); ++i ) {
for( std::vector<T>::iterator j=(*i).begin(); j!= (*i).end(); ++j ) {
*j = _rnd();
}
}
@ -307,8 +307,8 @@ eo2dVector<T,fitnessT>::eo2dVector( const unsigned _rows,
//_____________________________________________________________________________
/*template <class T, class fitnessT>
eoVector<T,fitnessT>::eoVector( istream& _is)
: eo1d<T, fitnessT>(), vector<T>( ){
eoVector<T,fitnessT>::eoVector( std::istream& _is)
: eo1d<T, fitnessT>(), std::vector<T>( ){
while (_is ) {
T tmp;
_is >> tmp;
@ -320,12 +320,12 @@ eoVector<T,fitnessT>::eoVector( istream& _is)
//_____________________________________________________________________________
template <class T, class fitnessT>
ostream& operator<<( ostream& _os, const eo2dVector<T,fitnessT>& _eo) {
std::ostream& operator<<( std::ostream& _os, const eo2dVector<T,fitnessT>& _eo) {
for( unsigned i=0; i<_eo.numOfRows(); ++i ) {
for( unsigned j=0; j<_eo.numOfCols(); ++j ) {
_os << _eo.getGene( i,j ) << " ";
}
_os << endl;
_os << std::endl;
}
return _os;
};