1757
|
1 /* |
|
2 |
|
3 Copyright (C) 1996 John W. Eaton |
|
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 |
|
56 string_vector& operator = (const string_vector& s) |
|
57 { |
1879
|
58 if (this != &s) |
|
59 Array<string>::operator = (s); |
|
60 |
1757
|
61 return *this; |
|
62 } |
|
63 |
|
64 ~string_vector (void) { } |
|
65 |
1811
|
66 int empty (void) const { return length () == 0; } |
1757
|
67 |
|
68 int max_length (void) const |
|
69 { |
|
70 int n = length (); |
|
71 int longest = 0; |
|
72 |
|
73 for (int i = 0; i < n; i++) |
|
74 { |
|
75 int tmp = elem(i).length (); |
|
76 |
|
77 if (tmp > longest) |
|
78 longest = tmp; |
|
79 } |
|
80 |
|
81 return longest; |
|
82 } |
|
83 |
|
84 string& operator[] (int i) { return Array<string>::elem (i); } |
|
85 |
|
86 string operator[] (int i) const { return Array<string>::elem (i); } |
|
87 |
1781
|
88 string_vector& qsort (void) |
|
89 { |
|
90 Array<string>::qsort (str_vec_compare); |
|
91 return *this; |
|
92 } |
1811
|
93 |
|
94 ostream& list_in_columns (ostream&) const; |
1757
|
95 }; |
|
96 |
|
97 #endif |
|
98 |
|
99 /* |
|
100 ;;; Local Variables: *** |
|
101 ;;; mode: C++ *** |
|
102 ;;; End: *** |
|
103 */ |