OpenIndiana and Solaris port
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Basic / OString.hh
1 /*
2  * $XConsortium: OString.hh /main/4 1996/07/06 13:09:08 rws $
3  *
4  * Copyright (c) 1992 HaL Computer Systems, Inc.  All rights reserved.
5  * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
6  * States.  Use of a copyright notice is precautionary only and does not
7  * imply publication or disclosure.
8  * 
9  * This software contains confidential information and trade secrets of HaL
10  * Computer Systems, Inc.  Use, disclosure, or reproduction is prohibited
11  * without the prior express written permission of HaL Computer Systems, Inc.
12  * 
13  *                         RESTRICTED RIGHTS LEGEND
14  * Use, duplication, or disclosure by the Government is subject to
15  * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
16  * Technical Data and Computer Software clause at DFARS 252.227-7013.
17  *                        HaL Computer Systems, Inc.
18  *                  1315 Dell Avenue, Campbell, CA  95008
19  * 
20  */
21
22 #include <string.h>
23
24 class OString : public Hashable
25 {
26 public:
27   enum copy_t { NO_COPY, COPY };
28   OString (const char *s, copy_t copy = COPY)
29     : f_delete_string (FALSE)
30     { string (s, copy); }
31   ~OString()
32     { if (f_delete_string) delete [] (char *) f_string; }
33
34   void string (const char *s, copy_t copy = COPY);
35   const char *string() const
36     { return (f_string); }
37   operator const char * () const
38     { return (f_string); }
39
40   inline u_int hash_code (u_int lower_bound, u_int upper_bound) const;
41   bool equals (const Hashable &s) const
42     { return (strcmp ((OString &) s, f_string) == 0); }
43
44 private:
45   const char *f_string;
46   bool     f_delete_string:1;
47 };
48
49 inline u_int
50 OString::hash_code (u_int lower_bound, u_int upper_bound) const
51 {
52   return (lower_bound + string_hash (f_string) %
53           (upper_bound - lower_bound + 1));
54 }