Ardour  8.12
data_type.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2011 David Robillard <d@drobilla.net>
3  * Copyright (C) 2007-2011 Carl Hetherington <carl@carlh.net>
4  * Copyright (C) 2007-2015 Paul Davis <paul@linuxaudiosystems.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef __ardour_data_type_h__
22 #define __ardour_data_type_h__
23 
24 #include <string>
25 #include <stdint.h>
26 #include <glib.h>
27 
29 
30 namespace ARDOUR {
31 
39 {
40 public:
53  enum Symbol {
54  AUDIO = 0,
55  MIDI = 1,
56  NIL = 2,
57  };
58 
62  static const uint32_t num_types = 2;
63 
64  DataType(const Symbol& symbol)
65  : _symbol(symbol)
66  {}
67 
68  static DataType front() { return DataType((Symbol) 0); }
69 
73  DataType(const std::string& str)
74  : _symbol(NIL) {
75  if (!g_ascii_strncasecmp(str.c_str(), "audio", str.length())) {
76  _symbol = AUDIO;
77  } else if (!g_ascii_strncasecmp(str.c_str(), "midi", str.length())) {
78  _symbol = MIDI;
79  }
80  }
81 
83  const char* to_string() const {
84  switch (_symbol) {
85  case AUDIO: return "audio";
86  case MIDI: return "midi";
87  default: return "unknown"; // reeeally shouldn't ever happen
88  }
89  }
90 
91  const char* to_i18n_string () const;
92 
93  inline operator uint32_t() const { return (uint32_t)_symbol; }
94 
98  class iterator {
99  public:
100 
101  iterator(uint32_t index) : _index(index) {}
102 
103  DataType operator*() { return DataType((Symbol)_index); }
104  iterator& operator++() { ++_index; return *this; } // yes, prefix only
105  bool operator==(const iterator& other) { return (_index == other._index); }
106  bool operator!=(const iterator& other) { return (_index != other._index); }
107 
108  private:
109  friend class DataType;
110 
111  uint32_t _index;
112  };
113 
114  static iterator begin() { return iterator(0); }
115  static iterator end() { return iterator(num_types); }
116 
117  bool operator==(const Symbol symbol) { return (_symbol == symbol); }
118  bool operator!=(const Symbol symbol) { return (_symbol != symbol); }
119 
120  bool operator==(const DataType other) { return (_symbol == other._symbol); }
121  bool operator!=(const DataType other) { return (_symbol != other._symbol); }
122 
123 private:
124  Symbol _symbol; // could be const if not for the string constructor
125 };
126 
127 
128 } // namespace ARDOUR
129 
130 #endif // __ardour_data_type_h__
131 
bool operator==(const iterator &other)
Definition: data_type.h:105
iterator(uint32_t index)
Definition: data_type.h:101
bool operator!=(const iterator &other)
Definition: data_type.h:106
static iterator end()
Definition: data_type.h:115
bool operator!=(const Symbol symbol)
Definition: data_type.h:118
const char * to_i18n_string() const
bool operator!=(const DataType other)
Definition: data_type.h:121
bool operator==(const Symbol symbol)
Definition: data_type.h:117
bool operator==(const DataType other)
Definition: data_type.h:120
static iterator begin()
Definition: data_type.h:114
const char * to_string() const
Definition: data_type.h:83
DataType(const Symbol &symbol)
Definition: data_type.h:64
DataType(const std::string &str)
Definition: data_type.h:73
static DataType front()
Definition: data_type.h:68
#define LIBARDOUR_API