void Reporter::printCurrentOrderBook(std::ostream& os) const { StrStream strstream; auto cap = strstream.capacity() - 128; const auto nbBids = bids_.size(); const auto nbAsks = asks_.size(); os << "Full Bids/Asks:\n"; auto i = 0U; while (1) { StrStream strstream_tmp; if (i < nbBids) { Limit bid = bids_[i]; strstream_tmp << i; strstream_tmp.append(6, ' '); strstream_tmp << ": " << getQty(bid) << " @ " << getPrice(bid); strstream_tmp.append(40, ' '); if (i < nbAsks) { Limit ask = asks_[i]; strstream_tmp << getQty(ask) << " @ " << getPrice(ask) << '\n'; } else { strstream_tmp << "empty\n"; } } else { strstream_tmp << i; strstream_tmp.append(6, ' '); strstream_tmp << ": empty"; strstream_tmp.append(40, ' '); if (i < nbAsks) { Limit ask = asks_[i]; strstream_tmp << getQty(ask) << " @ " << getPrice(ask) << '\n'; } else { strstream << strstream_tmp; strstream << "empty\n"; break; } } if (strstream.length() + strstream_tmp.length() > cap) { os.rdbuf()->sputn(strstream.c_str(), strstream.length()); strstream.clear(); } strstream << strstream_tmp; ++i; } os.rdbuf()->sputn(strstream.c_str(), strstream.length()); os.flush(); }
//--------------------------------------------------------------------------- void EnumUtil::input(StrStream& _ss, int& _value, const NameValueMap& _nameValueMap) { if(_ss.fail()) return; // Skip spaces int c; while((c = _ss.peek()) == ' ') _ss.ignore(1); if(isdigit(c)) { // a number, not a name _ss >> _value; return; } String tempStr; if(c == '\'' || c == '\"') { // Name is delimited by quotes int delim = c; int numDelims = 0; while(true) { c = _ss.get(); if(!_ss.gcount()) { _ss.clear(std::ios_base::eofbit); // eofbit could raise failbit too, clearing break; } tempStr.push_back(c); if(c == delim) { if(++numDelims == 2) break; } } } else { // Name is a string containing letters, digits, and underscores while(true) { c = _ss.get(); if(!_ss.gcount()) { _ss.clear(std::ios_base::eofbit); // eofbit could raise failbit too, clearing break; } if(isalnum(c) || c == '_') { tempStr.push_back(c); } else { _ss.unget(); break; } } } // Searching the read name in the map NameValueMap::const_iterator it = _nameValueMap.find(tempStr); if(it == _nameValueMap.end()) _ss.seekg(-1); // set error state else _value = it->second; }