Edinburgh Speech Tools  2.1-release
EST_svec_aux.cc
Go to the documentation of this file.
1 /*************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1994,1995,1996 */
6 /* All Rights Reserved. */
7 /* */
8 /* Permission is hereby granted, free of charge, to use and distribute */
9 /* this software and its documentation without restriction, including */
10 /* without limitation the rights to use, copy, modify, merge, publish, */
11 /* distribute, sublicense, and/or sell copies of this work, and to */
12 /* permit persons to whom this work is furnished to do so, subject to */
13 /* the following conditions: */
14 /* 1. The code must retain the above copyright notice, this list of */
15 /* conditions and the following disclaimer. */
16 /* 2. Any modifications must be clearly marked as such. */
17 /* 3. Original authors' names are not deleted. */
18 /* 4. The authors' names are not used to endorse or promote products */
19 /* derived from this software without specific prior written */
20 /* permission. */
21 /* */
22 /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25 /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30 /* THIS SOFTWARE. */
31 /* */
32 /*************************************************************************/
33 /* Author : Paul Taylor */
34 /* Date : May 1994 */
35 /*-----------------------------------------------------------------------*/
36 /* StrVector i/o utility functions */
37 /* */
38 /*=======================================================================*/
39 #include <cstdio>
40 #include <cctype>
41 #include <cstdlib>
42 #include <cstring>
43 #include <fstream>
44 #include <iostream>
45 #include "EST_types.h"
46 #include "EST_String.h"
47 #include "EST_Pathname.h"
48 #include "EST_string_aux.h"
49 #include "EST_cutils.h"
50 #include "EST_Token.h"
51 
52 using namespace std;
53 
55  const EST_String &filename,
56  const int vec_len)
57 {
58 
59  EST_TokenStream ts;
60  EST_String s;
61  EST_StrVector v;
62  int c;
63 
64  if(ts.open(filename) != 0){
65  cerr << "Can't open EST_TList<EST_StrVector> file " << filename << endl;
66  return misc_read_error;
67  }
68 
69  v.resize(vec_len);
70 // ts.set_SingleCharSymbols("");
71 // ts.set_PunctuationSymbols("");
72 
73  c=0;
74  while (!ts.eof())
75  {
76 
77  s = ts.get().string();
78  if(s != "")
79  {
80  if(c == vec_len)
81  {
82  cerr << "Too many points in line - expected " << vec_len << endl;
83  return wrong_format;
84  }
85  else
86  v[c++] = s;
87  }
88 
89  if(ts.eoln())
90  {
91  if(c != vec_len)
92  {
93  cerr << "Too few points in line - got "
94  << c << ", expected " << vec_len << endl;
95  return wrong_format;
96  }
97  else
98  {
99  w.append(v);
100  c=0;
101  }
102  }
103  }
104 
105  ts.close();
106  return format_ok;
107 
108 }
109 
EST_TokenStream & get(EST_Token &t)
get next token in stream
Definition: EST_Token.cc:499
EST_read_status load_TList_of_StrVector(EST_TList< EST_StrVector > &w, const EST_String &filename, const int vec_len)
Definition: EST_svec_aux.cc:54
void close(void)
Close stream.
Definition: EST_Token.cc:419
int open(const EST_String &filename)
open a EST_TokenStream for a file.
Definition: EST_Token.cc:213
int eof()
end of file
Definition: EST_Token.h:362
void resize(ssize_t n, int set=1)
Definition: EST_TVector.cc:196
#define wrong_format
#define misc_read_error
void append(const T &item)
add item onto end of list
Definition: EST_TList.h:196
EST_read_status
#define format_ok
int eoln()
end of line
Definition: EST_Token.cc:832
Utility EST_String Functions header file.