3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
|
* Copyright (C) 2005 - 2007 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
37 |
* ******************************************************/ |
* ******************************************************/ |
38 |
|
|
39 |
#include "lscpresultset.h" |
#include "lscpresultset.h" |
40 |
|
#include <iomanip> |
41 |
|
#include "../common/global_private.h" |
42 |
|
|
43 |
//Construct an empty resultset |
//Construct an empty resultset |
44 |
//Default index is -1 meaning the resultset doesn't have an index |
//Default index is -1 meaning the resultset doesn't have an index |
62 |
//Values could be of different types for now supports String, int and float. |
//Values could be of different types for now supports String, int and float. |
63 |
void LSCPResultSet::Add(String Label, String Value) { |
void LSCPResultSet::Add(String Label, String Value) { |
64 |
if (count == -1) |
if (count == -1) |
65 |
throw LinuxSamplerException("Attempting to change already produced resultset"); |
throw Exception("Attempting to change already produced resultset"); |
66 |
if (result_type != result_type_success) |
if (result_type != result_type_success) |
67 |
throw LinuxSamplerException("Attempting to create illegal resultset"); |
throw Exception("Attempting to create illegal resultset"); |
68 |
storage = storage + Label + ": " + Value + "\r\n"; |
storage = storage + Label + ": " + Value + "\r\n"; |
69 |
count++; |
count = 2; // results in form of "Label: Value" should always be handled as multi line responses |
70 |
} |
} |
71 |
|
|
72 |
void LSCPResultSet::Add(String Label, const char* pValue) { |
void LSCPResultSet::Add(String Label, const char* pValue) { |
94 |
} |
} |
95 |
|
|
96 |
void LSCPResultSet::Add(String Label, float Value) { |
void LSCPResultSet::Add(String Label, float Value) { |
97 |
char s[1024]; |
std::stringstream ss; |
98 |
snprintf(s, 1023, "%.3f", Value); |
ss.imbue(std::locale::classic()); |
99 |
Add(Label, String(s)); |
ss << std::fixed << std::setprecision(3) << Value; |
100 |
|
Add(Label, ss.str()); |
101 |
} |
} |
102 |
|
|
103 |
void LSCPResultSet::Add(String Label, bool Value) { |
void LSCPResultSet::Add(String Label, bool Value) { |
108 |
//Add a single string to the resultset |
//Add a single string to the resultset |
109 |
void LSCPResultSet::Add(String Value) { |
void LSCPResultSet::Add(String Value) { |
110 |
if (result_type != result_type_success) |
if (result_type != result_type_success) |
111 |
throw LinuxSamplerException("Attempting to create illegal resultset"); |
throw Exception("Attempting to create illegal resultset"); |
112 |
if (count == -1) |
if (count == -1) |
113 |
throw LinuxSamplerException("Attempting to change already produced resultset"); |
throw Exception("Attempting to change already produced resultset"); |
114 |
if (count != 0) |
if (count != 0) |
115 |
throw LinuxSamplerException("Attempting to create illegal resultset"); |
throw Exception("Attempting to create illegal resultset"); |
116 |
storage = Value + "\r\n"; |
storage = Value + "\r\n"; |
117 |
count = 1; |
count = 1; |
118 |
} |
} |
123 |
//This method will be used to generate unknown errors only (code 0) |
//This method will be used to generate unknown errors only (code 0) |
124 |
//To generate errors with other codes as well as warnings use other methods (below). |
//To generate errors with other codes as well as warnings use other methods (below). |
125 |
//Because this is an unknown error, this method will also print message to the stderr. |
//Because this is an unknown error, this method will also print message to the stderr. |
126 |
void LSCPResultSet::Error(LinuxSamplerException e) { |
void LSCPResultSet::Error(Exception e) { |
127 |
e.PrintMessage(); |
e.PrintMessage(); |
128 |
Error(e.Message()); |
Error(e.Message()); |
129 |
} |
} |