2002-05-31 14:43:23 +00:00
|
|
|
#ifndef CCONFIG_H
|
|
|
|
#define CCONFIG_H
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
#include "BasicTypes.h"
|
|
|
|
#include "CString.h"
|
2002-06-09 16:53:25 +00:00
|
|
|
#include "CNetworkAddress.h"
|
2002-05-31 17:32:26 +00:00
|
|
|
#include "XBase.h"
|
|
|
|
#include <iosfwd>
|
2002-06-01 19:26:11 +00:00
|
|
|
#include "stdmap.h"
|
2002-06-08 23:24:40 +00:00
|
|
|
#include "stdset.h"
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2002-05-31 18:35:53 +00:00
|
|
|
class CConfig;
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
struct iterator_traits<CConfig> {
|
|
|
|
typedef CString value_type;
|
|
|
|
typedef ptrdiff_t difference_type;
|
|
|
|
typedef bidirectional_iterator_tag iterator_category;
|
|
|
|
typedef CString* pointer;
|
|
|
|
typedef CString& reference;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2002-05-31 14:43:23 +00:00
|
|
|
class CConfig {
|
2002-04-29 14:40:01 +00:00
|
|
|
public:
|
2001-10-06 14:13:28 +00:00
|
|
|
enum EDirection { kLeft, kRight, kTop, kBottom,
|
|
|
|
kFirstDirection = kLeft, kLastDirection = kBottom };
|
2001-11-19 00:33:36 +00:00
|
|
|
enum EDirectionMask { kLeftMask = 1, kRightMask = 2,
|
|
|
|
kTopMask = 4, kBottomMask = 8 };
|
2002-05-30 16:13:16 +00:00
|
|
|
private:
|
|
|
|
class CCell {
|
|
|
|
public:
|
|
|
|
CString m_neighbor[kLastDirection - kFirstDirection + 1];
|
|
|
|
};
|
2002-06-03 18:53:18 +00:00
|
|
|
typedef std::map<CString, CCell, CStringUtil::CaselessCmp> CCellMap;
|
2002-05-30 16:13:16 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
typedef CCellMap::const_iterator internal_const_iterator;
|
2002-05-31 18:35:53 +00:00
|
|
|
class const_iterator : std::iterator_traits<CConfig> {
|
2002-05-30 16:13:16 +00:00
|
|
|
public:
|
|
|
|
explicit const_iterator() : m_i() { }
|
|
|
|
explicit const_iterator(const internal_const_iterator& i) : m_i(i) { }
|
|
|
|
|
|
|
|
const_iterator& operator=(const const_iterator& i) {
|
|
|
|
m_i = i.m_i;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
CString operator*() { return m_i->first; }
|
|
|
|
const CString* operator->() { return &(m_i->first); }
|
|
|
|
const_iterator& operator++() { ++m_i; return *this; }
|
|
|
|
const_iterator operator++(int) { return const_iterator(m_i++); }
|
|
|
|
const_iterator& operator--() { --m_i; return *this; }
|
|
|
|
const_iterator operator--(int) { return const_iterator(m_i--); }
|
|
|
|
bool operator==(const const_iterator& i) const {
|
|
|
|
return (m_i == i.m_i);
|
|
|
|
}
|
|
|
|
bool operator!=(const const_iterator& i) const {
|
|
|
|
return (m_i != i.m_i);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2002-06-01 19:26:11 +00:00
|
|
|
internal_const_iterator m_i;
|
2002-05-30 16:13:16 +00:00
|
|
|
};
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2002-05-31 14:43:23 +00:00
|
|
|
CConfig();
|
|
|
|
virtual ~CConfig();
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
// manipulators
|
|
|
|
|
2002-06-03 18:53:18 +00:00
|
|
|
// note that case is preserved in screen names but is ignored when
|
2002-06-08 23:24:40 +00:00
|
|
|
// comparing names. screen names and their aliases share a
|
|
|
|
// namespace and must be unique.
|
|
|
|
|
|
|
|
// add/remove screens. addScreen() returns false if the name
|
|
|
|
// already exists. the remove methods automatically remove
|
|
|
|
// aliases for the named screen and disconnect any connections
|
|
|
|
// to the removed screen(s).
|
|
|
|
bool addScreen(const CString& name);
|
2001-10-06 14:13:28 +00:00
|
|
|
void removeScreen(const CString& name);
|
|
|
|
void removeAllScreens();
|
|
|
|
|
2002-06-08 23:24:40 +00:00
|
|
|
// add/remove alias for a screen name. an alias can be used
|
|
|
|
// any place the canonical screen name can (except addScreen).
|
|
|
|
// addAlias() returns false if the alias name already exists
|
|
|
|
// or the canonical name is unknown. removeAlias() fails if
|
|
|
|
// the alias is unknown or a canonical name.
|
|
|
|
bool addAlias(const CString& canonical,
|
|
|
|
const CString& alias);
|
|
|
|
bool removeAlias(const CString& alias);
|
|
|
|
void removeAllAliases();
|
|
|
|
|
|
|
|
// connect/disconnect edges. both return false if srcName is
|
|
|
|
// unknown.
|
|
|
|
bool connect(const CString& srcName,
|
2001-10-06 14:13:28 +00:00
|
|
|
EDirection srcSide,
|
|
|
|
const CString& dstName);
|
2002-06-08 23:24:40 +00:00
|
|
|
bool disconnect(const CString& srcName,
|
2001-10-06 14:13:28 +00:00
|
|
|
EDirection srcSide);
|
|
|
|
|
2002-06-09 16:53:25 +00:00
|
|
|
// set the synergy and http listen addresses. there are no
|
|
|
|
// default addresses.
|
|
|
|
void setSynergyAddress(const CNetworkAddress&);
|
|
|
|
void setHTTPAddress(const CNetworkAddress&);
|
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
// accessors
|
|
|
|
|
2002-05-31 17:32:26 +00:00
|
|
|
// returns true iff the given name is a valid screen name.
|
|
|
|
bool isValidScreenName(const CString&) const;
|
|
|
|
|
2002-06-08 23:24:40 +00:00
|
|
|
// iterators over (canonical) screen names
|
2002-05-30 16:13:16 +00:00
|
|
|
const_iterator begin() const;
|
|
|
|
const_iterator end() const;
|
|
|
|
|
2002-05-31 17:32:26 +00:00
|
|
|
// returns true iff name names a screen
|
2002-05-31 18:08:08 +00:00
|
|
|
bool isScreen(const CString& name) const;
|
2002-05-31 17:32:26 +00:00
|
|
|
|
2002-06-08 23:24:40 +00:00
|
|
|
// returns true iff name is the canonical name of a screen
|
|
|
|
bool isCanonicalName(const CString& name) const;
|
|
|
|
|
|
|
|
// returns the canonical name of a screen or the empty string if
|
|
|
|
// the name is unknown. returns the canonical name if one is given.
|
|
|
|
CString getCanonicalName(const CString& name) const;
|
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
// get the neighbor in the given direction. returns the empty string
|
2002-06-08 23:24:40 +00:00
|
|
|
// if there is no neighbor in that direction. returns the canonical
|
|
|
|
// screen name.
|
2001-10-14 16:58:01 +00:00
|
|
|
CString getNeighbor(const CString&, EDirection) const;
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2002-06-09 16:53:25 +00:00
|
|
|
// get the listen addresses
|
|
|
|
const CNetworkAddress& getSynergyAddress() const;
|
|
|
|
const CNetworkAddress& getHTTPAddress() const;
|
|
|
|
|
2002-05-31 17:32:26 +00:00
|
|
|
// read/write a configuration. operator>> will throw XConfigRead
|
|
|
|
// on error.
|
2002-06-01 19:26:11 +00:00
|
|
|
friend std::istream& operator>>(std::istream&, CConfig&);
|
|
|
|
friend std::ostream& operator<<(std::ostream&, const CConfig&);
|
2002-05-31 17:32:26 +00:00
|
|
|
|
2001-10-14 14:37:41 +00:00
|
|
|
// get the name of a direction (for debugging)
|
|
|
|
static const char* dirName(EDirection);
|
|
|
|
|
2002-05-31 17:32:26 +00:00
|
|
|
private:
|
2002-06-01 19:26:11 +00:00
|
|
|
static bool readLine(std::istream&, CString&);
|
|
|
|
void readSection(std::istream&);
|
2002-06-09 16:53:25 +00:00
|
|
|
void readSectionNetwork(std::istream&);
|
2002-06-01 19:26:11 +00:00
|
|
|
void readSectionScreens(std::istream&);
|
|
|
|
void readSectionLinks(std::istream&);
|
2002-06-08 23:24:40 +00:00
|
|
|
void readSectionAliases(std::istream&);
|
2002-05-31 17:32:26 +00:00
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
private:
|
2002-06-08 23:24:40 +00:00
|
|
|
typedef std::map<CString, CString, CStringUtil::CaselessCmp> CNameMap;
|
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
CCellMap m_map;
|
2002-06-08 23:24:40 +00:00
|
|
|
CNameMap m_nameToCanonicalName;
|
2002-06-09 16:53:25 +00:00
|
|
|
CNetworkAddress m_synergyAddress;
|
|
|
|
CNetworkAddress m_httpAddress;
|
2001-10-06 14:13:28 +00:00
|
|
|
};
|
|
|
|
|
2002-05-31 17:32:26 +00:00
|
|
|
class XConfigRead : public XBase {
|
|
|
|
public:
|
|
|
|
XConfigRead(const CString&);
|
|
|
|
~XConfigRead();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// XBase overrides
|
|
|
|
virtual CString getWhat() const throw();
|
|
|
|
|
|
|
|
private:
|
|
|
|
CString m_error;
|
|
|
|
};
|
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
#endif
|