assume we always have strings.h
[libfirm] / ir / tv / IeeeCC754 / include / Hex.h
1 /*
2 ##########################################################################
3 #                                                                        #
4 # Program: IeeeCC754                                                     #
5 #                                                                        #
6 # Description:                                                           #
7 #   IeeeCC754 or IEEE 754 Compliance Checker is a precision and range    #
8 #   independent tool to test whether an implementation of                #
9 #   floating-point arithmetic (in hardware or software) is compliant     #
10 #   with the principles of the IEEE 754-854 floating-point standards.    #
11 #   You can find out more about the testing tool IeeeCC754 at            #
12 #                                                                        #
13 #         http://win-www.uia.ac.be/u/cant/ieeecc754.html                 #
14 #                                                                        #
15 #   This tool is in parts based on and greatly benefited from the        #
16 #   the program FPTEST developed by Jerome Coonen. For a full            #
17 #   description of the extensions to FPTEST and a reference to           #
18 #   the original Coonen program, please refer to the URL given above.    #
19 #   For the options available with the program IeeeCC754 and its         #
20 #   compatibility with David Hough's hexadecimal UCB format, we          #
21 #   also refer to the file readme.usage.                                 #
22 #                                                                        #
23 #  Usage: see readme.usage                                               #
24 #                                                                        #
25 #  Responsible authors:                                                  #
26 #         Brigitte Verdonk                                               #
27 #         Annie Cuyt                                                     #
28 #                                                                        #
29 #  Contributors:                                                         #
30 #         Johan Bogo (1998-1999)                                         #
31 #         Tim Gevers (10-12/2000)                                        #
32 #         Debby Ooms (1996-1997)                                         #
33 #         Geert Vermuyten (1996-1997)                                    #
34 #         Dennis Verschaeren (09/1996-06/2000)                           #
35 #                                                                        #
36 #  Copyright (C) 2000  University of Antwerp                             #
37 #                                                                        #
38 #  This program can be obtained from the authors, free, but WITHOUT ANY  #
39 #  WARRANTY; without even the implied warranty of MERCHANTABILITY or     #
40 #  FITNESS FOR A PARTICULAR PURPOSE.                                     #
41 #                                                                        #
42 #  Contact:                                                              #
43 #       Brigitte.Verdonk@uia.ua.ac.be                                    #
44 #       Department of Mathematics and Computer Science                   #
45 #       University of Antwerp (UIA)                                      #
46 #       Universiteitsplein 1                                             #
47 #       B2610 Antwerp, BELGIUM                                           #
48 #                                                                        #
49 ##########################################################################
50
51 Filename:
52        $RCSfile$
53
54 Last updated:
55        $Date$
56
57 */
58
59 /***************************************************************************
60 * This is a class definition for hexadecimal input of the bitstrings class.
61 * Hex is inherited from bitstring, so there are no data members necessery.
62 * The only thing that has to be done is to define the functions that change
63 * in behaviour.
64 ************************************************************************** */
65 #ifndef _HEXSTR_H
66 #define _HEXSTR_H
67
68
69 #include <iostream.h>
70 #include <Bitstring.h>
71
72 /*class definition*/
73
74 /**
75   This class manipulates the Bitstring class as a hexadecimal string of bits.
76   The only difference in the
77   hexadecimal representation is the length of the string, as it
78   is four times smaller than the binary representation.
79
80    All the members are defined in the class Bitstring, therefore there are no
81   extra data members in this class.
82
83   @author Bogo Johan
84  */
85
86 class Hex : public Bitstring
87 {
88
89 protected:
90   /** returns the binairy value of character v
91     @param v: character between 0-9 and A-F or a-F
92     @return: the binary value of v*/
93   void GetBin(char v);
94
95   /** returns the character value of the Bitstring b
96      @param b: binary value, from 0000-1111
97      @return: the character value of b*/
98   char GetHex(Bitstring& b) const;
99
100
101 public:
102   /* *  Constructor, creates empty Bitstring */ */
103   Hex();
104
105   /** Constructor
106     @param size: specifies the initial size of the bitstring.
107                  The size is multiplied by 4 for a bistring.*/
108   Hex(unsigned long size);
109
110   /**Constructor, initiates the object with str
111    @param hstr: the hexadecimal number in a string-format */
112   Hex(char *hstr);
113
114   /**Copy constructor
115    @param copy a Bitstring object */
116   Hex(const Bitstring &copy);
117
118   /* * Deconstructor */ */
119   ~Hex(){};
120
121
122   /** Get the length of the bitstring
123     @return: the length of the bitstring divided by 4*/
124   unsigned long Length() const {return length/4;};
125
126   /** changes the length of the bitstring to \textit{len} *4.
127     If the new length is larger then before, the bitstring
128     is appended with 0, else the bitstring is truncated to
129     the new length.
130     @param len the new length of the Bitstring
131     @return the previous length.
132     */
133   unsigned long Resize(unsigned long len);
134
135   /**converts the Bitstring to a C-string.
136    @return the converted Bitstring*/
137   void BitstrToString(char* out) const;
138
139   /**converts a C-string to a bitstring.
140    @param hstr a C-string to be converted
141    @return the HexString*/
142   void StringToBitstr(char *hstr);
143
144 };
145
146 #endif