Code:
#ifndef CONTAINER_H
#define CONTAINER_H
#include <iostream>
#include <string>
class Streamable {
virtual std::ostream& put( std::ostream& o ) const = 0;
friend std::ostream& operator<<( std::ostream& o, const Streamable& s );
friend std::ostream& operator<<( std::ostream& o, const Streamable* const s );
public:
virtual ~Streamable( ) {}
};
inline std::ostream& operator<<( std::ostream& o, const Streamable& s ) { return s.put( o ); }
inline std::ostream& operator<<( std::ostream& o, const Streamable* const s ) { return s->put( o ); }
class Container : public Streamable {
protected:
Container( ) { }
public:
typedef unsigned long Key;
enum Order { dontcare, ascending, descending };
class Functor;
class Exception;
virtual ~Container( ) { }
virtual void add( Key key ) { add( &key, 1 ); }
virtual void add( Key keys[], unsigned long size ) = 0;
virtual void remove( Key key ) { remove( &key, 1 ); }
virtual void remove( Key keys[], unsigned long size ) = 0;
virtual bool isMember( Key key ) const = 0;
virtual unsigned long size( ) const = 0;
virtual bool isEmpty( ) const { return size( ) == 0; }
virtual void foreach( const Functor& f, Order order = dontcare ) const = 0;
virtual Key minKey( ) const = 0;
virtual Key maxKey( ) const = 0;
virtual int teamNr( ) const = 0;
virtual int themeNr( ) const = 0;
};
class Container::Exception : public Streamable {
std::string msg;
virtual std::ostream& put( std::ostream& o ) const { return o << "Container::Exception (" << msg << ")"; }
public:
Exception( const std::string& msg ) : msg( msg ) {}
virtual ~Exception( ) {}
};
class Container::Functor {
public:
virtual bool operator( )( Key key ) const = 0;
virtual ~Functor( ) {}
};
#endif //CONTAINER_H
#ifndef CONTAINER_H
#define CONTAINER_H
#include <iostream>
#include <string>
class Streamable {
virtual std::ostream& put( std::ostream& o ) const = 0;
friend std::ostream& operator<<( std::ostream& o, const Streamable& s );
friend std::ostream& operator<<( std::ostream& o, const Streamable* const s );
public:
virtual ~Streamable( ) {}
};
inline std::ostream& operator<<( std::ostream& o, const Streamable& s ) { return s.put( o ); }
inline std::ostream& operator<<( std::ostream& o, const Streamable* const s ) { return s->put( o ); }
class Container : public Streamable {
protected:
Container( ) { }
public:
typedef unsigned long Key;
enum Order { dontcare, ascending, descending };
class Functor;
class Exception;
virtual ~Container( ) { }
virtual void add( Key key ) { add( &key, 1 ); }
virtual void add( Key keys[], unsigned long size ) = 0;
virtual void remove( Key key ) { remove( &key, 1 ); }
virtual void remove( Key keys[], unsigned long size ) = 0;
virtual bool isMember( Key key ) const = 0;
virtual unsigned long size( ) const = 0;
virtual bool isEmpty( ) const { return size( ) == 0; }
virtual void foreach( const Functor& f, Order order = dontcare ) const = 0;
virtual Key minKey( ) const = 0;
virtual Key maxKey( ) const = 0;
virtual int teamNr( ) const = 0;
virtual int themeNr( ) const = 0;
};
class Container::Exception : public Streamable {
std::string msg;
virtual std::ostream& put( std::ostream& o ) const { return o << "Container::Exception (" << msg << ")"; }
public:
Exception( const std::string& msg ) : msg( msg ) {}
virtual ~Exception( ) {}
};
class Container::Functor {
public:
virtual bool operator( )( Key key ) const = 0;
virtual ~Functor( ) {}
};
#endif //CONTAINER_H