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 |
|
27 #include <string> |
|
28 |
|
29 #include "Array.h" |
|
30 |
|
31 static int |
|
32 str_vec_compare (const string *a, const string *b) |
|
33 { |
|
34 return a->compare (*b); |
|
35 } |
|
36 |
|
37 class |
|
38 string_vector : public Array<string> |
|
39 { |
|
40 public: |
|
41 string_vector (void) : Array<string> () { } |
|
42 string_vector (int n) : Array<string> (n) { } |
|
43 string_vector (const char *s) : Array<string> (1, s) { } |
|
44 string_vector (const string& s) : Array<string> (1, s) { } |
|
45 string_vector (const string_vector& s) : Array<string> (s) { } |
|
46 |
|
47 string_vector& operator = (const string_vector& s) |
|
48 { |
|
49 Array<string>::operator = (s); |
|
50 return *this; |
|
51 } |
|
52 |
|
53 ~string_vector (void) { } |
|
54 |
|
55 int empty (void) { return length () == 0; } |
|
56 |
|
57 int max_length (void) const |
|
58 { |
|
59 int n = length (); |
|
60 int longest = 0; |
|
61 |
|
62 for (int i = 0; i < n; i++) |
|
63 { |
|
64 int tmp = elem(i).length (); |
|
65 |
|
66 if (tmp > longest) |
|
67 longest = tmp; |
|
68 } |
|
69 |
|
70 return longest; |
|
71 } |
|
72 |
|
73 string& operator[] (int i) { return Array<string>::elem (i); } |
|
74 |
|
75 string operator[] (int i) const { return Array<string>::elem (i); } |
|
76 |
1781
|
77 string_vector& qsort (void) |
|
78 { |
|
79 Array<string>::qsort (str_vec_compare); |
|
80 return *this; |
|
81 } |
1757
|
82 }; |
|
83 |
|
84 #endif |
|
85 |
|
86 /* |
|
87 ;;; Local Variables: *** |
|
88 ;;; mode: C++ *** |
|
89 ;;; page-delimiter: "^/\\*" *** |
|
90 ;;; End: *** |
|
91 */ |