Update to latest LV2 atom extension.
[ardour.git] / libs / ardour / ardour / data_type.h
index cbb88afccf89c417b7dc8880ec53ff927ea6d5fa..6a016ae75a0fe3ccdfd1401d4e3d989f08bb9f07 100644 (file)
@@ -1,16 +1,17 @@
 /*
-    Copyright (C) 2006 Paul Davis 
-    
+    Copyright (C) 2006 Paul Davis
+    Author: David 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
     Software Foundation; either version 2 of the License, or (at your option)
     any later version.
-    
+
     This program is distributed in the hope that it will be useful, but WITHOUT
     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     for more details.
-    
+
     You should have received a copy of the GNU General Public License along
     with this program; if not, write to the Free Software Foundation, Inc.,
     675 Mass Ave, Cambridge, MA 02139, USA.
@@ -20,7 +21,6 @@
 #define __ardour_data_type_h__
 
 #include <string>
-#include <ardour/data_type.h>
 #include <jack/jack.h>
 
 namespace ARDOUR {
@@ -35,26 +35,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;
-
-
-       /** Helper for collections that store typed things by index (BufferSet, PortList).
-        * Guaranteed to be a valid index from 0 to (the number of available types - 1),
-        * because NIL is not included.  No, this isn't pretty - purely for speed.
-        * See DataType::to_index().
-        */
-       inline static size_t symbol_index(const Symbol symbol)
-               { return (size_t)symbol - 1; }
+       static const uint32_t num_types = 2;
 
        DataType(const Symbol& symbol)
        : _symbol(symbol)
@@ -63,17 +62,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")
+               else if (str == "midi" || str == JACK_DEFAULT_MIDI_TYPE)
                        _symbol = MIDI;
-               else if (str == JACK_DEFAULT_MIDI_TYPE)
-                       _symbol = MIDI;
-               else
-                       _symbol = NIL;
        }
 
        /** Get the Jack type this DataType corresponds to */
@@ -84,7 +78,7 @@ public:
                        default:    return "";
                }
        }
-       
+
        /** Inverse of the from-string constructor */
        const char* to_string() const {
                switch (_symbol) {
@@ -94,8 +88,9 @@ public:
                }
        }
 
-       Symbol        to_symbol() const { return _symbol; }
-       inline size_t to_index() const  { return symbol_index(_symbol); }
+       const char* to_i18n_string () const;
+
+       inline operator uint32_t() const { return (uint32_t)_symbol; }
 
        /** DataType iterator, for writing generic loops that iterate over all
         * available types.
@@ -103,7 +98,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
@@ -113,20 +108,20 @@ 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); }
-       
+
        bool operator==(const DataType other) { return (_symbol == other._symbol); }
        bool operator!=(const DataType other) { return (_symbol != other._symbol); }
 
 private:
-       Symbol _symbol;
+       Symbol _symbol; // could be const if not for the string constructor
 };