Jack2 1.9.6

JackPortType.cpp

00001 /*
00002 Copyright (C) 2007 Dmitry Baikov
00003 
00004 This program is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU Lesser General Public License as published by
00006 the Free Software Foundation; either version 2.1 of the License, or
00007 (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU Lesser General Public License for more details.
00013 
00014 You should have received a copy of the GNU Lesser General Public License
00015 along with this program; if not, write to the Free Software 
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 
00018 */
00019 
00020 #include "JackPortType.h"
00021 #include <string.h>
00022 #include <assert.h>
00023 
00024 namespace Jack
00025 {
00026 
00027 static const JackPortType* port_types[] =
00028 {
00029     &gAudioPortType,
00030     &gMidiPortType,
00031 };
00032 
00033 jack_port_type_id_t PORT_TYPES_MAX = sizeof(port_types) / sizeof(port_types[0]);
00034 
00035 jack_port_type_id_t GetPortTypeId(const char* port_type)
00036 {
00037     for (jack_port_type_id_t i = 0; i < PORT_TYPES_MAX; ++i) {
00038         const JackPortType* type = port_types[i];
00039         assert(type != 0);
00040         if (strcmp(port_type, type->name) == 0)
00041             return i;
00042     }
00043     return PORT_TYPES_MAX;
00044 }
00045 
00046 const JackPortType* GetPortType(jack_port_type_id_t type_id)
00047 {
00048     assert(type_id >= 0 && type_id <= PORT_TYPES_MAX);
00049     const JackPortType* type = port_types[type_id];
00050     assert(type != 0);
00051     return type;
00052 }
00053 
00054 } // namespace Jack