reference return for API names
authorJP Cimalando <jpcima@users.noreply.github.com>
Wed, 8 Aug 2018 16:51:45 +0000 (18:51 +0200)
committerJP Cimalando <jpcima@users.noreply.github.com>
Wed, 8 Aug 2018 16:51:45 +0000 (18:51 +0200)
RtAudio.cpp
RtAudio.h

index 7b7c8efd3701a76aece071013885a43d96cb5dc6..07a63144d375a745ff4dfc35e75ffd2e935c4bb7 100644 (file)
@@ -160,22 +160,25 @@ const std::vector<RtAudio::Api>& RtAudio :: getCompiledApi()
   return compiledApis;
 }
 
-const std::string RtAudio :: getCompiledApiName( RtAudio::Api api )
+static const std::string unknown_api_name = "";
+static const std::string unknown_api_display_name = "Unknown";
+
+const std::string& RtAudio :: getCompiledApiName( RtAudio::Api api )
 {
   ApiNameMap::const_iterator it;
   for (it = apiNames.begin(); it != apiNames.end(); it++)
     if (it->second.first == api)
       return it->first;
-  return "";
+  return unknown_api_name;
 }
 
-const std::string RtAudio :: getCompiledApiDisplayName( RtAudio::Api api )
+const std::string& RtAudio :: getCompiledApiDisplayName( RtAudio::Api api )
 {
   ApiNameMap::const_iterator it;
   for (it = apiNames.begin(); it != apiNames.end(); it++)
     if (it->second.first == api)
       return it->second.second;
-  return "Unknown";
+  return unknown_api_display_name;
 }
 
 RtAudio::Api RtAudio :: getCompiledApiByName( const std::string &name )
index 78d96a91ed4490c873eaaa2336c353a1ad74229a..3927ae19e7ac3e2e5d5da3246c7dd79c9ab273f7 100644 (file)
--- a/RtAudio.h
+++ b/RtAudio.h
@@ -416,7 +416,7 @@ class RTAUDIO_DLL_PUBLIC RtAudio
     If the API is unknown or not compiled, this function will return
     the empty string.
   */
-  static const std::string getCompiledApiName( RtAudio::Api api );
+  static const std::string& getCompiledApiName( RtAudio::Api api );
 
   //! Return the display name of a specified compiled audio API.
   /*!
@@ -424,7 +424,7 @@ class RTAUDIO_DLL_PUBLIC RtAudio
     If the API is unknown or not compiled, this function will return
     the empty string.
   */
-  static const std::string getCompiledApiDisplayName( RtAudio::Api api );
+  static const std::string& getCompiledApiDisplayName( RtAudio::Api api );
 
   //! Return the compiled audio API having the given name.
   /*!