Exemplo n.º 1
0
void definefile( std::ostringstream& data, fs::ifstream& input, std::string& name, bool useconst = false ) {
	/* Check if already defined */
	std::vector<std::string>::iterator search = std::find( list.begin(), list.end(), name );
	if ( search == list.end() ) {
		list.push_back( name );
	} else {
		/* Show warning, object of this name is already processed! */
		std::cout << "Warning: '" << name << "' already defined, processing of new one stopped." << std::endl;
		return;
	}

	/* Define array */
	data << "static" << ( useconst ? " const " : " " ) << "unsigned char " << name << "[] = {" << std::endl;
	
	int size = input.tellg();
	input.seekg( 0, std::ios::beg );

	int c = 0;
	int col = 0;

	for ( int i = 1; i <= size; ++i ) {
		/* Get character and add to array */
		c = input.get();

		/*
			Using a static copy of the boost::format string gives a nice performance boost!
			Boost help says using const boost::format fmter(fstring);
			But static is faster and using the object without copy constructor is even faster!
		*/
		//static boost::format fmt( "0x%02X" );
		//data << fmt % c;

		/*
			Fast option then... this code is executed allot!
			Still faster then the optimized boost::format use, but not that much!
		*/
		static char temp[5];
		snprintf( temp, 5, "0x%02X", c );
		data << temp;

		if ( i >= size ) {
			/* Last character */
			data << std::endl;
		} else {
			/* Next */
			data << ", ";
		}

		/* New colume? */
		int curcol = ( i / 10 );
		if ( col < curcol ) {
			col = curcol;
			data << std::endl;
		}
	}

	data << "};" << std::endl << std::endl;
}
Exemplo n.º 2
0
  void ErrorFile::parse(boost::filesystem::ifstream& is)
  {
    std::string line;


    // matches[1], warning/error type
    // matches[2], rest of line
    boost::regex warningOrError("^\\s*\\**\\s+\\*\\*\\s*([^\\s\\*]+)\\s*\\*\\*(.*)$");

    // matches[1], rest of line
    boost::regex warningOrErrorContinue("^\\s*\\**\\s+\\*\\*\\s*~~~\\s*\\*\\*(.*)$");

    // completed successfully
    boost::regex completedSuccessful("^\\s*\\*+ EnergyPlus Completed Successfully.*");

    // ground temp completed successfully
    boost::regex groundTempCompletedSuccessful("^\\s*\\*+ GroundTempCalc\\S* Completed Successfully.*");

    // completed unsuccessfully
    boost::regex completedUnsuccessful("^\\s*\\*+ EnergyPlus Terminated.*");

    // repeat count


    // read the file line by line using regexes
    while(std::getline(is, line)){

      boost::smatch matches;

//      LOG(Debug, "Parsing ErrorFile Line: " << line);


      // parse the file
      if (boost::regex_search(line, matches, warningOrError)){
        std::string warningOrErrorType = std::string(matches[1].first, matches[1].second); boost::trim(warningOrErrorType);
        std::string warningOrErrorString = std::string(matches[2].first, matches[2].second); boost::trim(warningOrErrorString);

        // read the rest of the multi line warning or error
        while(true){
          std::streampos pos = is.tellg();
          if (!std::getline(is, line)){
            break;
          }
          if (boost::regex_search(line, matches, warningOrErrorContinue)){
            std::string temp = std::string(matches[1].first, matches[1].second); boost::trim_right(temp);
            warningOrErrorString += "\n" + temp;
          }else{
            // unget the line
            is.seekg(pos);
            break;
          }
        }

        LOG(Trace, "Error parsed: " << warningOrErrorString);


        // correctly sort warnings and errors
        try{
          ErrorLevel level(warningOrErrorType);

          switch(level.value()){
            case ErrorLevel::Warning:
              m_warnings.push_back(warningOrErrorString);
              break;
            case ErrorLevel::Severe:
              m_severeErrors.push_back(warningOrErrorString);
              break;
            case ErrorLevel::Fatal:
              m_fatalErrors.push_back(warningOrErrorString);
              break;
          }

        }catch(...){
          LOG(Error, "Unknown warning or error level '" << warningOrErrorType << "'");
        }

      }else if (boost::regex_match(line, completedSuccessful) 
                || boost::regex_match(line, groundTempCompletedSuccessful)) {
        m_completed = true;
        m_completedSuccessfully = true;
        break;
      }else if (boost::regex_match(line, completedUnsuccessful)){
        m_completed = true;
        m_completedSuccessfully = false;
        break;
      }
    }

  }