]>
Commit | Line | Data |
---|---|---|
12c86877 BH |
1 | /* |
2 | PowerDNS Versatile Database Driven Nameserver | |
3 | Copyright (C) 2002 PowerDNS.COM BV | |
4 | ||
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 2 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program; if not, write to the Free Software | |
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | */ | |
19 | #ifndef QTYPE_HH | |
20 | #define QTYPE_HH | |
21 | /* (C) 2002 POWERDNS.COM BV */ | |
d6ed1eef | 22 | // $Id$ |
12c86877 BH |
23 | #include <string> |
24 | #include <vector> | |
25 | #include <utility> | |
26 | ||
27 | using namespace std; | |
28 | ||
29 | /** The QType class is meant to deal easily with the different kind of resource types, like 'A', 'NS', | |
30 | * 'CNAME' etcetera. These types have both a name and a number. This class can seemlessly move between | |
31 | * them. Use it like this: | |
32 | ||
33 | \code | |
34 | QType t; | |
35 | t="CNAME"; | |
36 | cout<<t.getCode()<<endl; // prints '5' | |
37 | t=6; | |
38 | cout<<t.getName()<<endl; // prints 'SOA' | |
39 | \endcode | |
40 | ||
41 | */ | |
42 | ||
43 | ||
44 | ||
45 | class QType | |
46 | { | |
47 | public: | |
48 | QType(); //!< Naked constructor | |
49 | explicit QType(int); //!< convert from an integer to a QType | |
9b145472 | 50 | QType(const char *p); //!< convert from a char* to a QType |
d3a8e1df BH |
51 | QType(const QType& orig) : code(orig.code) |
52 | { | |
53 | } | |
12c86877 BH |
54 | QType &operator=(int); //!< Assigns integers to us |
55 | QType &operator=(const char *); //!< Assings strings to us | |
56 | QType &operator=(const string &); //!< Assings strings to us | |
d3a8e1df BH |
57 | QType &operator=(const QType&rhs) //!< Assings strings to us |
58 | { | |
59 | code=rhs.code; | |
60 | return *this; | |
61 | } | |
12c86877 BH |
62 | bool operator==(const QType &) const; //!< equality operator |
63 | ||
d6ed1eef | 64 | const string getName() const; //!< Get a string representation of this type |
12c86877 BH |
65 | int getCode() const; //!< Get the integer representation of this type |
66 | ||
67 | static int chartocode(const char *p); //!< convert a character string to a code | |
68 | ||
dd103621 | 69 | enum {A=1,NS=2,CNAME=5,SOA=6,PTR=12,HINFO=13,MX=15,TXT=16,RP=17,AAAA=28,LOC=29,SRV=33,NAPTR=35, SPF=99, AXFR=252, IXFR=254, ANY=255} types; |
12c86877 BH |
70 | private: |
71 | short int code; | |
72 | typedef pair<string,int> namenum; | |
73 | void insert(char *p, int n); | |
74 | ||
75 | static vector<namenum> names; | |
76 | static bool uninit; | |
77 | }; | |
78 | ||
79 | ||
80 | #endif |