1757
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1757
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_str_vec_h) |
|
24 #define octave_str_vec_h 1 |
|
25 |
1811
|
26 class ostream; |
|
27 |
1757
|
28 #include <string> |
|
29 |
|
30 #include "Array.h" |
|
31 |
|
32 static int |
2431
|
33 str_vec_compare (const void *a_arg, const void *b_arg) |
1757
|
34 { |
2431
|
35 const string *a = (const string *) a_arg; |
|
36 const string *b = (const string *) b_arg; |
|
37 |
1757
|
38 return a->compare (*b); |
|
39 } |
|
40 |
|
41 class |
|
42 string_vector : public Array<string> |
|
43 { |
|
44 public: |
1879
|
45 |
1757
|
46 string_vector (void) : Array<string> () { } |
1879
|
47 |
1757
|
48 string_vector (int n) : Array<string> (n) { } |
1879
|
49 |
1757
|
50 string_vector (const char *s) : Array<string> (1, s) { } |
1879
|
51 |
1757
|
52 string_vector (const string& s) : Array<string> (1, s) { } |
1879
|
53 |
1757
|
54 string_vector (const string_vector& s) : Array<string> (s) { } |
|
55 |
2493
|
56 string_vector (const char * const *s); |
|
57 |
|
58 string_vector (const char * const *s, int n); |
|
59 |
1757
|
60 string_vector& operator = (const string_vector& s) |
2941
|
61 { |
|
62 if (this != &s) |
|
63 Array<string>::operator = (s); |
1879
|
64 |
2941
|
65 return *this; |
|
66 } |
1757
|
67 |
|
68 ~string_vector (void) { } |
|
69 |
1811
|
70 int empty (void) const { return length () == 0; } |
1757
|
71 |
|
72 int max_length (void) const |
2941
|
73 { |
|
74 int n = length (); |
|
75 int longest = 0; |
1757
|
76 |
2941
|
77 for (int i = 0; i < n; i++) |
|
78 { |
|
79 int tmp = elem(i).length (); |
1757
|
80 |
2941
|
81 if (tmp > longest) |
|
82 longest = tmp; |
|
83 } |
1757
|
84 |
2941
|
85 return longest; |
|
86 } |
1757
|
87 |
|
88 string& operator[] (int i) { return Array<string>::elem (i); } |
|
89 |
|
90 string operator[] (int i) const { return Array<string>::elem (i); } |
|
91 |
2941
|
92 string_vector& qsort (bool make_unique = false) |
|
93 { |
|
94 Array<string>::qsort (str_vec_compare); |
|
95 |
|
96 if (make_unique) |
|
97 uniq (); |
|
98 |
|
99 return *this; |
|
100 } |
|
101 |
|
102 string_vector& uniq (void); |
1811
|
103 |
2937
|
104 char **c_str_vec (void) const; |
|
105 |
|
106 static void delete_c_str_vec (const char * const*); |
|
107 |
1811
|
108 ostream& list_in_columns (ostream&) const; |
1757
|
109 }; |
|
110 |
|
111 #endif |
|
112 |
|
113 /* |
|
114 ;;; Local Variables: *** |
|
115 ;;; mode: C++ *** |
|
116 ;;; End: *** |
|
117 */ |