diagnostic_msgs::DiagnosticStatus getMemoryStatus() {
    diagnostic_msgs::DiagnosticStatus memoryStatus;

    memoryStatus.name = "memoryStatus";
    memoryStatus.message = "The current memory status is ";
    float percentage = (memory.memFree + memory.memCached + memory.memBuffers) * 1.0 / memory.memTotal;
    if (0.3 <= percentage) {
	memoryStatus.level = 0;
	memoryStatus.message += " OK";
    }
    else if (0.2 <= percentage) {
	memoryStatus.level = 1;
	memoryStatus.message += " moderate";
    }
    else {
	memoryStatus.level = 2;
	memoryStatus.message += " weak";
    }

    memoryStatus.hardware_id = "memory";
    memoryStatus.values.resize(5);

    floatStringHelper.clear();
    floatStringHelper << percentage;
    memoryStatus.values[0].key = "free";
    floatStringHelper >> memoryStatus.values[0].value;

    floatStringHelper.clear();
    floatStringHelper << memory.memTotal;
    memoryStatus.values[1].key = "memTotal";
    floatStringHelper >> memoryStatus.values[1].value;

    floatStringHelper.clear();
    floatStringHelper << memory.memFree;
    memoryStatus.values[2].key = "memFree";
    floatStringHelper >> memoryStatus.values[2].value;

    floatStringHelper.clear();
    floatStringHelper << memory.memCached;
    memoryStatus.values[3].key = "memCached";
    floatStringHelper >> memoryStatus.values[3].value;

    floatStringHelper.clear();
    floatStringHelper << memory.memBuffers;
    memoryStatus.values[4].key = "memBuffers";
    floatStringHelper >> memoryStatus.values[4].value;

    return memoryStatus;
}
Example #2
0
void GuiHelper::printBytesPercent(GRender& render, uint32_t x, uint32_t y, long total, long other) {

	static std::stringstream ss;
	ss.str("");
	ss.clear();
	ss.imbue(std::locale(""));

	std::string unit;
	int div = 1;
	int digits = 0;

	switch (bytePercentUnit) {
	case GH_TYPE_BYTE:	div = 1; digits = 0; unit = " B"; break;
	case GH_TYPE_KBYTE: div = 1024; digits = 1; unit = " KiB"; break;
	case GH_TYPE_MBYTE: div = 1024 * 1024; digits = 1; unit = " MiB"; break;
	}

	float percent = (total) ? (100.0 * other / (total)) : (0);
	ss << " (" << std::setiosflags(std::ios::fixed) << std::setprecision(1) << percent << "%)";
	render.printR(x, y, ss.str());
	ss.str("");
	ss << std::setprecision(digits) << (other / (float) div) << unit ;
	render.printR(x-9, y, ss.str());

}
Example #3
0
void printERRLOG() {
  std::string errLine;
  while( std::getline(ERRLOG,errLine) ) {
    std::cerr << errLine << std::endl;
  }
  ERRLOG.clear();
}
 // This resets the flags of streamToReset and sets its string to be
 // newString.
 inline void
 ParsingUtilities::ResetStringstream( std::stringstream& streamToReset,
                                      std::string const& newString )
 {
   streamToReset.clear();
   streamToReset.str( newString );
 }
Example #5
0
    void init(uint64_t const _i)
    {
        i = _i;

        if (options.doubleIndexing)
        {
            indexBeginQry = (length(gH.qrySeqs) / options.queryPart) * i;
            indexEndQry = (i+1 == options.queryPart) // last interval
                            ? length(gH.qrySeqs) // reach until end
                            : (length(gH.qrySeqs) / options.queryPart) * (i+1);
            // make sure different frames of one sequence in same interval
            indexBeginQry -= (indexBeginQry % qNumFrames(blastProgram));
            indexEndQry -= (indexEndQry % qNumFrames(blastProgram));
        } else
        {
            indexBeginQry = qNumFrames(blastProgram) * i;
            indexEndQry = qNumFrames(blastProgram) * (i+1);
        }

        clear(seeds);
        clear(seedIndex);
        matches.clear();
        seedRefs.clear();
        seedRanks.clear();
//         stats.clear();
        statusStr.clear();
        statusStr.precision(2);
    }
Example #6
0
void NaCl::flushLogs() {
    string loutStr = lout.str();
    if(loutStr.length() != 0) {
        accumulatedEvents.Set("isDirty", true);
		accumulatedEvents.Set("messages", loutStr);
        lout.str(string());
        lout.clear();
    }
    string lerrStr = lerr.str();
    if(lerrStr.length() != 0) {
        accumulatedEvents.Set("isDirty", true);
		accumulatedEvents.Set("errors", lerrStr);
        lerr.str(string());
        lerr.clear();
    }
}
Example #7
0
   void setup () {

      // ----------------------------------------------------------------------
      // Initialize the Log component

      // Name of log file
      log_file = Parameters::get_optional<std::string>(
            "Log.log_file", "log.txt");
      log_file = Driver::output_dir + log_file;

      // Open log file
#ifdef PARALLEL_MPI
      if (Driver::proc_ID == log_master) {
         lout.open(log_file.c_str());
      }
#else // PARALLEL_MPI
      lout.open(log_file.c_str());
#endif // PARALLEL_MPI
      initialized = true;

      // Write the log file header
      lout << "Hydrodynamics Simulation" << std::endl << std::endl;

      // If the buffer is not empty, push it to the file
      lout << buffer.str();
      buffer.clear();
      buffer.str("");

   }
Example #8
0
// stringstreamをクリアして再利用できるようにする
void IPBase::clear_stringstream(std::stringstream &ss) {
	static const std::string empty_string;

	ss.str(empty_string);
	ss.clear();
	ss << std::dec;     // clear()でも元に戻らないので、毎回指定する。
}
Example #9
0
void CPlayer::SendSteamMessages(MessageTypes type, std::stringstream &ss)
{
    if (!ss.str().empty())
    {
        std::string item;

        while (std::getline(ss, item))
        {
            item = MSG_COLOR_WHITE + item + "|r"; // Default chat to white.
            const char* msg = item.c_str();

            if ((type & CHAT_BOX) != 0)
                ChatHandler(GetSession()).SendSysMessage(msg);
            if ((type & CHAT_WIDE) != 0)
            {
                WorldPacket data(SMSG_NOTIFICATION, (strlen(msg) + 1));
                data << msg;
                GetSession()->SendPacket(&data);
            }
        }

        ss.str(""); // Clear content
        ss.clear(); // Clear state flags.
    }
}
Example #10
0
void SettingsDAOSqlite3Impl::set( const std::string& key, const double& value ) {
	static std::stringstream ss;
	ss.str("");
	ss.clear();
	ss << value;
	set( key, ss.str() );
}
    virtual std::string generateIndexedIndependent(const OperationNode<Base>& indexedIndep,
            const IndexPattern& ip) override {
        bool isX = indexedIndep.getInfo()[0] == 0;
        if (isX) {
            return _nameGen->generateIndexedIndependent(indexedIndep, ip);
        }

        size_t nIndex = indexedIndep.getArguments().size();

        CPPADCG_ASSERT_KNOWN(indexedIndep.getOperationType() == CGOpCode::LoopIndexedIndep, "Invalid node type");
        CPPADCG_ASSERT_KNOWN(nIndex > 0, "Invalid number of arguments");

        std::vector<const IndexDclrOperationNode<Base>*> indices(nIndex);
        for (size_t i = 0; i < nIndex; ++i) {// typically there is only one index but there may be more
            CPPADCG_ASSERT_KNOWN(indexedIndep.getArguments()[i].getOperation() != nullptr, "Invalid argument");
            CPPADCG_ASSERT_KNOWN(indexedIndep.getArguments()[i].getOperation()->getOperationType() == CGOpCode::Index, "Invalid argument");
            indices[i] = &static_cast<const IndexOperationNode<Base>&> (*indexedIndep.getArguments()[i].getOperation()).getIndex();
        }

        _ss.clear();
        _ss.str("");

        _ss << _multName << "[" << LanguageC<Base>::indexPattern2String(ip, indices) << "]";
        return _ss.str();
    }
Example #12
0
void NCursesIOManager::setupNewLine(std::stringstream & ss, int & positionX, int & positionY) const
{
	move(positionY, positionX);
	++positionY;
	ss.clear();
	ss.str("");
}
Example #13
0
bool XQueryCompiler::getLanguageMode(std::stringstream& s) const
{
  const size_t lPeekSize = 7;
  char lPeek[lPeekSize];
  s.get(lPeek, lPeekSize);
  s.clear();
  s.seekg(0, s.beg);

  bool lXQueryMode;

  if (strncmp(lPeek, "jsoniq", lPeekSize - 1) == 0)
  {
    lXQueryMode = false;
  }
  else if (strncmp(lPeek, "xquery", lPeekSize - 1) == 0)
  {
    lXQueryMode = true;
  }
  else
  {
    if (theCompilerCB->theRootSctx) // could be null in eval
    {
      StaticContextConsts::language_kind_t lKind
        = theCompilerCB->theRootSctx->language_kind();
      lXQueryMode = (lKind != StaticContextConsts::language_kind_jsoniq);
    }
    else
    {
      lXQueryMode = true;
    }
  }
  return lXQueryMode;
}
Example #14
0
std::string to_string(const T& item) {
    static std::stringstream ss;
    ss.clear();

    ss << item;

    return ss.str();
}
Example #15
0
returnType from_hex_string(std::string str) {
    static std::stringstream ss;
    ss.clear();
    ss << std::hex << str;
    returnType retval;
    ss >> retval;
    
    return retval;
}
Example #16
0
returnType from_string(const std::string& str) {
    static std::stringstream ss;
    ss.clear();
    ss << str;
    returnType retval;
    ss >> retval;

    return retval;
}
Example #17
0
diagnostic_msgs::DiagnosticStatus getSwapStatus() {
    diagnostic_msgs::DiagnosticStatus swapStatus;

    swapStatus.name = "swapStatus";
    swapStatus.message = "The current swap space status is ";
    float percentage = (memory.swapFree + memory.swapCached) * 1.0 / memory.swapTotal;
    if (0.5 <= percentage) {
	swapStatus.level = 0;
	swapStatus.message += " OK";
    }
    else if (0.25 <= percentage) {
	swapStatus.level = 1;
	swapStatus.message += " moderate";
    }
    else {
	swapStatus.level = 2;
	swapStatus.message += " weak";
    }

    swapStatus.hardware_id = "swap_space";
    swapStatus.values.resize(4);

    floatStringHelper.clear();
    floatStringHelper << percentage;
    swapStatus.values[0].key = "free";
    floatStringHelper >> swapStatus.values[0].value;

    floatStringHelper.clear();
    floatStringHelper << memory.swapTotal;
    swapStatus.values[1].key = "swapTotal";
    floatStringHelper >> swapStatus.values[1].value;

    floatStringHelper.clear();
    floatStringHelper << memory.swapFree;
    swapStatus.values[2].key = "swapFree";
    floatStringHelper >> swapStatus.values[2].value;

    floatStringHelper.clear();
    floatStringHelper << memory.swapCached;
    swapStatus.values[3].key = "swapCached";
    floatStringHelper >> swapStatus.values[3].value;

    return swapStatus;
}
Example #18
0
void GuiHelper::printInt(GRender& render, uint32_t x, uint32_t y, long val) {

	static std::stringstream ss;
	ss.str("");
	ss.clear();
	ss.imbue(std::locale(""));

	ss << val;
	render.printR(x, y, ss.str());

}
    virtual std::string generateIndependent(const OperationNode<Base>& independent) override {
        size_t id = independent.getVariableID();
        if (id < _minMultiplierID) {
            return _nameGen->generateIndependent(independent);
        }

        _ss.clear();
        _ss.str("");
        _ss << _multName << "[" << (id - _minMultiplierID) << "]";
        return _ss.str();
    }
Example #20
0
void NetworkDataSource::FetchData(IVariables* variables)
{
	static std::stringstream str;
	auto result = recv(socket_, inputBuff_, BUFF_SIZE - 1, 0);
	if (result <= 0) return;

	inputBuff_[result] = '\0';

	if (str.str().size() > 10000)
	{
		str.clear();
	}

	bool newline = false;
	for (int i = 0; i < result; ++i)
		if (inputBuff_[i] == '\n')
		{
			newline = true;
		}

	str << inputBuff_;

	if (newline)
	{
		std::string command;
		std::getline(str, command);
		std::cout << "\n-------\nRECV:\n\t" << command << "\n------------\n";

		std::stringstream cmd(command);

		std::string type, name, value;
		char eqSign = 0;
		cmd >> type >> name >> eqSign >> value;

		if (eqSign != '=') return;
		if (type == "int")
		{
			variables->Set(name, std::stoi(value));
		}
		else if (type == "float")
		{
			variables->Set(name, std::stof(value));
		}
		else if (type == "string")
		{
			std::string tmp;
			while (cmd >> tmp)
			{
				value += " ";
				value += tmp;
			}
			variables->Set(name, value);
		}
	}
void lua_console::read_stream( std::stringstream &stream, nc_color text_color )
{
    std::string line;
    while( std::getline( stream, line ) ) {
        for( auto str : foldstring( line, width ) ) {
            text_stack.push_back( {str, text_color} );
        }
    }
    stream.str( std::string() ); // empty the buffer
    stream.clear();
}
Example #22
0
void GuiHelper::printFloat(GRender& render, uint32_t x, uint32_t y, float val, const std::string& unit) {

	static std::stringstream ss;
	ss.str("");
	ss.clear();
	ss << std::setiosflags(std::ios::fixed);
	ss << std::setprecision(1);

	ss << val << unit;
	render.printR(x, y, ss.str());

}
Example #23
0
int readLine(std::istream& is, std::stringstream& currentLine)
{
  if (is.eof())
    return -1;
  currentLine.str("");
  currentLine.clear();
  is.get(*currentLine.rdbuf());
  if (is.fail()) // fail is set on empty lines
    is.clear();
  G2O_FSKIP_LINE(is); // read \n not read by get()
  return static_cast<int>(currentLine.str().size());
}
Example #24
0
 /*
 * Transfer the next line of input to a stringstream
 */
 bool getLine(std::istream& in, std::stringstream& line)
 {
    std::string string;
    line.str(string);
    line.clear();
    if (!in.eof()) {
       getline(in, string);
       line.str(string);
       return true;
    } else {
       return false;
    }
 }
Example #25
0
void newtestinit() {

  // Reset counters
  N_SUCCESS = 0;
  N_FAIL = 0;

  // Clear error stream
  ERRLOG.clear();
  ERRLOG.str("");

  std::cout << std::endl << "UNIT TESTING STARTED" << std::endl;
  
}
Example #26
0
  void Environment::run_file(std::string path) {
    std::ifstream file(path.c_str(), std::ios::ate|std::ios::binary);

    if(!file) {
      std::string msg = std::string("Unable to open file to run: ");
      msg.append(path);
      throw std::runtime_error(msg);
    }

    std::streampos length = file.tellg();
    std::vector<char> buffer(length);
    file.seekg(0, std::ios::beg);
    file.read(&buffer[0], length);
    stream.clear();
    stream.rdbuf()->pubsetbuf(&buffer[0], length);

    CompiledFile* cf = CompiledFile::load(stream);
    if(cf->magic != "!RBIX") throw std::runtime_error("Invalid file");
    if((signature_ > 0 && cf->signature != signature_)
        || cf->version != version_) {
      throw BadKernelFile(path);
    }

    cf->execute(state);

    if(state->vm()->thread_state()->raise_reason() == cException) {
      Exception* exc = as<Exception>(state->vm()->thread_state()->current_exception());
      std::ostringstream msg;

      msg << "exception detected at toplevel: ";
      if(!exc->message()->nil_p()) {
        if(String* str = try_as<String>(exc->message())) {
          msg << str->c_str(state);
        } else {
          msg << "<non-string Exception message>";
        }
      } else if(Exception::argument_error_p(state, exc)) {
        msg << "given "
            << as<Fixnum>(exc->get_ivar(state, state->symbol("@given")))->to_native()
            << ", expected "
            << as<Fixnum>(exc->get_ivar(state, state->symbol("@expected")))->to_native();
      }
      msg << " (" << exc->klass()->debug_str(state) << ")";
      std::cout << msg.str() << "\n";
      exc->print_locations(state);
      Assertion::raise(msg.str().c_str());
    }

    delete cf;
  }
Example #27
0
void GuiHelper::printIntPercent(GRender& render, uint32_t x, uint32_t y, long total, long other, const std::string& unit) {

	static std::stringstream ss;
	ss.str("");
	ss.clear();
	ss.imbue(std::locale(""));

	float percent = (total) ? (100.0 * other / (total)) : (0);
	ss << " (" << std::setiosflags(std::ios::fixed) << std::setprecision(1) << percent << "%)";
	render.printR(x, y, ss.str());
	ss.str("");
	ss << other << unit ;
	render.printR(x-9, y, ss.str());

}
Example #28
0
    void buildLine(std::stringstream& ss, TTF_Font *face)
    {
        TextLine oTempLine;
        ss << '\0';
        oTempLine.sLineStr = ss.str();

        int w, h;
        TTF_SizeText(face, oTempLine.sLineStr.c_str(), &w, &h);

        oTempLine.iLineWidth = w;

        iMaxLineWidth = MAX(iMaxLineWidth, oTempLine.iLineWidth);
        ss.clear();
        ss.str("");
        vLines.push_back(oTempLine);
	}
Example #29
0
void getCode() {
	if (cntTAB == 0)
		std::cout << "$ ";
	else {
		for (int i = 1; i <= cntTAB; ++i)
			std::cout << "\t";
	}
	std::string s;
	do {
		getline(std::cin, s);
	} while (s == "");
	ss.str("");
	ss.clear();
	ss << s;
//	std::cerr << "hello" << s << "bye";
}
Example #30
0
void MAVShell::tokenize_stream(std::stringstream &sstream) {
    string cmd_line;
    //get command line (everything up to '\n')
    while( getline(sstream, cmd_line) ) {
        istringstream cmd_stream(cmd_line);

        // copy cmd_line to vector as whitespace separated strings
        istream_iterator<string> begin(cmd_stream);
        istream_iterator<string> end;
        vector<string> argv(begin, end);

        execute_cmd(argv);
    }
    // we have to clear the stringstream, otherwise all operations on the stream will fail instantly
    sstream.clear();
}