GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
str-vec.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_str_vec_h)
24 #define octave_str_vec_h 1
25 
26 #include "octave-config.h"
27 
28 #include <iosfwd>
29 #include <list>
30 #include <string>
31 
32 #include "Array.h"
33 
34 class
35 OCTAVE_API
37 {
38 public:
39 
40  string_vector (void) : Array<std::string> () { }
41 
43  : Array<std::string> (dim_vector (n, 1)) { }
44 
45  string_vector (const char *s)
46  : Array<std::string> (dim_vector (1, 1), s) { }
47 
49  : Array<std::string> (dim_vector (1, 1), s) { }
50 
52 
53  //! Constructor for STL containers of std::string
54  /*!
55  Templated constructor for any template class with std::string as the
56  first parameter, and begin, end, and size methods, i.e., a class with
57  similar interface as the STL containers.
58  */
59  template<template <typename...> class String_Container, typename... Other>
60  string_vector (const String_Container<std::string, Other...>& lst);
61 
63  : Array<std::string> (s.as_column ()) { }
64 
65  string_vector (const char * const *s);
66 
67  string_vector (const char * const *s, octave_idx_type n);
68 
69  string_vector& operator = (const string_vector& s)
70  {
71  if (this != &s)
73 
74  return *this;
75  }
76 
77  ~string_vector (void) { }
78 
79  bool empty (void) const { return numel () == 0; }
80 
82  {
83  octave_idx_type n = numel ();
84  octave_idx_type longest = 0;
85 
86  for (octave_idx_type i = 0; i < n; i++)
87  {
88  octave_idx_type tmp = elem (i).length ();
89 
90  if (tmp > longest)
91  longest = tmp;
92  }
93 
94  return longest;
95  }
96 
97  void resize (octave_idx_type n, const std::string& rfv = "")
98  {
100  }
101 
103  { return Array<std::string>::elem (i); }
104 
105  std::string operator[] (octave_idx_type i) const
106  { return Array<std::string>::elem (i); }
107 
108  string_vector& sort (bool make_uniq = false);
109 
110  string_vector& uniq (void);
111 
112  string_vector& append (const std::string& s);
113 
114  string_vector& append (const string_vector& sv);
115 
116  std::string join (const std::string& sep = "") const;
117 
118  char **c_str_vec (void) const;
119 
120  std::list<std::string> std_list (void) const;
121 
122  static void delete_c_str_vec (const char * const*);
123 
124  std::ostream&
125  list_in_columns (std::ostream&, int width = 0,
126  const std::string& prefix = "") const;
127 };
128 
129 
130 template<template <typename...> class String_Container, typename... Other>
131 string_vector::string_vector (const String_Container<std::string, Other...>&
132  lst)
133  : Array<std::string> ()
134 {
135  resize (lst.size ());
136 
137  octave_idx_type i = 0;
138  for (const std::string& s : lst)
139  elem(i++) = s;
140 }
141 
142 #endif
string_vector(const std::string &s)
Definition: str-vec.h:48
string_vector(void)
Definition: str-vec.h:40
octave_idx_type max_length(void) const
Definition: str-vec.h:81
bool empty(void) const
Definition: str-vec.h:79
STL namespace.
T & elem(octave_idx_type n)
Definition: Array.h:482
s
Definition: file-io.cc:2682
void resize(octave_idx_type n, const std::string &rfv="")
Definition: str-vec.h:97
string_vector(const string_vector &s)
Definition: str-vec.h:51
static int elem
Definition: __contourc__.cc:50
void resize(const dim_vector &dv, const T &rfv)
Definition: Array.cc:1028
double tmp
Definition: data.cc:6300
bool append
Definition: load-save.cc:1582
string_vector(const Array< std::string > &s)
Definition: str-vec.h:62
string_vector(const char *s)
Definition: str-vec.h:45
T::size_type numel(const T &str)
Definition: oct-string.cc:61
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
string_vector(octave_idx_type n)
Definition: str-vec.h:42
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
Array< T > & operator=(const Array< T > &a)
Definition: Array.h:309
~string_vector(void)
Definition: str-vec.h:77