Exemple #1
0
void Reporter::printMidQuotesAndTrades(std::ostream& os, Errors& errors)
{
    StrStream strstream;
    if (unlikely(bids_.begin() == bids_.end() || asks_.begin() == asks_.end()))
    {
        strstream << "NAN" << '\n';
    }
    else if (receivedNewTrade_)
    {
        strstream << getQty(currentTrade_) << '@' << getPrice(currentTrade_) << '\n';
        receivedNewTrade_ = false;
        detectCross_ = false;
    }
    else if (unlikely(getPrice(*bids_.begin()) >= getPrice(*asks_.begin())))
    {
        if (likely(!detectCross_)) detectCross_ = true;
        else
        {
            strstream << "Cross BID (" << getPrice(*bids_.begin()) <<  ")/ASK(" << getPrice(*asks_.begin()) << ')' << '\n';
            ++errors.bestBidEqualOrUpperThanBestAsk;
        }
    }
    else
    {
        Price midQuote = (getPrice(*bids_.begin())+getPrice(*asks_.begin()))/2;
        strstream << midQuote << '\n';
    }
    os.rdbuf()->sputn(strstream.c_str(), strstream.length());
    os.flush();
}
Exemple #2
0
void testIdiomSearch(char *idiom)
{
	StrStream st;
	EDict::testIdiom(idiom, st);
	st.print();
	
}
Exemple #3
0
int	extractCron::do_job(char *jobdesc)
{
	ACE_SOCK_Connector conn;
	ACE_SOCK_Stream  peer;
	ACE_Time_Value tv(3, 0);
	ACE_INET_Addr	addr(harvestPort, harvestIPaddr);
	char	urlbuff[1024];
	StrStream	httpreq;
	int	ret;

	printf("JobDesc: %s\n", jobdesc);
	CGI::escape(urlbuff, jobdesc);
	httpreq.init(2); // 2 kilobytes buff
	httpreq.rawadd("GET /harvest?expr=");
	httpreq.rawadd(urlbuff);
	httpreq.rawadd(" HTTP/1.1\n\n");

	httpreq.print();
	
	if ( conn.connect(peer, addr) < 0) {
		printf("conn failed!\n");
		return 0;
	}

	ret = peer.send( httpreq.str(), httpreq.len() );
	return 0;
	
}
Exemple #4
0
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 doIOTest() {
  using namespace fs;
  using Ptr = const CharT*;
  using StrStream = std::basic_stringstream<CharT>;
  const char* const InCStr = InStr;
  const Ptr E = OutStr;
  const path p((const char*)InStr);
  StrStream ss;
  { // test output
    auto& ret = (ss << p);
    assert(ss.str() == E);
    assert(&ret == &ss);
  }
  { // test input
    path p_in;
    auto& ret = ss >> p_in;
    assert(p_in.native() == (const char*)InStr);
    assert(&ret == &ss);
  }
}
Exemple #6
0
	//-------------------------------------------------------------------
	void ZenWorld::_readVobTree(ZenArchive* _zenArchive, const WorldObjectPtr& _root)
	{
		Progress& progress = Progress::getSingleton();
		progress.setPosition(_zenArchive->getDataStream()->tellg());

		StrStream ss;
		ss << "childs" << mChildID++;
		int childs = _zenArchive->readInt(ss.str());
		for(int i = 0; i != childs; ++i)
		{
			WorldObjectPtr wobj;
			if(!_root.isNull())
			{
				wobj = _zenArchive->readObject();
				if(!wobj.isNull())
				{
					_root->addChild(wobj, true);
				}
			}
			_readVobTree(_zenArchive, wobj);
		}
	}
Exemple #7
0
int
main (int argc, char **argv)
{
	int	res=0;
	char fname[256];
	
	/*
	if (argc < 2) {
		printf("option: w for word, i for idiom\n");
		exit(0);
	}
	*/
	init_env();	

	HanChar::prepare();

	//test_nameValPairTable();
	
	/*
	res = dbStore::prepare(
		config.GetStrVal("DBNAME", "ANYDICT"),
		config.GetStrVal("DBID", "inisoft"),
		config.GetStrVal("DBPASS", "gksehf")
		);
	*/
	//res = dbStore::prepare( "ANYDICT2", "inisoft", "gksehf");
	if (res < 0) {
		return -1;
	}

	HDict::load(adhome);
	HGram::load(adhome);

	printf("### %s", argv[0]);
	if (argc > 1) printf("\tOption: %s", argv[1]);
	printf("\n\n");

	printf("# JH2WS_TABSIZE = %d\n", JH2WS_TABSIZE);
	if (argc > 1 && argv[1][0]=='w') {
		HanChar::printCodeTab();
	}
	
	if (argc > 1 && argv[1][0]=='y') {
		HanChar::printSylInfo();
	}

	if (argc > 1 && argv[1][0]=='d') {
		HDict::printList();
	}

	if (argc > 1 && argv[1][0]=='c') {
		HDict::printListConjOnly();
	}

	if (argc > 1 && argv[1][0]=='a') {
		HDict::printListAuxOnly();
	}

	if (argc > 1 && argv[1][0]=='j') {
		HDict::printListJosaOnly();
	}

	if (argc > 1 && argv[1][0]=='e') {
		HDict::printListEomiOnly();
	}
	
	if (argc > 1 && argv[1][0]=='g') {
		HGram::printList();
	}
	
	if (argc > 1 && argv[1][0]=='s') {
		StrStream resStr;
		resStr.init(10*1024);
		HProc::test_stemmer( StrUtil::path_merge(fname, adhome, "dataH/test-howtoberich.txt"),  resStr);
	}

	
	return 0;
		
}
Exemple #8
0
void Reporter::printErrors(std::ostream& os, Errors& errors, const int verbose)
{
    StrStream strstream;    
    strstream << "Summary:";
    
    // Parsing (not really errors)
    if (unlikely(errors.commentedLines))
    {
        strstream << "\n [" << errors.commentedLines << "] commented lines";
    }
    if (unlikely(errors.blankLines))
    {
        strstream << "\n [" << errors.blankLines << "] blank lines";
    }
    
    auto nbErrors = errors.nbErrors();
    if (unlikely(nbErrors > 0))
    {
        strstream << "\nFound " << nbErrors << " error:";
        
        // Parsing
        if (unlikely(errors.corruptedMessages))
        {
            strstream << "\n [" << errors.corruptedMessages << "] corrupted messages";
        }
        if (unlikely(errors.IncompleteMessages))
        {
            strstream << "\n [" << errors.IncompleteMessages << "] incomplete messages";
        }
        if (unlikely(errors.wrongActions))
        {
            strstream << "\n [" << errors.wrongActions << "] wrong actions";
        }
        if (unlikely(errors.wrongSides))
        {
            strstream << "\n [" << errors.wrongSides << "] wrong sides";
        }
        if (unlikely(errors.negativeOrderIds))
        {
            strstream << "\n [" << errors.negativeOrderIds << "] negative orderIds";
        }
        if (unlikely(errors.negativeQuantities))
        {
            strstream << "\n [" << errors.negativeQuantities << "] negative quantities";
        }
        if (unlikely(errors.negativePrices))
        {
            strstream << "\n [" << errors.negativePrices << "] negative prices";
        }
        if (unlikely(errors.missingActions))
        {
            strstream << "\n [" << errors.missingActions << "] missing actions";
        }
        if (unlikely(errors.missingOrderIds))
        {
            strstream << "\n [" << errors.missingOrderIds << "] missing orderIds";
        }
        if (unlikely(errors.missingSides))
        {
            strstream << "\n [" << errors.missingSides << "] missing sides";
        }
        if (unlikely(errors.missingQuantities))
        {
            strstream << "\n [" << errors.missingQuantities << "] missing quantities";
        }
        if (unlikely(errors.missingPrices))
        {
            strstream << "\n [" << errors.missingPrices << "] missing prices";
        }
        if (unlikely(errors.zeroOrderIds))
        {
            strstream << "\n [" << errors.zeroOrderIds << "] zero orderIds";
        }
        if (unlikely(errors.zeroQuantities))
        {
            strstream << "\n [" << errors.zeroQuantities << "] zero quantities";
        }
        if (unlikely(errors.zeroPrices))
        {
            strstream << "\n [" << errors.zeroPrices << "] zero prices";
        }
        if (unlikely(errors.outOfBoundsOrderIds))
        {
            strstream << "\n [" << errors.outOfBoundsOrderIds << "] out of bounds orderIds";
        }
        if (unlikely(errors.outOfBoundsQuantities))
        {
            strstream << "\n [" << errors.outOfBoundsQuantities << "] out of bounds quantities";
        }
        if (unlikely(errors.outOfBoundsPrices))
        {
            strstream << "\n [" << errors.outOfBoundsPrices << "] out of bounds prices";
        }
        
        // Order Management
        if (unlikely(errors.duplicateOrderIds))
        {
            strstream << "\n [" << errors.duplicateOrderIds << "] duplicate OrderIds";
        }
        if (unlikely(errors.modifiesWithUnknownOrderId))
        {
            strstream << "\n [" << errors.modifiesWithUnknownOrderId << "] modifies with unknown OrderIds";
        }
        if (unlikely(errors.modifiesNotMatchedPrice))
        {
            strstream << "\n [" << errors.modifiesNotMatchedPrice << "] modifies with not matched order price";
        }
        if (unlikely(errors.cancelsWithUnknownOrderId))
        {
            strstream << "\n [" << errors.cancelsWithUnknownOrderId << "] cancels with unknown OrderIds";
        }
        if (unlikely(errors.cancelsNotMatchedQtyOrPrice))
        {
            strstream << "\n [" << errors.cancelsNotMatchedQtyOrPrice << "] cancels with not matched order price";
        }
        if (unlikely(errors.bestBidEqualOrUpperThanBestAsk))
        {
            strstream << "\n [" << errors.bestBidEqualOrUpperThanBestAsk << "] best bid equal or upper than best ask";
        }
    }        
    else
    {
        strstream << "\nNo error found";
    }
    
    auto nbCriticalErrors = errors.nbCriticalErrors();
    if (unlikely(nbCriticalErrors > 0))
    {
        strstream << "\nFound [" << nbCriticalErrors << "] critical error:";
        if (unlikely(errors.modifiesLimitQtyTooLow))
        {
            strstream << "\n [" << errors.modifiesLimitQtyTooLow << "] modifies with limit quantity too low";
        }
        if (unlikely(errors.modifiesLimitNotFound))
        {
            strstream << "\n [" << errors.modifiesLimitNotFound << "] modifies limit not found";
        }
        if (unlikely(errors.cancelsLimitQtyTooLow))
        {
            strstream << "\n [" << errors.cancelsLimitQtyTooLow << "] cancels with limit quantity too low";
        }
        if (unlikely(errors.cancelsLimitNotFound))
        {
            strstream << "\n [" << errors.cancelsLimitNotFound << "] cancels limit not found";
        }
    }
    else
    {
        strstream << "\nNo critical error found";
    }
    
    strstream << '\n';
    if (unlikely(verbose))
        strstream << "Summary length: " << strstream.length() << '\n';
    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;
	}