svcore  1.9
CSVFormat.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006 Chris Cannam.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef _CSV_FORMAT_H_
17 #define _CSV_FORMAT_H_
18 
19 #include <QString>
20 #include <QStringList>
21 
22 class CSVFormat
23 {
24 public:
25  enum ModelType {
31  };
32 
33  enum TimingType {
36  };
37 
38  enum TimeUnits {
42  };
43 
52  };
53 
59  };
60  typedef unsigned int ColumnQualities;
61 
62  CSVFormat() : // arbitrary defaults
66  m_separator(","),
67  m_sampleRate(44100),
68  m_windowSize(1024),
69  m_columnCount(0),
70  m_variableColumnCount(false),
71  m_allowQuoting(true),
73  { }
74 
75  CSVFormat(QString path); // guess format
76 
84  void guessFormatFor(QString path);
85 
86  ModelType getModelType() const { return m_modelType; }
88  TimeUnits getTimeUnits() const { return m_timeUnits; }
89  int getSampleRate() const { return m_sampleRate; }
90  int getWindowSize() const { return m_windowSize; }
91  int getColumnCount() const { return m_columnCount; }
92  bool getAllowQuoting() const { return m_allowQuoting; }
93  QChar getSeparator() const {
94  if (m_separator == "") return ' ';
95  else return m_separator[0];
96  }
97 
101  void setSeparator(QChar s) { m_separator = s; }
102  void setSampleRate(int r) { m_sampleRate = r; }
103  void setWindowSize(int s) { m_windowSize = s; }
104  void setColumnCount(int c) { m_columnCount = c; }
105  void setAllowQuoting(bool q) { m_allowQuoting = q; }
106 
107  QList<ColumnPurpose> getColumnPurposes() const { return m_columnPurposes; }
108  void setColumnPurposes(QList<ColumnPurpose> cl) { m_columnPurposes = cl; }
109 
111  ColumnPurpose getColumnPurpose(int i) const;
112  void setColumnPurpose(int i, ColumnPurpose p);
113 
114  // read-only; only valid if format has been guessed:
115  QList<ColumnQualities> getColumnQualities() const { return m_columnQualities; }
116 
117  // read-only; only valid if format has been guessed:
118  QList<QStringList> getExample() const { return m_example; }
119  int getMaxExampleCols() const { return m_maxExampleCols; }
120 
121 protected:
125  QString m_separator;
128 
131 
132  QList<ColumnQualities> m_columnQualities;
133  QList<ColumnPurpose> m_columnPurposes;
134 
135  QList<float> m_prevValues;
136 
138 
139  QList<QStringList> m_example;
141 
142  void guessSeparator(QString line);
143  void guessQualities(QString line, int lineno);
144  void guessPurposes();
145 
146  void guessFormatFor_Old(QString path);
147 
148 };
149 
150 #endif
CSVFormat()
Definition: CSVFormat.h:62
int m_maxExampleCols
Definition: CSVFormat.h:140
void guessSeparator(QString line)
Definition: CSVFormat.cpp:86
bool getAllowQuoting() const
Definition: CSVFormat.h:92
int m_columnCount
Definition: CSVFormat.h:129
QList< QStringList > getExample() const
Definition: CSVFormat.h:118
void guessFormatFor(QString path)
Guess the format of the given CSV file, setting the fields in this object accordingly.
Definition: CSVFormat.cpp:38
QList< ColumnPurpose > getColumnPurposes() const
Definition: CSVFormat.h:107
int m_windowSize
Definition: CSVFormat.h:127
QList< float > m_prevValues
Definition: CSVFormat.h:135
ColumnPurpose getColumnPurpose(int i)
Definition: CSVFormat.cpp:303
void setSeparator(QChar s)
Definition: CSVFormat.h:101
ModelType getModelType() const
Definition: CSVFormat.h:86
QList< ColumnPurpose > m_columnPurposes
Definition: CSVFormat.h:133
void guessQualities(QString line, int lineno)
Definition: CSVFormat.cpp:99
void setWindowSize(int s)
Definition: CSVFormat.h:103
int getMaxExampleCols() const
Definition: CSVFormat.h:119
void setAllowQuoting(bool q)
Definition: CSVFormat.h:105
void guessPurposes()
Definition: CSVFormat.cpp:187
int getSampleRate() const
Definition: CSVFormat.h:89
void setSampleRate(int r)
Definition: CSVFormat.h:102
void guessFormatFor_Old(QString path)
ModelType m_modelType
Definition: CSVFormat.h:122
void setModelType(ModelType t)
Definition: CSVFormat.h:98
void setTimingType(TimingType t)
Definition: CSVFormat.h:99
TimingType getTimingType() const
Definition: CSVFormat.h:87
QChar getSeparator() const
Definition: CSVFormat.h:93
TimingType m_timingType
Definition: CSVFormat.h:123
QList< ColumnQualities > getColumnQualities() const
Definition: CSVFormat.h:115
QList< QStringList > m_example
Definition: CSVFormat.h:139
void setColumnCount(int c)
Definition: CSVFormat.h:104
void setColumnPurpose(int i, ColumnPurpose p)
Definition: CSVFormat.cpp:321
void setColumnPurposes(QList< ColumnPurpose > cl)
Definition: CSVFormat.h:108
TimeUnits getTimeUnits() const
Definition: CSVFormat.h:88
bool m_allowQuoting
Definition: CSVFormat.h:137
QString m_separator
Definition: CSVFormat.h:125
unsigned int ColumnQualities
Definition: CSVFormat.h:60
void setTimeUnits(TimeUnits t)
Definition: CSVFormat.h:100
int getWindowSize() const
Definition: CSVFormat.h:90
bool m_variableColumnCount
Definition: CSVFormat.h:130
TimeUnits m_timeUnits
Definition: CSVFormat.h:124
int getColumnCount() const
Definition: CSVFormat.h:91
int m_sampleRate
Definition: CSVFormat.h:126
QList< ColumnQualities > m_columnQualities
Definition: CSVFormat.h:132