Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "DbcSignal.hpp"
00036
00037 #include <vector>
00038 #include <istream>
00039 #include <sstream>
00040 #include <limits>
00041 #include <iterator>
00042 #include <algorithm>
00043
00044 std::string& trim(std::string& str, const std::string& toTrim = " ") {
00045 std::string::size_type pos = str.find_last_not_of(toTrim);
00046 if (pos == std::string::npos) {
00047 str.clear();
00048 } else {
00049 str.erase(pos + 1);
00050 str.erase(0, str.find_first_not_of(toTrim));
00051 }
00052 return str;
00053 }
00054
00055 std::vector<std::string>& split(const std::string &s, char delim, std::vector<std::string> &elems) {
00056 std::stringstream ss(s);
00057 std::string item;
00058 while (std::getline(ss, item, delim)) {
00059 elems.push_back(item);
00060 }
00061 return elems;
00062 }
00063
00064 std::vector<std::string> split(const std::string &s, char delim) {
00065 std::vector<std::string> elems;
00066 split(s, delim, elems);
00067 return elems;
00068 }
00069
00070 std::istream& operator>>(std::istream& in, Signal& sig) {
00071 std::string line;
00072 std::getline(in, line);
00073 if (!line.empty() && *line.rbegin() == '\r') {
00074 line.erase(line.length() - 1, 1);
00075 }
00076 if (line.empty()) {
00077 in.setstate(std::ios_base::failbit);
00078 return in;
00079 }
00080
00081
00082 std::istringstream sstream(line);
00083 std::string preamble;
00084 sstream >> preamble;
00085 if (preamble != "SG_") {
00086 in.setstate(std::ios_base::failbit);
00087 return in;
00088 }
00089
00090
00091 sstream >> sig.name;
00092
00093 std::string multi;
00094 sstream >> multi;
00095
00096
00097 if (multi == ":") {
00098 sig.multiplexor = NONE;
00099 } else {
00100
00101 if (multi == "M") {
00102 sig.multiplexor = MULTIPLEXOR;
00103 } else {
00104
00105 std::istringstream multstream(multi);
00106 multstream.ignore(1);
00107 unsigned short multiNum;
00108 multstream >> multiNum;
00109 sig.multiplexor = MULTIPLEXED;
00110 sig.multiplexNum = multiNum;
00111 }
00112
00113 sstream >> multi;
00114 }
00115
00116 sstream >> sig.startBit;
00117 sstream.ignore(1);
00118 sstream >> sig.length;
00119 sstream.ignore(1);
00120
00121 int order;
00122 sstream >> order;
00123 if (order == 0) {
00124 sig.order = MOTOROLA;
00125 } else {
00126 sig.order = INTEL;
00127 }
00128
00129 char sign;
00130 sstream >> sign;
00131 if (sign == '+') {
00132 sig.sign = UNSIGNED;
00133 } else {
00134 sig.sign = SIGNED;
00135 }
00136
00137
00138 sstream.ignore(std::numeric_limits<std::streamsize>::max(), '(');
00139 sstream >> sig.factor;
00140 sstream.ignore(1);
00141 sstream >> sig.offset;
00142 sstream.ignore(1);
00143
00144
00145 sstream.ignore(std::numeric_limits<std::streamsize>::max(), '[');
00146 sstream >> sig.minimum;
00147 sstream.ignore(1);
00148 sstream >> sig.maximum;
00149 sstream.ignore(1);
00150
00151
00152 std::string unit;
00153 sstream >> unit;
00154 sig.unit = trim(unit, "\"");
00155
00156
00157 std::string to;
00158 sstream >> to;
00159 std::vector<std::string> toStrings = split(to, ',');
00160 for (size_t i = 0; i < toStrings.size(); i++) {
00161 sig.to.insert(sig.to.end(), toStrings[i]);
00162 }
00163
00164 return in;
00165 }
00166