allow to obtain api names regardless of being compiled or not
authorJP Cimalando <jpcima@users.noreply.github.com>
Fri, 10 Aug 2018 13:24:46 +0000 (15:24 +0200)
committerJP Cimalando <jpcima@users.noreply.github.com>
Sat, 11 Aug 2018 12:55:44 +0000 (14:55 +0200)
RtAudio.cpp
RtAudio.h
rtaudio_c.cpp
rtaudio_c.h
tests/apinames.cpp

index 4e75d683c74aa843320c00eba96efd39a17c60c3..1e480d4ef7883a702036b1cbda407425983e35f9 100644 (file)
@@ -166,22 +166,16 @@ void RtAudio :: getCompiledApi( std::vector<RtAudio::Api> &apis )
                                    rtaudio_compiled_apis + rtaudio_num_compiled_apis);
 }
 
-const std::string RtAudio :: getCompiledApiName( RtAudio::Api api )
+std::string RtAudio :: getApiName( RtAudio::Api api )
 {
-  if (api < 0 || api > RtAudio::NUM_APIS
-      || (std::find(rtaudio_compiled_apis,
-                    rtaudio_compiled_apis+rtaudio_num_compiled_apis,
-                    api) == rtaudio_compiled_apis+rtaudio_num_compiled_apis))
+  if (api < 0 || api >= RtAudio::NUM_APIS)
     return "";
   return rtaudio_api_names[api][0];
 }
 
-const std::string RtAudio :: getCompiledApiDisplayName( RtAudio::Api api )
+std::string RtAudio :: getApiDisplayName( RtAudio::Api api )
 {
-  if (api < 0 || api > RtAudio::NUM_APIS
-      || (std::find(rtaudio_compiled_apis,
-                    rtaudio_compiled_apis+rtaudio_num_compiled_apis,
-                    api) == rtaudio_compiled_apis+rtaudio_num_compiled_apis))
+  if (api < 0 || api >= RtAudio::NUM_APIS)
     return "Unknown";
   return rtaudio_api_names[api][1];
 }
index 9976541c2e8aeff04f073accf2eee12ebf7d6abd..7eb7ac8da628bfb80ac681a4895795071f670f90 100644 (file)
--- a/RtAudio.h
+++ b/RtAudio.h
@@ -406,18 +406,16 @@ class RTAUDIO_DLL_PUBLIC RtAudio
   /*!
     This obtains a short lower-case name used for identification purposes.
     This value is guaranteed to remain identical across library versions.
-    If the API is unknown or not compiled, this function will return
-    the empty string.
+    If the API is unknown, this function will return the empty string.
   */
-  static const std::string getCompiledApiName( RtAudio::Api api );
+  static std::string getApiName( RtAudio::Api api );
 
   //! Return the display name of a specified compiled audio API.
   /*!
     This obtains a long name used for display purposes.
-    If the API is unknown or not compiled, this function will return
-    the empty string.
+    If the API is unknown, this function will return the empty string.
   */
-  static const std::string getCompiledApiDisplayName( RtAudio::Api api );
+  static std::string getApiDisplayName( RtAudio::Api api );
 
   //! Return the compiled audio API having the given name.
   /*!
index 59d6cd12b78f816f854f3aa30575c6fb6a8f1111..da3ab24ebc255896d27b3fef231f3c7de4e8f570 100644 (file)
@@ -22,13 +22,13 @@ extern "C" const unsigned int rtaudio_num_compiled_apis;
 const rtaudio_api_t *rtaudio_compiled_api() { return rtaudio_compiled_apis; }
 
 extern "C" const char* rtaudio_api_names[][2];
-const char *rtaudio_compiled_api_name(rtaudio_api_t api) {
+const char *rtaudio_api_name(rtaudio_api_t api) {
     if (api < 0 || api >= RTAUDIO_API_NUM)
         return NULL;
     return rtaudio_api_names[api][0];
 }
 
-const char *rtaudio_compiled_api_display_name(rtaudio_api_t api)
+const char *rtaudio_api_display_name(rtaudio_api_t api)
 {
     if (api < 0 || api >= RTAUDIO_API_NUM)
         return "Unknown";
index e4cdf82a55947d782d7e42c3946f6692d7837e13..a366117b0aa8b9a93da62ec0f29cc946c82d8fb6 100644 (file)
@@ -107,8 +107,8 @@ typedef struct rtaudio *rtaudio_t;
 
 RTAUDIOAPI const char *rtaudio_version(void);
 RTAUDIOAPI const rtaudio_api_t *rtaudio_compiled_api(void);
-RTAUDIOAPI const char *rtaudio_compiled_api_name(rtaudio_api_t api);
-RTAUDIOAPI const char *rtaudio_compiled_api_display_name(rtaudio_api_t api);
+RTAUDIOAPI const char *rtaudio_api_name(rtaudio_api_t api);
+RTAUDIOAPI const char *rtaudio_api_display_name(rtaudio_api_t api);
 RTAUDIOAPI rtaudio_api_t rtaudio_compiled_api_by_name(const char *name);
 
 RTAUDIOAPI const char *rtaudio_error(rtaudio_t audio);
index 9dc634c408405e629433c92834b5bf3203a39ae1..c270764034cb3e8cd6e52d500ded8d3f7f7fcb5f 100644 (file)
@@ -21,14 +21,14 @@ int test_cpp() {
     // ensure the known APIs return valid names
     std::cout << "API names by identifier (C++):\n";
     for ( size_t i = 0; i < apis.size() ; ++i ) {
-        const std::string name = RtAudio::getCompiledApiName(apis[i]);
+        const std::string name = RtAudio::getApiName(apis[i]);
         if (name.empty()) {
-            std::cerr << "Invalid name for API " << (int)apis[i] << "\n";
+            std::cout << "Invalid name for API " << (int)apis[i] << "\n";
             exit(1);
         }
-        const std::string displayName = RtAudio::getCompiledApiDisplayName(apis[i]);
+        const std::string displayName = RtAudio::getApiDisplayName(apis[i]);
         if (displayName.empty()) {
-            std::cerr << "Invalid display name for API " << (int)apis[i] << "\n";
+            std::cout << "Invalid display name for API " << (int)apis[i] << "\n";
             exit(1);
         }
         std::cout << "* " << (int)apis[i] << " '" << name << "': '" << displayName << "'\n";
@@ -36,14 +36,14 @@ int test_cpp() {
 
     // ensure unknown APIs return the empty string
     {
-        const std::string name = RtAudio::getCompiledApiName((RtAudio::Api)-1);
+        const std::string name = RtAudio::getApiName((RtAudio::Api)-1);
         if (!name.empty()) {
-            std::cerr << "Bad string for invalid API '" << name << "'\n";
+            std::cout << "Bad string for invalid API '" << name << "'\n";
             exit(1);
         }
-        const std::string displayName = RtAudio::getCompiledApiDisplayName((RtAudio::Api)-1);
+        const std::string displayName = RtAudio::getApiDisplayName((RtAudio::Api)-1);
         if (displayName!="Unknown") {
-            std::cerr << "Bad display string for invalid API '" << displayName << "'\n";
+            std::cout << "Bad display string for invalid API '" << displayName << "'\n";
             exit(1);
         }
     }
@@ -51,9 +51,9 @@ int test_cpp() {
     // try getting API identifier by name
     std::cout << "API identifiers by name (C++):\n";
     for ( size_t i = 0; i < apis.size() ; ++i ) {
-        std::string name = RtAudio::getCompiledApiName(apis[i]);
+        std::string name = RtAudio::getApiName(apis[i]);
         if ( RtAudio::getCompiledApiByName(name) != apis[i] ) {
-            std::cerr << "Bad identifier for API '" << name << "'\n";
+            std::cout << "Bad identifier for API '" << name << "'\n";
             exit( 1 );
         }
         std::cout << "* '" << name << "': " << (int)apis[i] << "\n";
@@ -62,7 +62,7 @@ int test_cpp() {
             name[j] = (j & 1) ? toupper(name[j]) : tolower(name[j]);
         RtAudio::Api api = RtAudio::getCompiledApiByName(name);
         if ( api != RtAudio::UNSPECIFIED ) {
-            std::cerr << "Identifier " << (int)api << " for invalid API '" << name << "'\n";
+            std::cout << "Identifier " << (int)api << " for invalid API '" << name << "'\n";
             exit( 1 );
         }
     }
@@ -72,7 +72,7 @@ int test_cpp() {
         RtAudio::Api api;
         api = RtAudio::getCompiledApiByName("");
         if ( api != RtAudio::UNSPECIFIED ) {
-            std::cerr << "Bad identifier for unknown API name\n";
+            std::cout << "Bad identifier for unknown API name\n";
             exit( 1 );
         }
     }
@@ -88,14 +88,14 @@ int test_c() {
     // ensure the known APIs return valid names
     std::cout << "API names by identifier (C):\n";
     for ( size_t i = 0; apis[i] != RTAUDIO_API_UNSPECIFIED; ++i) {
-        const std::string name = rtaudio_compiled_api_name(apis[i]);
+        const std::string name = rtaudio_api_name(apis[i]);
         if (name.empty()) {
-            std::cerr << "Invalid name for API " << (int)apis[i] << "\n";
+            std::cout << "Invalid name for API " << (int)apis[i] << "\n";
             exit(1);
         }
-        const std::string displayName = rtaudio_compiled_api_display_name(apis[i]);
+        const std::string displayName = rtaudio_api_display_name(apis[i]);
         if (displayName.empty()) {
-            std::cerr << "Invalid display name for API " << (int)apis[i] << "\n";
+            std::cout << "Invalid display name for API " << (int)apis[i] << "\n";
             exit(1);
         }
         std::cout << "* " << (int)apis[i] << " '" << name << "': '" << displayName << "'\n";
@@ -103,16 +103,16 @@ int test_c() {
 
     // ensure unknown APIs return the empty string
     {
-        const char *s = rtaudio_compiled_api_name((rtaudio_api_t)-1);
+        const char *s = rtaudio_api_name((rtaudio_api_t)-1);
         const std::string name(s?s:"");
         if (!name.empty()) {
-            std::cerr << "Bad string for invalid API '" << name << "'\n";
+            std::cout << "Bad string for invalid API '" << name << "'\n";
             exit(1);
         }
-        s = rtaudio_compiled_api_display_name((rtaudio_api_t)-1);
+        s = rtaudio_api_display_name((rtaudio_api_t)-1);
         const std::string displayName(s?s:"");
         if (displayName!="Unknown") {
-            std::cerr << "Bad display string for invalid API '" << displayName << "'\n";
+            std::cout << "Bad display string for invalid API '" << displayName << "'\n";
             exit(1);
         }
     }
@@ -120,10 +120,10 @@ int test_c() {
     // try getting API identifier by name
     std::cout << "API identifiers by name (C):\n";
     for ( size_t i = 0; apis[i] != RTAUDIO_API_UNSPECIFIED ; ++i ) {
-        const char *s = rtaudio_compiled_api_name(apis[i]);
+        const char *s = rtaudio_api_name(apis[i]);
         std::string name(s?s:"");
         if ( rtaudio_compiled_api_by_name(name.c_str()) != apis[i] ) {
-            std::cerr << "Bad identifier for API '" << name << "'\n";
+            std::cout << "Bad identifier for API '" << name << "'\n";
             exit( 1 );
         }
         std::cout << "* '" << name << "': " << (int)apis[i] << "\n";
@@ -132,7 +132,7 @@ int test_c() {
             name[j] = (j & 1) ? toupper(name[j]) : tolower(name[j]);
         rtaudio_api_t api = rtaudio_compiled_api_by_name(name.c_str());
         if ( api != RTAUDIO_API_UNSPECIFIED ) {
-            std::cerr << "Identifier " << (int)api << " for invalid API '" << name << "'\n";
+            std::cout << "Identifier " << (int)api << " for invalid API '" << name << "'\n";
             exit( 1 );
         }
     }
@@ -142,7 +142,7 @@ int test_c() {
         rtaudio_api_t api;
         api = rtaudio_compiled_api_by_name("");
         if ( api != RTAUDIO_API_UNSPECIFIED ) {
-            std::cerr << "Bad identifier for unknown API name\n";
+            std::cout << "Bad identifier for unknown API name\n";
             exit( 1 );
         }
     }