// test programs
#ifndef BADSITENAMEEXCEPTION_CC
#define BADSITENAMEEXCEPTION_CC
#include "TemasBase.h"
#include <ctype.h>
#ifdef __USE_STD_IOSTREAM
#include <exception.h>
#else
#include <exception>
#endif
#include <string>
using namespace std;
class BadSiteNameException : public exception
{
string Error_string;
public:
BadSiteNameException()
{
Error_string = "BadSiteNameException";
}
BadSiteNameException( const BadSiteNameException &E )
{
Error_string = E.Error_string;
}
BadSiteNameException( string S )
{
Error_string += S;
}
~BadSiteNameException(){}
virtual const char* what()
{
return Error_string.data();
}
void test( string name_string ) throw(BadSiteNameException)
{
if( name_string.length() > MaxLengthName )
{
string S = "BadSiteNameException: Invalid site name. ";
S += name_string;
S += " is longer than ";
S += "6";
S += "\n";
throw new BadSiteNameException( S );
}
for(int i = 0; i < name_string.length(); i++ )
{
if( ( isalnum( name_string[i] ) || name_string[i] == '_' ) )
continue;
else
{
throw BadSiteNameException( "BadSiteNameException: Invalid site name. " + name_string +
" must be alphanumeric or have a _.\n" );
}
}
} // test
};
#endif // BadSiteNameException