summaryrefslogtreecommitdiff
path: root/libs/ardour/ardour/data_type.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-06-29 06:58:07 +0000
committerDavid Robillard <d@drobilla.net>2007-06-29 06:58:07 +0000
commiteb296b2c957f574334fae2aefd8b863cf7631769 (patch)
tree57a546f8c61a81b7088b23b9fcd92a5b9d578e9f /libs/ardour/ardour/data_type.h
parent44867662a3d020e042714d1c5e948b8c3afea941 (diff)
Reduce overhead of multi-type-ness (last Summer's SoC):
Use uint32_t instead of size_t counts (halves size of ChanCount on 64-bit). Shift DataType values down to eliminate subtraction every index of a ChanCount or *Set. Allow using DataType directly as an array index (prettier/terser). Fix some mixed spaces/tabs in file comment headers. git-svn-id: svn://localhost/ardour2/trunk@2082 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/ardour/data_type.h')
-rw-r--r--libs/ardour/ardour/data_type.h45
1 files changed, 24 insertions, 21 deletions
diff --git a/libs/ardour/ardour/data_type.h b/libs/ardour/ardour/data_type.h
index 3818a8d74f..68d9554904 100644
--- a/libs/ardour/ardour/data_type.h
+++ b/libs/ardour/ardour/data_type.h
@@ -1,5 +1,6 @@
/*
Copyright (C) 2006 Paul Davis
+ Author: Dave Robillard
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
@@ -35,17 +36,25 @@ namespace ARDOUR {
class DataType
{
public:
- /// WARNING: make REALLY sure you don't mess up indexes if you change this
+ /** Numeric symbol for this DataType.
+ *
+ * Castable to int for use as an array index (e.g. by ChanCount).
+ * Note this means NIL is (ntypes-1) and guaranteed to change when
+ * types are added, so this number is NOT suitable for serialization,
+ * network, or binary anything.
+ *
+ * WARNING: The number of non-NIL entries here must match num_types.
+ */
enum Symbol {
- NIL = 0,
- AUDIO,
- MIDI
+ AUDIO = 0,
+ MIDI = 1,
+ NIL = 2,
};
/** Number of types (not including NIL).
* WARNING: make sure this matches Symbol!
*/
- static const size_t num_types = 2;
+ static const uint32_t num_types = 2;
DataType(const Symbol& symbol)
: _symbol(symbol)
@@ -54,17 +63,12 @@ public:
/** Construct from a string (Used for loading from XML and Ports)
* The string can be as in an XML file (eg "audio" or "midi"), or a
* Jack type string (from jack_port_type) */
- DataType(const std::string& str) {
- if (str == "audio")
- _symbol = AUDIO;
- else if (str == JACK_DEFAULT_AUDIO_TYPE)
+ DataType(const std::string& str)
+ : _symbol(NIL) {
+ if (str == "audio" || str == JACK_DEFAULT_AUDIO_TYPE)
_symbol = AUDIO;
- else if (str == "midi")
- _symbol = MIDI;
- else if (str == JACK_DEFAULT_MIDI_TYPE)
+ else if (str == "midi" || str == JACK_DEFAULT_MIDI_TYPE)
_symbol = MIDI;
- else
- _symbol = NIL;
}
/** Get the Jack type this DataType corresponds to */
@@ -85,8 +89,7 @@ public:
}
}
- //Symbol to_symbol() const { return _symbol; }
- inline size_t to_index() const { return (size_t)_symbol - 1; }
+ inline operator uint32_t() const { return (uint32_t)_symbol; }
/** DataType iterator, for writing generic loops that iterate over all
* available types.
@@ -94,7 +97,7 @@ public:
class iterator {
public:
- iterator(size_t index) : _index(index) {}
+ iterator(uint32_t index) : _index(index) {}
DataType operator*() { return DataType((Symbol)_index); }
iterator& operator++() { ++_index; return *this; } // yes, prefix only
@@ -104,11 +107,11 @@ public:
private:
friend class DataType;
- size_t _index;
+ uint32_t _index;
};
- static iterator begin() { return iterator(1); }
- static iterator end() { return iterator(num_types+1); }
+ static iterator begin() { return iterator(0); }
+ static iterator end() { return iterator(num_types); }
bool operator==(const Symbol symbol) { return (_symbol == symbol); }
bool operator!=(const Symbol symbol) { return (_symbol != symbol); }
@@ -117,7 +120,7 @@ public:
bool operator!=(const DataType other) { return (_symbol != other._symbol); }
private:
- Symbol _symbol;
+ Symbol _symbol; // could be const if not for the string constructor
};