Ardour  9.0-pre0-582-g084a23a80d
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 #pragma once
22 
23 #include <string>
24 #include <stdint.h>
25 #include <glib.h>
26 
28 
29 namespace ARDOUR {
30 
38 {
39 public:
52  enum Symbol {
53  AUDIO = 0,
54  MIDI = 1,
55  NIL = 2,
56  };
57 
61  static const uint32_t num_types = 2;
62 
63  DataType(const Symbol& symbol)
64  : _symbol(symbol)
65  {}
66 
67  static DataType front() { return DataType((Symbol) 0); }
68 
72  DataType(const std::string& str)
73  : _symbol(NIL) {
74  if (!g_ascii_strncasecmp(str.c_str(), "audio", str.length())) {
75  _symbol = AUDIO;
76  } else if (!g_ascii_strncasecmp(str.c_str(), "midi", str.length())) {
77  _symbol = MIDI;
78  }
79  }
80 
82  const char* to_string() const {
83  switch (_symbol) {
84  case AUDIO: return "audio";
85  case MIDI: return "midi";
86  default: return "unknown"; // reeeally shouldn't ever happen
87  }
88  }
89 
90  const char* to_i18n_string () const;
91 
92  inline operator uint32_t() const { return (uint32_t)_symbol; }
93 
97  class iterator {
98  public:
99 
100  iterator(uint32_t index) : _index(index) {}
101 
102  DataType operator*() { return DataType((Symbol)_index); }
103  iterator& operator++() { ++_index; return *this; } // yes, prefix only
104  bool operator==(const iterator& other) { return (_index == other._index); }
105  bool operator!=(const iterator& other) { return (_index != other._index); }
106 
107  private:
108  friend class DataType;
109 
110  uint32_t _index;
111  };
112 
113  static iterator begin() { return iterator(0); }
114  static iterator end() { return iterator(num_types); }
115 
116  bool operator==(const Symbol symbol) { return (_symbol == symbol); }
117  bool operator!=(const Symbol symbol) { return (_symbol != symbol); }
118 
119  bool operator==(const DataType other) { return (_symbol == other._symbol); }
120  bool operator!=(const DataType other) { return (_symbol != other._symbol); }
121 
122 private:
123  Symbol _symbol; // could be const if not for the string constructor
124 };
125 
126 
127 } // namespace ARDOUR
128 
129 
bool operator==(const iterator &other)
Definition: data_type.h:104
iterator(uint32_t index)
Definition: data_type.h:100
bool operator!=(const iterator &other)
Definition: data_type.h:105
static iterator end()
Definition: data_type.h:114
bool operator!=(const Symbol symbol)
Definition: data_type.h:117
const char * to_i18n_string() const
bool operator!=(const DataType other)
Definition: data_type.h:120
bool operator==(const Symbol symbol)
Definition: data_type.h:116
bool operator==(const DataType other)
Definition: data_type.h:119
static iterator begin()
Definition: data_type.h:113
const char * to_string() const
Definition: data_type.h:82
DataType(const Symbol &symbol)
Definition: data_type.h:63
DataType(const std::string &str)
Definition: data_type.h:72
static DataType front()
Definition: data_type.h:67
#define LIBARDOUR_API