TEST(TemplateTypeTest, templateTest)
{
    std::string         inputStr(R"({"templateMember":[1,2,3,4]})");
    std::stringstream   input(inputStr);
    std::stringstream   output;
    TemplateTypeTest::TemplateType<int>   data;

    input  >> ThorsAnvil::Serialize::jsonImport(data);
    output << ThorsAnvil::Serialize::jsonExport(data, ThorsAnvil::Serialize::PrinterInterface::OutputType::Stream);

    EXPECT_EQ(output.str(), inputStr);
}

TEST(TemplateTypeTest, normalInheritingFromtemplateTest)
{
    std::string         inputStr(R"({"templateMember":[1,2,3,4],"normalName":"A name"})");
    std::stringstream   input(inputStr);
    std::stringstream   output;
    TemplateTypeTest::NormalInheritFromTemplate   data;

    input  >> ThorsAnvil::Serialize::jsonImport(data);
    output << ThorsAnvil::Serialize::jsonExport(data, ThorsAnvil::Serialize::PrinterInterface::OutputType::Stream);

    EXPECT_EQ(output.str(), inputStr);
}
  void executeElevatorServices(char input[])
  {
    std::string inputStr(input);

    switch (input[0]) {
    case 'o':
      open_close_elev_doors_client.call(openElevDoorsCall);
      break;
    case 'c':
      open_close_elev_doors_client.call(closeElevDoorsCall);
      break;
    case 's':
      setElevPropsCall.request.velocity = parseFloat(inputStr.substr(1));
      set_elev_props_client.call(setElevPropsCall);
      break;
    case 'f':
      setElevPropsCall.request.force = parseFloat(inputStr.substr(1));
      set_elev_props_client.call(setElevPropsCall);
      break;
    default:
      try {
        targetFloorCall.request.target_floor = std::stoi(inputStr);
        target_floor_elev_client.call(targetFloorCall);
      } catch (std::exception const & e) {
        std::cout << "Unknown command" << std::endl;
      }
    };
  }
Exemplo n.º 3
0
std::string TextLoader::LoadFullFile(std::string fileName)
{
   try
   {
      std::ifstream inputStr(fileName);
      std::string str = "";
      if(inputStr)
      {

         inputStr.seekg(0, std::ios::end);   
         str.reserve(inputStr.tellg());
         inputStr.seekg(0, std::ios::beg);

         str.assign((std::istreambuf_iterator<char>(inputStr)),
                  std::istreambuf_iterator<char>());
         inputStr.close();
      }
      else
      {
         LOG(ERROR) << "Could not load file "  << fileName;
      }
      return str;
   }
   catch(std::ifstream::failure e)
   {
      LOG(ERROR) << "Error opening file";
      return "";
   }

}
Exemplo n.º 4
0
int main(int argc, char const *argv[]) {
	std::fstream file_out( "out.txt" , std::fstream::out);
	// std::fstream file( "in.txt" , std::fstream::in);

	//std::string inputStr("1 8");  // found 4
	//std::string inputStr("2 16");  // found 4
	//std::string inputStr("37 12392342");  // found 23104.9993088173
	std::string inputStr("1 2000000000");  // found 76374950.8918325007
	std::istringstream iss(inputStr);

	//std::istream& input = std::cin;
	std::istream& input = iss;
	// std::istream& input = file;

	std::cout.precision(10);
	std::cout << std::fixed;
	std::ostream& output = std::cout;
	// std::ostream& output = file_out;

	double c;
	input >> c;

	double time;
	input >> time;

	SortEstimate se;

	double numberOfInts = se.howMany(c, time, output);
	output << "\n\nnumberOfInts = " << numberOfInts << "\n";

	file_out.close();
	return 0;
}
Exemplo n.º 5
0
string Benchmark::init() throw(std::runtime_error)
{
    raw_buffer inputBuffer = input();
    string inputStr(inputBuffer.m_str, inputBuffer.m_len);
    json_t *parsed = json_parse_document(inputStr.c_str());
    if (!parsed)
        throw runtime_error("Failed to parse json input");
    json_free_value(&parsed);
    return inputStr;
}
  void readLineInput(char input[30])
  {
    std::cin.getline(input, 30);

    std::string inputStr(input);
    if (boost::iequals(inputStr, "q"))
    {
      rosNode.shutdown();
      std::exit(EXIT_SUCCESS);
    }
  }
  bool setControlType(char input[])
  {
    std::string inputStr(input);

    if (boost::iequals(inputStr, "door"))
    {
      std::cout << "Control type set to 'door'" << std::endl;
      type = DOOR;
      setActiveUnits();
      return true;
    }
    else if (boost::iequals(inputStr, "elevator"))
    {
      std::cout << "Control type set to 'elevator'" << std::endl;
      type = ELEVATOR;
      setActiveUnits();
      return true;
    }

    return false;
  }
  void executeDoorServices(char input[])
  {
    std::string inputStr(input);

    switch (input[0]) {
    case 'o':
      open_close_doors_client.call(openDoorsCall);
      break;
    case 'c':
      open_close_doors_client.call(closeDoorsCall);
      break;
    case 'l':
      setVelDoorsCall.request.lin_x = setVelDoorsCall.request.lin_y = parseFloat(inputStr.substr(1));
      set_vel_doors_client.call(setVelDoorsCall);
      break;
    case 'a':
      setVelDoorsCall.request.ang_z = parseFloat(inputStr.substr(1));
      set_vel_doors_client.call(setVelDoorsCall);
      break;
    default:
      std::cout << "Unknown command" << std::endl;
    };
  }
Exemplo n.º 9
0
static int
MimeInlineTextPlain_parse_line (char *line, PRInt32 length, MimeObject *obj)
{
  int status;
  PRBool quoting = ( obj->options
    && ( obj->options->format_out == nsMimeOutput::nsMimeMessageQuoting ||
         obj->options->format_out == nsMimeOutput::nsMimeMessageBodyQuoting
       )           );  // see above
  PRBool plainHTML = quoting || (obj->options &&
       obj->options->format_out == nsMimeOutput::nsMimeMessageSaveAs);
       // see above

  PRBool rawPlainText = obj->options &&
       (obj->options->format_out == nsMimeOutput::nsMimeMessageFilterSniffer
       || obj->options->format_out == nsMimeOutput::nsMimeMessageAttach);

  // this routine gets called for every line of data that comes through the
  // mime converter. It's important to make sure we are efficient with 
  // how we allocate memory in this routine. be careful if you go to add
  // more to this routine.

  NS_ASSERTION(length > 0, "zero length");
  if (length <= 0) return 0;

  mozITXTToHTMLConv *conv = GetTextConverter(obj->options);
  MimeInlineTextPlain *text = (MimeInlineTextPlain *) obj;

  PRBool skipConversion = !conv || rawPlainText ||
                          (obj->options && obj->options->force_user_charset);

  char *mailCharset = NULL;
  nsresult rv;

  // if this part has a name and it's not a message/rfc822, don't quote
  if (quoting && obj->headers && MimeHeaders_get_name(obj->headers, obj->options) 
      && PL_strcasecmp(obj->content_type, MESSAGE_RFC822))
    return 0;

  if (!skipConversion)
  {
    nsDependentCString inputStr(line, length);
    nsAutoString lineSourceStr;

    // For 'SaveAs', |line| is in |mailCharset|.
    // convert |line| to UTF-16 before 'html'izing (calling ScanTXT())
    if (obj->options->format_out == nsMimeOutput::nsMimeMessageSaveAs)
    { // Get the mail charset of this message.
      MimeInlineText  *inlinetext = (MimeInlineText *) obj;
      if (!inlinetext->initializeCharset)
         ((MimeInlineTextClass*)&mimeInlineTextClass)->initialize_charset(obj);
      mailCharset = inlinetext->charset;
      if (mailCharset && *mailCharset) {
        rv = nsMsgI18NConvertToUnicode(mailCharset, inputStr, lineSourceStr);
        NS_ENSURE_SUCCESS(rv, -1);
      }
      else // this probably never happens ...
        CopyUTF8toUTF16(inputStr, lineSourceStr);
    }
    else  // line is in UTF-8
      CopyUTF8toUTF16(inputStr, lineSourceStr);

    nsCAutoString prefaceResultStr;  // Quoting stuff before the real text

    // Recognize quotes
    PRUint32 oldCiteLevel = text->mCiteLevel;
    PRUint32 logicalLineStart = 0;
    rv = conv->CiteLevelTXT(lineSourceStr.get(),
                            &logicalLineStart, &(text->mCiteLevel));
    NS_ENSURE_SUCCESS(rv, -1);

    // Find out, which recognitions to do
    PRBool whattodo = obj->options->whattodo;
    if (plainHTML)
    {
      if (quoting)
        whattodo = 0;  // This is done on Send. Don't do it twice.
      else
        whattodo = whattodo & ~mozITXTToHTMLConv::kGlyphSubstitution;
                   /* Do recognition for the case, the result is viewed in
                      Mozilla, but not GlyphSubstitution, because other UAs
                      might not be able to display the glyphs. */
      if (!text->mBlockquoting)
        text->mCiteLevel = 0;
    }

    // Write blockquote
    if (text->mCiteLevel > oldCiteLevel)
    {
      prefaceResultStr += "</pre>";
      for (PRUint32 i = 0; i < text->mCiteLevel - oldCiteLevel; i++)
      {
        nsCAutoString style;
        MimeTextBuildPrefixCSS(text->mQuotedSizeSetting, text->mQuotedStyleSetting,
                               text->mCitationColor, style);
        if (!plainHTML && !style.IsEmpty())
        {
          prefaceResultStr += "<blockquote type=cite style=\"";
          prefaceResultStr += style;
          prefaceResultStr += "\">";
        }
        else
          prefaceResultStr += "<blockquote type=cite>";
      }
      prefaceResultStr += "<pre wrap>";
    }
    else if (text->mCiteLevel < oldCiteLevel)
    {
      prefaceResultStr += "</pre>";
      for (PRUint32 i = 0; i < oldCiteLevel - text->mCiteLevel; i++)
        prefaceResultStr += "</blockquote>";
      prefaceResultStr += "<pre wrap>";
      if (text->mCiteLevel == 0)
        prefaceResultStr += "<!---->";   /* Make sure, NGLayout puts out
                                            a linebreak */
    }

    // Write plain text quoting tags
    if (logicalLineStart != 0 && !(plainHTML && text->mBlockquoting))
    {
      if (!plainHTML)
        prefaceResultStr += "<span class=\"moz-txt-citetags\">";

      nsAutoString citeTagsSource;
      lineSourceStr.Mid(citeTagsSource, 0, logicalLineStart);

      // Convert to HTML
      nsXPIDLString citeTagsResultUnichar;
      rv = conv->ScanTXT(citeTagsSource.get(), 0 /* no recognition */,
                         getter_Copies(citeTagsResultUnichar));
      if (NS_FAILED(rv)) return -1;

      AppendUTF16toUTF8(citeTagsResultUnichar, prefaceResultStr);
      if (!plainHTML)
        prefaceResultStr += "</span>";
    }


    // recognize signature
    if ((lineSourceStr.Length() >= 4)
        && lineSourceStr.First() == '-'
        && Substring(lineSourceStr, 0, 3).EqualsLiteral("-- ")
        && (lineSourceStr[3] == '\r' || lineSourceStr[3] == '\n') )
    {
      text->mIsSig = PR_TRUE;
      if (!quoting)
        prefaceResultStr += "<div class=\"moz-txt-sig\">";
    }


    /* This is the main TXT to HTML conversion:
       escaping (very important), eventually recognizing etc. */
    nsXPIDLString lineResultUnichar;

    rv = conv->ScanTXT(lineSourceStr.get() + logicalLineStart,
                       whattodo, getter_Copies(lineResultUnichar));
    NS_ENSURE_SUCCESS(rv, -1);

    if (!(text->mIsSig && quoting))
    {
      status = MimeObject_write(obj, prefaceResultStr.get(), prefaceResultStr.Length(), PR_TRUE);
      if (status < 0) return status;
      nsCAutoString outString;
      if (obj->options->format_out != nsMimeOutput::nsMimeMessageSaveAs ||
          !mailCharset || !*mailCharset)
        CopyUTF16toUTF8(lineResultUnichar, outString);
      else
      { // convert back to mailCharset before writing.       
        rv = nsMsgI18NConvertFromUnicode(mailCharset, 
                                         lineResultUnichar, outString);
        NS_ENSURE_SUCCESS(rv, -1);
      }

      status = MimeObject_write(obj, outString.get(), outString.Length(), PR_TRUE);
    }
    else
    {
      status = NS_OK;
    }
  }
  else
  {
    status = MimeObject_write(obj, line, length, PR_TRUE);
  }

  return status;
}
Exemplo n.º 10
0
bool Language::untar(wxString file_source, wxString directory)
{
	#ifdef DEBUG
		wxPuts("Start UNTAR");
	#endif
    
	int i = 0;
    wxFFileInputStream inputStr(file_source);
    if (inputStr.Ok())
    {
        wxTarInputStream tarStr(inputStr);

        wxTarEntry* tarEntry = NULL;
        while (true)
        {
            if (tarEntry)
            {
                delete tarEntry;
            }
            tarEntry = tarStr.GetNextEntry();
            if (!tarEntry)
                break;
            else
            {
                if (tarEntry->GetTypeFlag() == wxTAR_REGTYPE)
                {
                    wxString tarFile = tarEntry->GetInternalName();
					
                    // Extract to destination
                    wxString destFilename = directory + tarFile;
                    tarStr.OpenEntry(*tarEntry);
                    wxString path = wxPathOnly(destFilename);

                    if (!wxDirExists(path)) {
						wxString p;
						wxStringTokenizer tkz(path, wxT("/\\"));
						p = tkz.GetNextToken();
						while (tkz.HasMoreTokens())
						{
							wxString token = tkz.GetNextToken();

							p += wxFILE_SEP_PATH + token;
							if (!wxDirExists(p))
							{
								if (!wxMkdir(p)) {
									wxPuts("problem creating dir");
									return 0;
								}
							}
						}
					}
					wxFileOutputStream outStream(destFilename);
					if (!outStream.Ok()) {
						return 0;
					}
					static unsigned char buf[1024];
					size_t bytesLeft = tarStr.GetSize();
					while (bytesLeft > 0)
					{
						size_t bytesToRead = wxMin((size_t) 1024, bytesLeft);
						tarStr.Read((void*) buf, bytesToRead);
						outStream.Write((void*) buf, bytesToRead);
						bytesLeft -= bytesToRead;
					}
					// chmod?
                }
                i ++;
            }
        }
    }
	#ifdef DEBUG
		wxPuts("Done UNTAR");
	#endif
	
	return 1;
}
bool MapperTestDAImpl::Exec( Context &context, ParameterMapper *input, ResultMapper *output)
{
	StartTrace1(MapperTestDAImpl.Exec, fName);
	Anything config, anyDataType;
	TraceAny(fConfig, "fConfig: ");
	String strMode;
	if ( input->Get("DataType", anyDataType, context) ) {
		strMode = anyDataType.AsString();
	} else {
		strMode = "String";
	}
	Trace("DataType is [" << strMode << "]");

	if ( input->Get("transfer", config, context) ) {
		TraceAny(config, "Config: ");
		for (long i = 0, sz=config.GetSize(); i < sz; i++) {
			String strGetKey, strPutKey;
			Anything anyEntry = config[i];
			strGetKey = config.SlotName(i);
			if ( anyEntry.GetType() == AnyArrayType ) { //<! assume unnamed configuration entries { /getKey putKey }
				strGetKey = anyEntry.SlotName(0L);
				anyEntry = anyEntry[0L];
			}
			strPutKey = anyEntry.AsString();
			Trace("get key [" << strGetKey << "] put key [" << strPutKey << "]");
			if (strGetKey.Length()) {
				String inputStr(128L);
				bool bGetCode, bPutCode = false;
				if (strMode.Compare("int") == 0) {
					int iTestVal = 0;
					bGetCode = input->Get(strGetKey, iTestVal, context);
					if (bGetCode) {
						bPutCode = output->Put(strPutKey, iTestVal, context);
						Trace("From [" << strGetKey << "] to [" << strPutKey << "]: [" << (long)iTestVal << "]");
					}
				} else if (strMode.Compare("long") == 0) {
					long lTestVal = 0L;
					bGetCode = input->Get(strGetKey, lTestVal, context);
					if (bGetCode) {
						bPutCode = output->Put(strPutKey, lTestVal, context);
						Trace("From [" << strGetKey << "] to [" << strPutKey << "]: [" << lTestVal << "]");
					}
				} else if (strMode.Compare("bool") == 0) {
					bool bTestVal = false;
					bGetCode = input->Get(strGetKey, bTestVal, context);
					if (bGetCode) {
						bPutCode = output->Put(strPutKey, bTestVal, context);
						Trace("From [" << strGetKey << "] to [" << strPutKey << "]: [" << (bTestVal ? "true" : "false") << "]");
					}
				} else if (strMode.Compare("float") == 0) {
					float fTestVal = 0.0F;
					bGetCode = input->Get(strGetKey, fTestVal, context);
					if (bGetCode) {
						bPutCode = output->Put(strPutKey, fTestVal, context);
						Trace("From [" << strGetKey << "] to [" << strPutKey << "]: [" << fTestVal << "]");
					}
				} else if (strMode.Compare("double") == 0) {
					double dTestVal = 0.0;
					bGetCode = input->Get(strGetKey, dTestVal, context);
					if (bGetCode) {
						bPutCode = output->Put(strPutKey, dTestVal, context);
						Trace("From [" << strGetKey << "] to [" << strPutKey << "]: [" << dTestVal << "]");
					}
				} else if (strMode.Compare("Anything") == 0) {
					Anything aTestVal;
					bGetCode = input->Get(strGetKey, aTestVal, context);
					if (bGetCode) {
						bPutCode = output->Put(strPutKey, aTestVal, context);
						StringStream Ios(inputStr);
						aTestVal.PrintOn(Ios);
						Ios << std::flush;
						Trace("From [" << strGetKey << "] to [" << strPutKey << "]: [" << inputStr << "]");
					}
				} else if (strMode.Compare("StringStream") == 0) {
					StringStream Ios(inputStr);
					bGetCode = input->Get(strGetKey, Ios, context);
					Ios << std::flush;
					if (bGetCode) {
						bPutCode = output->Put(strPutKey, Ios, context);
						Trace("From [" << strGetKey << "] to [" << strPutKey << "]: [" << inputStr << "]");
					}
				} else {
					// default is String mode
					String sTestVal = "";
					bGetCode = input->Get(strGetKey, sTestVal, context);
					if (bGetCode) {
						bPutCode = output->Put(strPutKey, sTestVal, context);
						Trace("From [" << strGetKey << "] to [" << strPutKey << "]: [" << sTestVal << "]");
					}
				}
				Trace("GetCode: " << (bGetCode ? "true" : "false") << " PutCode: " << (bPutCode ? "true" : "false"));
			}
		}
		Trace("ret: true");
		return true;
	}
	Trace("ret: false");
	return false;
}