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