void init_logging()
{
    init_factories();

    std::istringstream strm(settings);
    logging::init_from_stream(strm);
}
float CHelperXMLAttributes::getValueAsFloat(const String& attrName, float def) const
{
	if (!exists(attrName))
	{
		return def;
	}

	float val;
	std::istringstream strm(getValue(attrName).c_str());

	strm >> val;

	// success?
	if (strm.fail())
	{
		char szException[MAX_PATH] = {0};
		_snprintf(szException, MAX_PATH, 
			"CHelperXMLAttributes::getValueAsInteger - failed to convert attribute '%s' with value '%s' to float.",
			attrName.c_str(), 
			getValue(attrName).c_str());

		throw std::exception(szException);
	}

	return val;
}
Example #3
0
FileSkeleton::FileSkeleton(const std::string &filename)
{
    ifstream strm(filename.c_str());
  
    if(!strm.is_open()) {
        Debugging::out() << "Error opening file " << filename << endl;
        return;
    }

    while(!strm.eof()) {
        vector<string> line = readWords(strm);
        if(line.size() < 5)
            continue; //error

        Vector3 p;
        sscanf(line[1].c_str(), "%lf", &(p[0]));
        sscanf(line[2].c_str(), "%lf", &(p[1]));
        sscanf(line[3].c_str(), "%lf", &(p[2]));

        if(line[4] == "-1")
            line[4] = std::string();

        makeJoint(line[0], p * 2., line[4]);
    }

    initCompressed();
}
Example #4
0
void VerifyCorrectWorkIstreamOperator(std::string const &str)
{
	std::istringstream strm(str);
	CMyString myStr;
	strm >> myStr;
	BOOST_CHECK_EQUAL(myStr.GetStringData(), str);
}
// Output hexdump to a QString
QString QWSHexDump::toString() {
    QString result;
    QTextStream strm(&result, QFile::WriteOnly);
    outstrm = &strm;
    hexDump();
    return result;
}
// static
void LLFloaterProperties::onClickCopy(void* user_data)
{
	LLFloaterProperties* floaterp = (LLFloaterProperties*)user_data;
	if(floaterp)
	{
		LLViewerInventoryItem* item = (LLViewerInventoryItem*)floaterp->findItem();
		if(item)
		{
			std::string str(floaterp->childGetValue("item_text").asString());
			std::string::size_type pos;
			while((pos = str.find("    ")) != std::string::npos)
			{
				str.replace(pos, 4, "\t");
			}

			std::istringstream strm(str);
			LLViewerInventoryItem* temp = new LLViewerInventoryItem();
			temp->importLegacyStream(strm);
			std::ostringstream strm2;
			temp->exportLegacyStream(strm2, TRUE);
			LLWString wstr(utf8str_to_wstring(strm2.str()));

			gClipboard.copyFromSubstring(wstr, 0, wstr.length());

			//delete temp;
		}
	}
}
void stream_client()
{
  try 
  {
    std::cout << "Connecting to " << url << std::endl;

    saga::stream::stream strm (url);
    strm.connect ();

    std::cout << "Connected!" << std::endl;

    std::string msg ("test from client\n");
    std::cout << "Sending : " << msg;
    strm.write (saga::buffer (msg));

    char buff[255];
    saga::ssize_t read_bytes = strm.read (saga::buffer (buff));

    std::cout << "Received: " << std::string (buff, read_bytes) << std::endl;
  } 
  catch ( saga::exception const & e )
  {
    std::cerr << "saga::exception caught: " << e.what () << std::endl;
	++exit_code;
  }
}
Example #8
0
/////////////////////////////////////////////////////////////////////////
// Load the distributed UAI file
bool line_parser(graph_type& graph, const std::string& filename, const std::string& textline) {
    std::stringstream strm(textline);
    graphlab::vertex_id_type vid;
    vertex_data vdata;
    vdata.dual_contrib = 0.0;
    string type;
    strm >> type;
 
     if(type == "v") { 
      vdata.factor_type = VAR;
      vdata.nvars = 1;
      vdata.cards.resize(1);
      strm>>vid;
      strm >> vdata.cards[0];
      vdata.potentials.resize(vdata.cards[0]);
      //vdata.beliefs.setOnes(vdata.cards[0]);
      //vdata.beliefs /= vdata.cards[0];
      vdata.beliefs.setConstant(vdata.cards[0], 0.5);
      vdata.unary_degree.resize(vdata.cards[0], 0);
      //for(int i=0; i< vdata.cards[0]; i++){
      // strm>>vdata.potentials[i];
      //   vdata.potentials[i] = log10(vdata.potentials[i]);
         
      //   }
     //    vdata.potentials.maxCoeff(&vdata.best_configuration);
      graph.add_vertex(vid,vdata);
    }
Example #9
0
void QuantityManager::read(const std::string & data) {
	std::stringstream strm(data);
	std::string line;
	while (getline(strm,line)) {
		IBK::trim(line);
		if (line.empty() || line[0] == '#') continue;
		Quantity qd;
		try {
			qd.read(line);
		}
		catch (IBK::Exception & ex) {
			throw IBK::Exception(ex, IBK::FormatString("Cannot read quantity definition from line '%1'.")
				.arg(line), "[QuantityManager::read]");
		}
		// check if we already have such a quantity
		int idx = index(qd);
		if (idx != -1) {
			// replace quantity
			IBK::IBK_Message(IBK::FormatString("Replacing quantity '%1::%2' with new definition.\n")
							 .arg(Quantity::type2string(qd.m_type))
							 .arg(qd.m_name), IBK::MSG_PROGRESS, "QuantityManager::read" ,1);
			m_quantities[idx] = qd;
		}
		else {
			// add quantity to list
			m_quantities.push_back(qd);
			// add new reference to global index map
			m_globalIndexMap[ std::make_pair(qd.m_type, qd.m_name)]= m_quantities.size()-1;
		}
	}
}
int main(int argc, char* argv[]) {

  string alignmentFileName, geneDBFileName;

  if (argc < 3) {
    cout << "usage: printDuplicates alignemntFile genedb " << endl;
    exit(1);
  }

  alignmentFileName = argv[1];
  geneDBFileName    = argv[2];

  GeneDB genedb;
  genedb.Read(geneDBFileName);
  genedb.IndexChromosomes();

  ifstream alignmentIn;
  CrucialOpen(alignmentFileName, alignmentIn, std::ios::in);
  
  while(alignmentIn) {
    string line;
    getline(alignmentIn, line);
    if (line == "###") {
      // found the end of an entry
      

    }
    else {
      string chrName, genome, source;
      int start, end, identity;
      char a, strand, b;
      string annotationString;
      stringstream strm(line);
      strm >> chrName >> genome >> source >> start >> end >> a >> strand >> b >> annotationString;
      vector<string> annotations;
      if (source != "exon") {
        continue;
      }
      ParseSeparatedList(annotationString, annotations, ';');

      GeneDBChromosome *chromosomePtr;
      chromosomePtr = genedb.Find(chrName);
      if (chromosomePtr == NULL) {
        cout << "chromosome " << chromosomePtr << " not found in database." << endl;
        continue;
      }
      int exonIndex;
      if ( chromosomePtr->LookupIndexByStart(start, exonIndex) ) {
        if (chromosomePtr->exons[exonIndex].start <= start and 
            chromosomePtr->exons[exonIndex].end   >= end) {
          chromosomePtr->exons[exonIndex].Print(cout);
        }
      }
      else {
        
      }
    }
  }
}
Example #11
0
void MainWindow::onCellChanged(int row, int col) {
    //Determine if user caused this signal
    if(ui->tableWidget->selectedItems().contains(ui->tableWidget->item(row, col))) {
        qDebug() << "onCellChanged row="<<row<<" col="<<col;

        //Determine which column was updated
        if(col == 1 && network != NULL) {
            //Address field changed
            NetNode* node = network->getNode(ui->tableWidget->item(row, 0)->text());
            QString addrText = ui->tableWidget->item(row, col)->text();

            //Check for address formatting error
            si_address address;
            if(address.parseString(addrText.toAscii().data()) != 0) {
                //Formating error

                qDebug() << "ERROR - Invalid address! [" << addrText<<"]";

                addrText = node->getAddress().toString().c_str();

                ui->tableWidget->item(row, col)->setText(addrText);
            }
            else {
                qDebug() << "Read new address "<<address.toString().c_str();
                node->setAddress(address);
                network->computeAddresses();
            }
        }
        else if(col == 2 && network != NULL) {
            //Automatic address field changed
            NetNode* node = network->getNode(ui->tableWidget->item(row, 0)->text());

            node->setAutoAddress(ui->tableWidget->item(row, 2)->checkState() == Qt::Checked);
            network->computeAddresses();
        }
        else if(col == 3 && network != NULL) {
            //MMT Enable field changed
            NetNode* node = network->getNode(ui->tableWidget->item(row, 0)->text());

            node->setMmtEnable(ui->tableWidget->item(row, 3)->checkState() == Qt::Checked);
        }
        else if(col == 4 && network != NULL) {
            //MMT UID field changed
            NetNode* node = network->getNode(ui->tableWidget->item(row, 0)->text());

            int value = ui->tableWidget->item(row, 4)->text().toInt();
            if(value < 0 || network->isMmtUidUsed(value)) {
                QString mmtUidStr;
                QTextStream strm(&mmtUidStr);
                strm << node->getMmtUid();

                ui->tableWidget->item(row, 4)->setText(mmtUidStr);
            }
            else {
                node->setMmtUid(value);
            }
        }
    }
}
Example #12
0
    void bcast(const size_t& root, T& elem) {
#ifdef HAS_MPI
      // Get the mpi rank and size
      if(mpi_tools::rank() == root) {
        // serialize the object
        graphlab::charstream cstrm(128);
        graphlab::oarchive oarc(cstrm);
        oarc << elem;
        cstrm.flush();
        char* send_buffer = cstrm->c_str();
        int send_buffer_size = cstrm->size();
        assert(send_buffer_size >= 0);

        // send the ammount to send
        int error = MPI_Bcast(&send_buffer_size,  // Send buffer
                              1,                  // send count
                              MPI_INT,            // send type
                              root,               // root rank
                              MPI_COMM_WORLD);
        assert(error == MPI_SUCCESS);

        // send the actual data
        error = MPI_Bcast(send_buffer,  // Send buffer
                          send_buffer_size,    // send count
                          MPI_BYTE,            // send type
                          root,               // root rank
                          MPI_COMM_WORLD);
        assert(error == MPI_SUCCESS);

      } else {
        int recv_buffer_size(-1);
        // recv the ammount the required buffer size
        int error = MPI_Bcast(&recv_buffer_size,  // recvbuffer
                              1,                  // recvcount
                              MPI_INT,            // recvtype
                              root,               // root rank
                              MPI_COMM_WORLD);
        assert(error == MPI_SUCCESS);
        assert(recv_buffer_size >= 0);

        std::vector<char> recv_buffer(recv_buffer_size);
        error = MPI_Bcast(&(recv_buffer[0]),  // recvbuffer
                          recv_buffer_size,                  // recvcount
                          MPI_BYTE,            // recvtype
                          root,               // root rank
                          MPI_COMM_WORLD);
        assert(error == MPI_SUCCESS);
        // construct the local element
        namespace bio = boost::iostreams;
        typedef bio::stream<bio::array_source> icharstream;
        icharstream strm(&(recv_buffer[0]), recv_buffer.size());
        graphlab::iarchive iarc(strm);
        iarc >> elem;

      }
#else
      logstream(LOG_FATAL) << "MPI not installed!" << std::endl;
#endif
    } // end of bcast
Example #13
0
		/**
			Takes an initializer list of vectors with a length of \b vector_length
			and constructs a matrix where each of these vectors represents a set in the matrix.

			@param values - the list of vectors to construct the matrix from

			@throws std::invalid_argument - if the number of values in \b values is not equal to \b n_vectors
		*/
		BaseMatrix(const std::initializer_list<BaseMatrix<T, vector_length, 1>> &values)
		{
			if (values.size() != n_vectors)
			{
				throw DevaInvalidInputException(
					"Tried to create matrix with " + strm(n_vectors) + " columns, but passed " + strm(values.size()));
			}
			auto val_i = values.begin();
			for (int i = 0;i <= n_vectors;i++)
			{
				for (int j = 0;j <= vector_length - 1;j++)
				{
					data[i * vector_length + j] = (*val_i)(0, j);
				}
				val_i++;
			}
		}
void OSCSender::sendMessage(std::string msg){
	char buff[128];
	osc::OutboundPacketStream strm(buff, 128);
	strm << osc::BeginBundleImmediate;
	strm << osc::BeginMessage(msg.c_str()) << osc::EndMessage;
	strm << osc::EndBundle;
	transmitSocket.Send(strm.Data(), strm.Size());
}
Example #15
0
int ktup_comparison_hasch ( char *i_seq1, char *i_seq2, const int ktup)
{
  /*Ktup comparison adapted from Rob Edgar, NAR, vol32, No1, 381, 2004*/
  /*1: hasch sequence 1
    2: Count the number of seq2 ktup found in seq1
  */

  char c;
  int key;

  static HaschT*H1;
  static char *pseq;
  Hasch_entry *e;
  char *s;
  int l, ls;
  int p, a, max_dist=-1;
  double score=0;



  if (!strm (i_seq1, pseq))
    {
      if (H1)
	{
	  hdestroy (H1, declare_ktup_hasch_data, free_ktup_hasch_data);
	  string2key (NULL, NULL);
	}
      H1=hasch_sequence ( i_seq1, ktup);
      vfree (pseq);pseq=(char*)vcalloc ( strlen (i_seq1)+1, sizeof (char));
      sprintf ( pseq, "%s", i_seq1);
    }

  ls=l=strlen (i_seq2);
  s=i_seq2;
  p=0;
  while (ls>ktup)
    {
      c=s[ktup];s[ktup]='\0';
      key=string2key (s, NULL);
      e=hsearch (H1,key,FIND, declare_ktup_hasch_data, free_ktup_hasch_data);

      if ( e==NULL);
      else if ( max_dist==-1)score++;
      else
	{
	  for ( a=1; a<=(e->data)->list[1]; a++)
	    if (FABS((p-(e->data)->list[a]))<=max_dist)
	      {score++; break;}
	}
      s[ktup]=c;s++;p++;ls--;
    }
  score/=(l-ktup);
  score=(log(0.1+score)-log(0.1))/(log(1.1)-log(0.1));

  if ( score>100) score=100;
  return (int)(score*100);
}
Example #16
0
int _tmain(int argc, _TCHAR* argv[])
{
	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

	signals::IBlock* devices[1];
	int numDevices = DRIVER_HpsdrEthernet.Discover(devices, _countof(devices));
	std::cout << numDevices << " devices found" << std::endl;

	signals::IBlock* hpsdr = devices[0];
	ASSERT(hpsdr != NULL);

	typedef std::list<CAttrObserver*> TObservList;
	TObservList obsList;
	signals::IAttributes* attrs = hpsdr->Attributes();
	{
		unsigned count = attrs->Itemize(NULL, 0);
		signals::IAttribute** attrList = new signals::IAttribute*[count];
		VERIFY(attrs->Itemize(attrList, count) == count);
		for(unsigned i = 0; i < count; i++)
		{
			obsList.push_back(new CAttrObserver("", attrList[i]));
		}
		delete [] attrList;
	}

	signals::IAttribute* recvSpeed = attrs->GetByName("recvRate");
	ASSERT(recvSpeed);
	long newSpeed = 48000;
	recvSpeed->setValue(&newSpeed);

	unsigned numOut = hpsdr->Outgoing(NULL, 0);
	signals::IOutEndpoint** outEPs = new signals::IOutEndpoint*[numOut];
	VERIFY(hpsdr->Outgoing(outEPs, numOut) == numOut);
	signals::IOutEndpoint* recv1 = outEPs[2];
	signals::IEPBuffer* buff = recv1->CreateBuffer();
	recv1->Connect(buff);

	{
		CStreamObserver<signals::etypComplex> strm(buff);

		hpsdr->Start();
		Sleep(30000);
		hpsdr->Stop();
	}

	for(TObservList::iterator trans = obsList.begin(); trans != obsList.end(); trans++)
	{
		delete *trans;
	}
	buff->Release();
	delete [] outEPs;
	VERIFY(!hpsdr->Release());

	std::cout << numPackets << " entries received" << std::endl;
	Sleep(30000);
	return 0;
}
void dc_stream_receive::process_buffer(bool outsidelocked) {
  // if barrier is set. we should not process anything
  if (barrier) return;
  if (outsidelocked || bufferlock.try_lock()) {
    // only makes sense to process if we at least have
    // a header
    while (size_t(buffer.size()) >= sizeof(packet_hdr)) {
      // read the header
      packet_hdr hdr;
      buffer.peek((char*)(&hdr), sizeof(hdr));
      #ifdef DC_RECEIVE_DEBUG
      logstream(LOG_INFO) << "peeked packet header. Has length " 
                          << hdr.len << std::endl;         
      #endif
      //do we have enough to extract a single packet
      // if not, quit now!
      if (size_t(buffer.size()) < sizeof(packet_hdr) + hdr.len) break;

      buffer.skip(sizeof(packet_hdr));
      
      if ((hdr.packet_type_mask & CONTROL_PACKET) == 0) {
        bytesreceived += hdr.len;
      }

      if (hdr.packet_type_mask & BARRIER) {
        #ifdef DC_RECEIVE_DEBUG
        logstream(LOG_INFO) << "Comm barrier" << std::endl;
        #endif
        ASSERT_EQ(hdr.len, 0); // barrier packets cannot contain data
        // barrier only makes sense if we have incomplete calls
        barrier = pending_calls.value > 0;
        // ok. we do have incomplete calls. quit processing.
        if (barrier) break;
      }
      else if ((hdr.packet_type_mask & FAST_CALL) || (hdr.packet_type_mask & REPLY_PACKET)) {
        // if it is a fast call, dispatch the function immediately. replies are also fast tracked
        #ifdef DC_RECEIVE_DEBUG
        if (hdr.packet_type_mask & REPLY_PACKET) logstream(LOG_INFO) << "Is reply" << std::endl;
        else logstream(LOG_INFO) << "Is fast call" << std::endl;
        #endif
        boost::iostreams::stream<circular_char_buffer_source> strm(buffer,hdr.len);
        dc->exec_function_call(hdr.src,hdr, strm);
      }
      else if (hdr.packet_type_mask & STANDARD_CALL) {
        #ifdef DC_RECEIVE_DEBUG
        logstream(LOG_INFO) << "Is deferred call" << std::endl;
        #endif
        // not a fast call. so read out the buffer
        char* tmpbuf = new char[hdr.len];
        buffer.read(tmpbuf, hdr.len);
        pending_calls.inc();
        dc->deferred_function_call(hdr.src,hdr, tmpbuf, hdr.len);
      }
    }
    if (!outsidelocked) bufferlock.unlock();
  }
}
int is_dynamic_memory ( void *array)
{
  Memcontrol *p;
  if (array==NULL)return 0;
  p=(Memcontrol *)array;
  p-=2;
  if ( strm (p[0].check, "dy"))return 1;
  return 0;
}
Example #19
0
void Image::LoadImage(wxString image, bool remove,wxFileSystem *filesystem)
{
  m_compressedImage.Clear();
  m_scaledBitmap.Create (1,1);

  if (filesystem) {
    wxFSFile *fsfile = filesystem->OpenFile(image);
    if (fsfile) { // open successful

      wxInputStream *istream = fsfile->GetStream();

      m_compressedImage = ReadCompressedImage(istream);
    }

    // Closing and deleting fsfile is important: If this line is missing
    // opening .wxmx files containing hundreds of images might lead to a
    // "too many open files" error.
    delete fsfile;
  }
  else {
    wxFile file(image);
    if(file.IsOpened())
      {
	wxFileInputStream strm(file);
	bool ok=strm.IsOk();
	if(ok)
	    m_compressedImage = ReadCompressedImage(&strm);
	
	file.Close();
	if(ok && remove)
	  wxRemoveFile (image);
      }
  }

  wxImage Image;
  if(m_compressedImage.GetDataLen()>0)
    {
      wxMemoryInputStream istream(m_compressedImage.GetData(),m_compressedImage.GetDataLen());
      Image.LoadFile(istream);
    }
  
  m_extension = wxFileName(image).GetExt();

  if(Image.Ok())
    {
      m_originalWidth  = Image.GetWidth();
      m_originalHeight = Image.GetHeight();
    }
  else
    {
      // Leave space for an image showing an error message
      m_originalWidth  = 400;
      m_originalHeight = 250;
    }
  ViewportSize(m_viewportWidth,m_viewportHeight,m_scale);

}
Example #20
0
void MainWindow::updateTable() {
    ui->tableWidget->clearContents();
    ui->tableWidget->setRowCount(0);

    if(network != NULL) {
        qDebug() << "UpdateTable() - Start";
        QMap<QString, NetNode*> nodes = network->getNodeMap();
        QMap<QString, NetNode*>::iterator nodeIter = nodes.begin();

        //ui->tableWidget->setRowCount(nodes.size());
        int row = 0;

        while(nodeIter != nodes.end()) {
            QTableWidgetItem* name = new QTableWidgetItem(nodeIter.key());
            name->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);

            QString addrStr = nodeIter.value()->getAddress().toString().c_str();
            QTableWidgetItem* address = new QTableWidgetItem(addrStr);

            QTableWidgetItem* autoAssign = new QTableWidgetItem();
            if(nodeIter.value()->isAutoAddress()) {
                autoAssign->setCheckState(Qt::Checked);
            }
            else {
                autoAssign->setCheckState(Qt::Unchecked);
            }

            QTableWidgetItem* mmtEnable = new QTableWidgetItem();
            if(nodeIter.value()->isMmtEnabled()) {
                mmtEnable->setCheckState(Qt::Checked);
            }
            else {
                mmtEnable->setCheckState(Qt::Unchecked);
            }

            QString mmtUidStr;
            QTextStream strm(&mmtUidStr);
            strm << nodeIter.value()->getMmtUid();
            QTableWidgetItem* mmtUid = new QTableWidgetItem(mmtUidStr);

            ui->tableWidget->insertRow(row);

            qDebug() << "Insert at row "<<row;
            ui->tableWidget->setItem(row, 0, name);
            ui->tableWidget->setItem(row, 1, address);
            ui->tableWidget->setItem(row, 2, autoAssign);
            ui->tableWidget->setItem(row, 3, mmtEnable);
            ui->tableWidget->setItem(row, 4, mmtUid);

            row++;
            nodeIter++;
        }

        qDebug() << "UpdateTable() - End";
    }
}
Example #21
0
      /// Load a RINEX clock file; may set the drift and accel flags.
      bool loadFile(const std::string& filename) throw(Exception)
      {
      try {
         // open the input stream
         RinexClockStream strm(filename.c_str());
         if(!strm.is_open()) {
            Exception e("File " + filename + " could not be opened");
            GPSTK_THROW(e);
         }
         strm.exceptions(std::ios::failbit);
         //cout << "Opened file " << filename << endl;

         // declare header and data
         RinexClockHeader head;
         RinexClockData data;

         // read the RINEX clock header
         try {
            strm >> head;
         }
         catch(Exception& e) {
            e.addText("Error reading header of file " + filename);
            GPSTK_RETHROW(e);
         }
         //cout << "Read header" << endl; head.dump();

         // save in FileStore
         clkFiles.addFile(filename, head);

         // read data
         try {
            while(strm >> data) {
               //data.dump(cout);

               if(data.datatype == std::string("AS")) {
                  // add this data
                  ClockRecord rec;
                  rec.bias = data.bias; rec.sig_bias = data.sig_bias,
                  rec.drift = data.drift; rec.sig_drift = data.sig_drift,
                  rec.accel = data.accel; rec.sig_accel = data.sig_accel;
                  addClockRecord(data.sat, data.time, rec);
               }
            }
         }
         catch(Exception& e) {
            e.addText("Error reading data of file " + filename);
            GPSTK_RETHROW(e);
         }

         // close
         strm.close();

      }
      catch(Exception& e) { GPSTK_RETHROW(e); }

      }  // end RinexClockStore::loadFile()
Example #22
0
/////////////////////////////////////////////////////////////////////////
// Edge Loader (used to read the adjacency list and add edges to the graph)
bool edge_loader(graph_type& graph, const std::string& fname,
                 const std::string& textline)
{
    if ( textline.length() == 0 || textline[0] == '#' )
        return true; // empty or comment line, return
    
    std::stringstream strm(textline);
    graphlab::vertex_id_type vid;
    
    // first entry in the line is a vertex ID
    strm >> vid;
    
    if (opts.verbose > 0)
        logstream(LOG_EMPH) << "Here's the input: "
        << textline << "\n"
        << vid << "\n";
    
    // Line should contain at least 1 more number (degree of node)
    if (!strm.good())
    {
        logstream(LOG_ERROR) << "The following ajacency list line is incomplete(check adj_list standard):\n"
        << textline << std::endl;
        return EXIT_FAILURE;
    }
    
    // second entry is the out-degree
    int outdeg;
    strm >> outdeg;
    
    graphlab::vertex_id_type other_vid;
    for (int i=0; i!=outdeg; ++i)
    {
        // Line should contain more numbers (id of neighbours)
        if (!strm.good())
        {
            logstream(LOG_ERROR) << "The following ajacency list line is incomplete(check adj_list standard):\n"
            << textline << std::endl;
            return EXIT_FAILURE;
        }
        
        strm >> other_vid;
        
        // only add edges in one direction
        if (other_vid < vid)
            continue;
        
        if (opts.verbose > 0)
            logstream(LOG_EMPH) << "Adding edge: (" << vid << "," << other_vid << ")\n";
        
        edge_data edata; edata.empty = false;
        graph.add_edge(vid,other_vid,edata);
    }
    
    return true;
}
void distributed_glshared_manager::invalidate(size_t entry, const std::string &value, bool incache) {
  if (incache) {
//    read_synchronize(entry, false);
    std::stringstream strm(value);
    iarchive iarc(strm);
    glsharedobjs[entry]->load(iarc);
  }
  else {
    glsharedobjs[entry]->invalidated = true;
  }
}
Example #24
0
 void AppendParams(params_t& params, const ::std::string& data)
 {
     if( StringIsBlank(data) )
     {
         return;
     }
     ::std::istringstream strm(data);
     T param;
     strm >> param;
     params.push_back(param);
 }
Example #25
0
bool snakeInitLevel(const std::string& levelFile, SnakeGameInfo& state)
{
  std::ifstream strm(levelFile.c_str());
  if(!strm.is_open()) return false;
  std::string line;
  while(std::getline(strm, line)){
    state.level.push_back(line);
  }
  state.levelWidth = state.level[0].length();
  state.levelHeight = state.level.size();
  return true;
}
Example #26
0
void filelist::writeback(const std::map<std::string, int64_t>& data)
{
	std::string backingtmp = backingfile + ".new";
	std::ofstream strm(backingtmp);
	if(!strm)
		return;
	for(auto& i : data)
		if(i.second != 0)
			strm << i.second << " " << i.first << std::endl;
	strm.close();
	directory::rename_overwrite(backingtmp.c_str(), backingfile.c_str());
}
Example #27
0
 //! Composition operator
 void operator() (record_type const& rec, insertion_list& insertions) const
 {
     std::size_t size = m_Formatters.size();
     insertions.resize(size);
     for (std::size_t i = 0; i < size; ++i)
     {
         log::aux::basic_ostringstreambuf< char_type > buf(insertions[i]);
         stream_type strm(&buf);
         m_Formatters[i](strm, rec);
         strm.flush();
     }
 }
//---------------------------------------------------------------------------
void __fastcall TClockDlg::OKButtonClick( TObject */*Sender*/ )
{
   bigClockCorr = correction;
   // and save the correction to the correction file
   std::ofstream strm( ".\\Configuration\\time.correction", std::ios::trunc | std::ios::binary );
   if ( strm )
   {
      // date_correction is already in seconds

      strm << long( bigClockCorr * dtg::daySecs ) << std::endl;
   }
   Close();
}
Example #29
0
unsigned int getSizeOfFile( const char *filename )
{
	unsigned int fsize( 0 );
	TFileStream strm( filename );

	if( !( strm.isOpen() ) )
		return( fsize ); // of 0

	fsize = strm.Size();
	strm.Close();

	return( fsize );
}
Example #30
0
 basic_parsed_options<charT>
 parse_config_file(const char* filename, 
                   const options_description& desc,
                   bool allow_unregistered)
 { 
     // Parser return char strings
     std::basic_ifstream< charT > strm(filename);
     if (!strm) 
     {
         pdalboost::throw_exception(reading_file(filename));
     }
     return parse_config_file(strm, desc, allow_unregistered);
 }