~ubuntu-branches/debian/sid/octave3.0/sid

« back to all changes in this revision

Viewing changes to liboctave/str-vec.h

  • Committer: Bazaar Package Importer
  • Author(s): Rafael Laboissiere
  • Date: 2007-12-23 16:04:15 UTC
  • Revision ID: james.westby@ubuntu.com-20071223160415-n4gk468dihy22e9v
Tags: upstream-3.0.0
ImportĀ upstreamĀ versionĀ 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
Copyright (C) 1996, 1997, 2000, 2002, 2003, 2005, 2006, 2007
 
4
              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 3 of the License, or (at your
 
11
option) any 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, see
 
20
<http://www.gnu.org/licenses/>.
 
21
 
 
22
*/
 
23
 
 
24
#if !defined (octave_str_vec_h)
 
25
#define octave_str_vec_h 1
 
26
 
 
27
#include <iostream>
 
28
#include <list>
 
29
#include <string>
 
30
 
 
31
#include "Array.h"
 
32
 
 
33
class
 
34
OCTAVE_API
 
35
string_vector : public Array<std::string>
 
36
{
 
37
public:
 
38
 
 
39
  string_vector (void) : Array<std::string> () { }
 
40
 
 
41
  explicit string_vector (octave_idx_type n) : Array<std::string> (n) { }
 
42
 
 
43
  string_vector (const char *s) : Array<std::string> (1, s) { }
 
44
 
 
45
  string_vector (const std::string& s) : Array<std::string> (1, s) { }
 
46
 
 
47
  string_vector (const string_vector& s) : Array<std::string> (s) { }
 
48
 
 
49
  string_vector (const std::list<std::string>& lst);
 
50
 
 
51
  string_vector (const char * const *s);
 
52
 
 
53
  string_vector (const char * const *s, octave_idx_type n);
 
54
 
 
55
  string_vector& operator = (const string_vector& s)
 
56
  {
 
57
    if (this != &s)
 
58
      Array<std::string>::operator = (s);
 
59
 
 
60
    return *this;
 
61
  }
 
62
 
 
63
  ~string_vector (void) { }
 
64
 
 
65
  bool empty (void) const { return length () == 0; }
 
66
 
 
67
  octave_idx_type max_length (void) const
 
68
  {
 
69
    octave_idx_type n = length ();
 
70
    octave_idx_type longest = 0;
 
71
 
 
72
    for (octave_idx_type i = 0; i < n; i++)
 
73
      {
 
74
        octave_idx_type tmp = elem(i).length ();
 
75
 
 
76
        if (tmp > longest)
 
77
          longest = tmp;
 
78
      }
 
79
 
 
80
    return longest;
 
81
  }
 
82
 
 
83
  std::string& operator[] (octave_idx_type i) { return Array<std::string>::elem (i); }
 
84
 
 
85
  std::string operator[] (octave_idx_type i) const { return Array<std::string>::elem (i); }
 
86
 
 
87
  static int compare (const void *a_arg, const void *b_arg);
 
88
 
 
89
  string_vector& qsort (bool make_uniq = false)
 
90
  {
 
91
    Array<std::string>::qsort (compare);
 
92
 
 
93
    if (make_uniq)
 
94
      uniq ();
 
95
 
 
96
    return *this;
 
97
  }
 
98
 
 
99
  string_vector& uniq (void);
 
100
 
 
101
  string_vector& append (const std::string& s);
 
102
 
 
103
  string_vector& append (const string_vector& sv);
 
104
 
 
105
  char **c_str_vec (void) const;
 
106
 
 
107
  static void delete_c_str_vec (const char * const*);
 
108
 
 
109
  std::ostream& list_in_columns (std::ostream&, int width = 0) const;
 
110
};
 
111
 
 
112
#endif
 
113
 
 
114
/*
 
115
;;; Local Variables: ***
 
116
;;; mode: C++ ***
 
117
;;; End: ***
 
118
*/