ardour
data_type.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006 Paul Davis
3  Author: David Robillard
4 
5  This program is free software; you can redistribute it and/or modify it
6  under the terms of the GNU General Public License as published by the Free
7  Software Foundation; either version 2 of the License, or (at your option)
8  any later version.
9 
10  This program is distributed in the hope that it will be useful, but WITHOUT
11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13  for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 
20 #ifndef __ardour_data_type_h__
21 #define __ardour_data_type_h__
22 
23 #include <string>
24 #include <stdint.h>
25 #include <glib.h>
26 
28 
29 namespace ARDOUR {
30 
38 {
39 public:
49  enum Symbol {
50  AUDIO = 0,
51  MIDI = 1,
52  NIL = 2,
53  };
54 
58  static const uint32_t num_types = 2;
59 
60  DataType(const Symbol& symbol)
61  : _symbol(symbol)
62  {}
63 
67  DataType(const std::string& str)
68  : _symbol(NIL) {
69  if (!g_ascii_strncasecmp(str.c_str(), "audio", str.length())) {
70  _symbol = AUDIO;
71  } else if (!g_ascii_strncasecmp(str.c_str(), "midi", str.length())) {
72  _symbol = MIDI;
73  }
74  }
75 
77  const char* to_string() const {
78  switch (_symbol) {
79  case AUDIO: return "audio";
80  case MIDI: return "midi";
81  default: return "unknown"; // reeeally shouldn't ever happen
82  }
83  }
84 
85  const char* to_i18n_string () const;
86 
87  inline operator uint32_t() const { return (uint32_t)_symbol; }
88 
92  class iterator {
93  public:
94 
95  iterator(uint32_t index) : _index(index) {}
96 
97  DataType operator*() { return DataType((Symbol)_index); }
98  iterator& operator++() { ++_index; return *this; } // yes, prefix only
99  bool operator==(const iterator& other) { return (_index == other._index); }
100  bool operator!=(const iterator& other) { return (_index != other._index); }
101 
102  private:
103  friend class DataType;
104 
105  uint32_t _index;
106  };
107 
108  static iterator begin() { return iterator(0); }
109  static iterator end() { return iterator(num_types); }
110 
111  bool operator==(const Symbol symbol) { return (_symbol == symbol); }
112  bool operator!=(const Symbol symbol) { return (_symbol != symbol); }
113 
114  bool operator==(const DataType other) { return (_symbol == other._symbol); }
115  bool operator!=(const DataType other) { return (_symbol != other._symbol); }
116 
117 private:
118  Symbol _symbol; // could be const if not for the string constructor
119 };
120 
121 
122 } // namespace ARDOUR
123 
124 #endif // __ardour_data_type_h__
125 
DataType(const std::string &str)
Definition: data_type.h:67
iterator(uint32_t index)
Definition: data_type.h:95
const char * to_string() const
Definition: data_type.h:77
bool operator==(const Symbol symbol)
Definition: data_type.h:111
DataType(const Symbol &symbol)
Definition: data_type.h:60
static iterator end()
Definition: data_type.h:109
Definition: amp.h:29
bool operator!=(const iterator &other)
Definition: data_type.h:100
#define LIBARDOUR_API
iterator & operator++()
Definition: data_type.h:98
bool operator!=(const DataType other)
Definition: data_type.h:115
bool operator!=(const Symbol symbol)
Definition: data_type.h:112
bool operator==(const iterator &other)
Definition: data_type.h:99
Definition: ardour.h:41
bool operator==(const DataType other)
Definition: data_type.h:114
static iterator begin()
Definition: data_type.h:108