1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
/*
* File: DICTClient.hh
* Version: 0.9
* History: see DICTClient.cc
*
* Legalese
* Copyright (C) 1999 Sudhakar Chandrasekharan (thaths@netscape.com)
*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef DICT_HH
#define DICT_HH
#include <string>
#include <vector>
class DICTClient {
private:
DICTClient(const DICTClient & other);
DICTClient & operator=(const DICTClient & other);
public:
DICTClient(const char * h = "dict.org", int p = 2628);
~DICTClient() {hangup();}
void dial(); // Connect to dict server */
void hangup(); // diconnect from dict server
void setHost(const char * h = "dict.org", int p = 2628);
// set dict server
const char * getHost(); // Get name of dict server
int getPort(); // Get port of dict server
bool isConnected() {return connected;}
struct Definition {
string book;
string definition;
Definition(const string & b) : book(b) {}
};
typedef vector<Definition> Definitions;
Definitions lookup(const char *, const char * book = "*");
// Looks up a defination and
struct Exception {
virtual string message() const = 0;
virtual ~Exception() {}
};
struct BadPort : public Exception {
int port;
BadPort(int p) : port(p) {}
string message() const;
};
struct InvalidHost : public Exception {
string host_name;
InvalidHost(const string & n) : host_name(n) {}
string message() const;
};
struct CannotMapTcpToProtocolNumber : public Exception {
string message() const {return "Cannot map \"tcp\" to protocol number";}
};
struct SocketCreationFailed : public Exception {
string message() const {return "Socket creation failed";}
};
struct SetsockoptFailed : public Exception {
string message() const {return "setsockopt() failed";}
};
struct ConnectFailed : public Exception {
string message() const {return "connect() failed";}
};
struct NotConnected : public Exception {
string message() const {return "Not connected";}
};
struct ServerDisconnected : public Exception {
string message() const {return "The server disconnected";}
};
private:
int sd; /* socket descriptor */
string host; /* dict server */
int port; /* port of dict server */
int connected; /* A flag to indicate whether connected */
int readline(int, char *, int);
string find_book(const char *);
};
struct WordNetDefinition {
string part_of_speech;
string number;
string definition;
};
vector<WordNetDefinition> wordnet_split(const string &);
#endif
|