本文整理汇总了C++中OrderList类的典型用法代码示例。如果您正苦于以下问题:C++ OrderList类的具体用法?C++ OrderList怎么用?C++ OrderList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OrderList类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: match
ZR::RetVal MyOrders::match( Order * myOrder )
{
if( myOrder->m_locked ) return ZR::ZR_FINISH;
OrderList asks;
m_asks->filterOrders( asks, myOrder->m_currency );
ZR::ZR_Number amount = myOrder->m_amount;
for( OrderIterator askIt = asks.begin(); askIt != asks.end(); askIt++ ) {
Order * other = *askIt;
if( other->m_ignored ) continue; // trying to execute this order did not go well in the past. Don't try again.
if( other->m_isMyOrder ) continue; // don't fill own orders
if( myOrder->m_matched.find( other->m_order_id ) != myOrder->m_matched.end() ) continue; // matched that already
if( myOrder->m_price < other->m_price ) break; // no need to try and find matches beyond
std::cerr << "Zero Reserve: Match at ask price " << other->m_price.toStdString() << std::endl;
myOrder->m_matched.insert( other->m_order_id );
if( amount > other->m_amount ) {
buy( other, myOrder, other->m_amount );
}
else {
buy( other, myOrder, amount );
return ZR::ZR_FINISH;
}
amount -= other->m_amount;
}
return ZR::ZR_SUCCESS;
}
示例2: textFile
ModList::OrderList ModList::readListFile()
{
OrderList itemList;
if (m_list_file.isNull() || m_list_file.isEmpty())
return itemList;
QFile textFile(m_list_file);
if (!textFile.open(QIODevice::ReadOnly | QIODevice::Text))
return OrderList();
QTextStream textStream;
textStream.setAutoDetectUnicode(true);
textStream.setDevice(&textFile);
while (true)
{
QString line = textStream.readLine();
if (line.isNull() || line.isEmpty())
break;
else
{
OrderItem it;
it.enabled = !line.endsWith(".disabled");
if (!it.enabled)
{
line.chop(9);
}
it.id = line;
itemList.append(it);
}
}
textFile.close();
return itemList;
}
示例3: getOrders
OrderList PgsqlDataProvider::getOrders(OrderType type, string methodName, uint32_t stockId)
{
OrderList orderList;
nontransaction command(*conn);
string query = "SELECT id, broker_id, stock_id, amount, price FROM " + methodName + "(" + to_string(stockId) + ");";
result queryResult(command.exec(query));
if (verbose)
cout << "Result of " << query << ": " << endl;
ResultIterator endIterator = queryResult.end();
for (ResultIterator iterator = queryResult.begin(); iterator != endIterator; ++iterator)
{
Order order;
order.setId(iterator[0].as<uint64_t>());
order.setType(type);
order.setBrokerId(iterator[1].as<uint32_t>());
order.setStockId(iterator[2].as<uint32_t>());
order.setAmount(iterator[3].as<uint32_t>());
order.setPrice(Decimal(iterator[4].as<string>()));
orderList.push_back(order);
}
if (verbose)
cout << orderList.size() << " orders. " << endl;
return orderList;
}
示例4: write
void JSONObject::write(std::ostream& str, WriteVisitor& visitor)
{
OrderList defaultOrder;
defaultOrder.push_back("UniqueID");
defaultOrder.push_back("Name");
defaultOrder.push_back("TargetName");
writeOrder(str, defaultOrder, visitor);
}
示例5: MoveBuoysToWaypoints
/**
* Perform all steps to upgrade from the old station buoys to the new version
* that uses waypoints. This includes some old saveload mechanics.
*/
void MoveBuoysToWaypoints()
{
/* Buoy orders become waypoint orders */
OrderList *ol;
FOR_ALL_ORDER_LISTS(ol) {
if (ol->GetFirstSharedVehicle()->type != VEH_SHIP) continue;
for (Order *o = ol->GetFirstOrder(); o != NULL; o = o->next) UpdateWaypointOrder(o);
}
Vehicle *v;
FOR_ALL_VEHICLES(v) {
if (v->type != VEH_SHIP) continue;
UpdateWaypointOrder(&v->current_order);
}
/* Now make the stations waypoints */
Station *st;
FOR_ALL_STATIONS(st) {
if ((st->had_vehicle_of_type & HVOT_WAYPOINT) == 0) continue;
StationID index = st->index;
TileIndex xy = st->xy;
Town *town = st->town;
StringID string_id = st->string_id;
char *name = st->name;
Date build_date = st->build_date;
/* Delete the station, so we can make it a real waypoint. */
delete st;
Waypoint *wp = new (index) Waypoint(xy);
wp->town = town;
wp->string_id = STR_SV_STNAME_BUOY;
wp->name = name;
wp->delete_ctr = 0; // Just reset delete counter for once.
wp->build_date = build_date;
wp->owner = OWNER_NONE;
if (IsInsideBS(string_id, STR_SV_STNAME_BUOY, 9)) wp->town_cn = string_id - STR_SV_STNAME_BUOY;
if (IsBuoyTile(xy) && GetStationIndex(xy) == index) {
wp->facilities |= FACIL_DOCK;
}
wp->rect.BeforeAddTile(xy, StationRect::ADD_FORCE);
}
}
示例6: matchesAt
UBool OrderList::matchesAt(int32_t offset, const OrderList &other) const
{
// NOTE: sizes include the NULLORDER, which we don't want to compare.
int32_t otherSize = other.size() - 1;
if (listSize - 1 - offset < otherSize) {
return FALSE;
}
for (int32_t i = offset, j = 0; j < otherSize; i += 1, j += 1) {
if (getOrder(i) != other.getOrder(j)) {
return FALSE;
}
}
return TRUE;
}
示例7: writeBackup
void Backup::writeBackup(OrderList &orders) {
std::string output;
for(int floor = 0; floor < N_FLOORS; ++floor){
if(orders.checkOrder(BUTTON_COMMAND, floor)) {
output += makeJSON(BUTTON_COMMAND, floor);
}
}
writeStringToFile(output);
}
示例8: matchOrders
void OrderMatcher::matchOrders(TradeList& tradeList, OrderList& buyList, OrderList& sellList, Decimal price)
{
if (verbose)
cout << endl << "Matching orders..." << endl;
if (buyList.size() == 0 || sellList.size() == 0)
return;
Order buyOrder = buyList.front();
Order sellOrder = sellList.front();
bool finished = false;
while (!finished && buyOrder.getPrice() >= price && sellOrder.getPrice() <= price)
{
uint32_t amount = std::min(buyOrder.getAmount(), sellOrder.getAmount());
Trade trade(amount, price, buyOrder, sellOrder);
tradeList.push_back(trade);
buyOrder.decreaseAmount(amount);
sellOrder.decreaseAmount(amount);
if (buyOrder.getAmount() == 0)
{
buyList.pop_front();
if (buyList.size() > 0)
buyOrder = buyList.front();
else
finished = true;
}
if (sellOrder.getAmount() == 0)
{
sellList.pop_front();
if (sellList.size() > 0)
sellOrder = sellList.front();
else
finished = true;
}
}
}
示例9: init
ZR::RetVal MyOrders::init()
{
try {
OrderList myorders;
ZrDB::Instance()->loadOrders( &myorders );
for( OrderIterator it = myorders.begin(); it != myorders.end(); it++) {
Order * order = *it;
addOrder( order );
if( order->m_orderType == Order::ASK ) {
m_asks->addOrder( order );
}
else {
m_bids->addOrder( order );
}
}
}
catch( std::runtime_error & e ) {
g_ZeroReservePlugin->placeMsg( std::string( "Exception caught: " ) + e.what() );
return ZR::ZR_FAILURE;
}
return ZR::ZR_SUCCESS;
}
示例10: ARRAY_SIZE
void SSearchTest::offsetTest()
{
const char *test[] = {
// The sequence \u0FB3\u0F71\u0F71\u0F80 contains a discontiguous
// contraction (\u0FB3\u0F71\u0F80) logically followed by \u0F71.
"\\u1E33\\u0FB3\\u0F71\\u0F71\\u0F80\\uD835\\uDF6C\\u01B0",
"\\ua191\\u16ef\\u2036\\u017a",
#if 0
// This results in a complex interaction between contraction,
// expansion and normalization that confuses the backwards offset fixups.
"\\u0F7F\\u0F80\\u0F81\\u0F82\\u0F83\\u0F84\\u0F85",
#endif
"\\u0F80\\u0F81\\u0F82\\u0F83\\u0F84\\u0F85",
"\\u07E9\\u07EA\\u07F1\\u07F2\\u07F3",
"\\u02FE\\u02FF"
"\\u0300\\u0301\\u0302\\u0303\\u0304\\u0305\\u0306\\u0307\\u0308\\u0309\\u030A\\u030B\\u030C\\u030D\\u030E\\u030F"
"\\u0310\\u0311\\u0312\\u0313\\u0314\\u0315\\u0316\\u0317\\u0318\\u0319\\u031A\\u031B\\u031C\\u031D\\u031E\\u031F"
"\\u0320\\u0321\\u0322\\u0323\\u0324\\u0325\\u0326\\u0327\\u0328\\u0329\\u032A\\u032B\\u032C\\u032D\\u032E\\u032F"
"\\u0330\\u0331\\u0332\\u0333\\u0334\\u0335\\u0336\\u0337\\u0338\\u0339\\u033A\\u033B\\u033C\\u033D\\u033E\\u033F"
"\\u0340\\u0341\\u0342\\u0343\\u0344\\u0345\\u0346\\u0347\\u0348\\u0349\\u034A\\u034B\\u034C\\u034D\\u034E", // currently not working, see #8081
"\\u02FE\\u02FF\\u0300\\u0301\\u0302\\u0303\\u0316\\u0317\\u0318", // currently not working, see #8081
"a\\u02FF\\u0301\\u0316", // currently not working, see #8081
"a\\u02FF\\u0316\\u0301",
"a\\u0430\\u0301\\u0316",
"a\\u0430\\u0316\\u0301",
"abc\\u0E41\\u0301\\u0316",
"abc\\u0E41\\u0316\\u0301",
"\\u0E41\\u0301\\u0316",
"\\u0E41\\u0316\\u0301",
"a\\u0301\\u0316",
"a\\u0316\\u0301",
"\\uAC52\\uAC53",
"\\u34CA\\u34CB",
"\\u11ED\\u11EE",
"\\u30C3\\u30D0",
"p\\u00E9ch\\u00E9",
"a\\u0301\\u0325",
"a\\u0300\\u0325",
"a\\u0325\\u0300",
"A\\u0323\\u0300B",
"A\\u0300\\u0323B",
"A\\u0301\\u0323B",
"A\\u0302\\u0301\\u0323B",
"abc",
"ab\\u0300c",
"ab\\u0300\\u0323c",
" \\uD800\\uDC00\\uDC00",
"a\\uD800\\uDC00\\uDC00",
"A\\u0301\\u0301",
"A\\u0301\\u0323",
"A\\u0301\\u0323B",
"B\\u0301\\u0323C",
"A\\u0300\\u0323B",
"\\u0301A\\u0301\\u0301",
"abcd\\r\\u0301",
"p\\u00EAche",
"pe\\u0302che",
};
int32_t testCount = ARRAY_SIZE(test);
UErrorCode status = U_ZERO_ERROR;
RuleBasedCollator *col = (RuleBasedCollator *) Collator::createInstance(Locale::getEnglish(), status);
if (U_FAILURE(status)) {
errcheckln(status, "Failed to create collator in offsetTest! - %s", u_errorName(status));
return;
}
char buffer[4096]; // A bit of a hack... just happens to be long enough for all the test cases...
// We could allocate one that's the right size by (CE_count * 10) + 2
// 10 chars is enough room for 8 hex digits plus ", ". 2 extra chars for "[" and "]"
col->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status);
for(int32_t i = 0; i < testCount; i += 1) {
if (i>=4 && i<=6 && logKnownIssue("9156", "was 8081")) {
continue; // timebomb until ticket #9156 (was #8081) is resolved
}
UnicodeString ts = CharsToUnicodeString(test[i]);
CollationElementIterator *iter = col->createCollationElementIterator(ts);
OrderList forwardList;
OrderList backwardList;
int32_t order, low, high;
do {
low = iter->getOffset();
order = iter->next(status);
high = iter->getOffset();
forwardList.add(order, low, high);
} while (order != CollationElementIterator::NULLORDER);
iter->reset();
iter->setOffset(ts.length(), status);
backwardList.add(CollationElementIterator::NULLORDER, iter->getOffset(), iter->getOffset());
//.........这里部分代码省略.........
示例11: MoveBuoysToWaypoints
/**
* Perform all steps to upgrade from the old station buoys to the new version
* that uses waypoints. This includes some old saveload mechanics.
*/
void MoveBuoysToWaypoints()
{
/* Buoy orders become waypoint orders */
OrderList *ol;
FOR_ALL_ORDER_LISTS(ol) {
VehicleType vt = ol->GetFirstSharedVehicle()->type;
if (vt != VEH_SHIP && vt != VEH_TRAIN) continue;
for (Order *o = ol->GetFirstOrder(); o != NULL; o = o->next) UpdateWaypointOrder(o);
}
Vehicle *v;
FOR_ALL_VEHICLES(v) {
VehicleType vt = v->type;
if (vt != VEH_SHIP && vt != VEH_TRAIN) continue;
UpdateWaypointOrder(&v->current_order);
}
/* Now make the stations waypoints */
Station *st;
FOR_ALL_STATIONS(st) {
if ((st->had_vehicle_of_type & HVOT_WAYPOINT) == 0) continue;
StationID index = st->index;
TileIndex xy = st->xy;
Town *town = st->town;
StringID string_id = st->string_id;
char *name = st->name;
st->name = NULL;
Date build_date = st->build_date;
/* TTDPatch could use "buoys with rail station" for rail waypoints */
bool train = st->train_station.tile != INVALID_TILE;
TileArea train_st = st->train_station;
/* Delete the station, so we can make it a real waypoint. */
delete st;
/* Stations and waypoints are in the same pool, so if a station
* is deleted there must be place for a Waypoint. */
assert(Waypoint::CanAllocateItem());
Waypoint *wp = new (index) Waypoint(xy);
wp->town = town;
wp->string_id = train ? STR_SV_STNAME_WAYPOINT : STR_SV_STNAME_BUOY;
wp->name = name;
wp->delete_ctr = 0; // Just reset delete counter for once.
wp->build_date = build_date;
wp->owner = train ? GetTileOwner(xy) : OWNER_NONE;
if (IsInsideBS(string_id, STR_SV_STNAME_BUOY, 9)) wp->town_cn = string_id - STR_SV_STNAME_BUOY;
if (train) {
/* When we make a rail waypoint of the station, convert the map as well. */
TILE_AREA_LOOP(t, train_st) {
if (!IsTileType(t, MP_STATION) || GetStationIndex(t) != index) continue;
SB(_me[t].m6, 3, 3, STATION_WAYPOINT);
wp->rect.BeforeAddTile(t, StationRect::ADD_FORCE);
}
wp->train_station = train_st;
wp->facilities |= FACIL_TRAIN;
} else if (IsBuoyTile(xy) && GetStationIndex(xy) == index) {
wp->rect.BeforeAddTile(xy, StationRect::ADD_FORCE);
wp->facilities |= FACIL_DOCK;
}
}
示例12: MoveWaypointsToBaseStations
/**
* Perform all steps to upgrade from the old waypoints to the new version
* that uses station. This includes some old saveload mechanics.
*/
void MoveWaypointsToBaseStations()
{
/* In version 17, ground type is moved from m2 to m4 for depots and
* waypoints to make way for storing the index in m2. The custom graphics
* id which was stored in m4 is now saved as a grf/id reference in the
* waypoint struct. */
if (IsSavegameVersionBefore(17)) {
for (OldWaypoint *wp = _old_waypoints.Begin(); wp != _old_waypoints.End(); wp++) {
if (wp->delete_ctr != 0) continue; // The waypoint was deleted
/* Waypoint indices were not added to the map prior to this. */
_m[wp->xy].m2 = (StationID)wp->index;
if (HasBit(_m[wp->xy].m3, 4)) {
wp->spec = StationClass::Get(STAT_CLASS_WAYP, _m[wp->xy].m4 + 1);
}
}
} else {
/* As of version 17, we recalculate the custom graphic ID of waypoints
* from the GRF ID / station index. */
for (OldWaypoint *wp = _old_waypoints.Begin(); wp != _old_waypoints.End(); wp++) {
for (uint i = 0; i < StationClass::GetCount(STAT_CLASS_WAYP); i++) {
const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP, i);
if (statspec != NULL && statspec->grf_prop.grffile->grfid == wp->grfid && statspec->grf_prop.local_id == wp->localidx) {
wp->spec = statspec;
break;
}
}
}
}
if (!Waypoint::CanAllocateItem(_old_waypoints.Length())) SlError(STR_ERROR_TOO_MANY_STATIONS_LOADING);
/* All saveload conversions have been done. Create the new waypoints! */
for (OldWaypoint *wp = _old_waypoints.Begin(); wp != _old_waypoints.End(); wp++) {
Waypoint *new_wp = new Waypoint(wp->xy);
new_wp->town = wp->town;
new_wp->town_cn = wp->town_cn;
new_wp->name = wp->name;
new_wp->delete_ctr = 0; // Just reset delete counter for once.
new_wp->build_date = wp->build_date;
new_wp->owner = wp->owner;
new_wp->string_id = STR_SV_STNAME_WAYPOINT;
TileIndex t = wp->xy;
if (IsTileType(t, MP_RAILWAY) && GetRailTileType(t) == 2 /* RAIL_TILE_WAYPOINT */ && _m[t].m2 == wp->index) {
/* The tile might've been reserved! */
bool reserved = !IsSavegameVersionBefore(100) && HasBit(_m[t].m5, 4);
/* The tile really has our waypoint, so reassign the map array */
MakeRailWaypoint(t, GetTileOwner(t), new_wp->index, (Axis)GB(_m[t].m5, 0, 1), 0, GetRailType(t));
new_wp->facilities |= FACIL_TRAIN;
new_wp->owner = GetTileOwner(t);
SetRailStationReservation(t, reserved);
if (wp->spec != NULL) {
SetCustomStationSpecIndex(t, AllocateSpecToStation(wp->spec, new_wp, true));
}
new_wp->rect.BeforeAddTile(t, StationRect::ADD_FORCE);
}
wp->new_index = new_wp->index;
}
/* Update the orders of vehicles */
OrderList *ol;
FOR_ALL_ORDER_LISTS(ol) {
if (ol->GetFirstSharedVehicle()->type != VEH_TRAIN) continue;
for (Order *o = ol->GetFirstOrder(); o != NULL; o = o->next) UpdateWaypointOrder(o);
}
Vehicle *v;
FOR_ALL_VEHICLES(v) {
if (v->type != VEH_TRAIN) continue;
UpdateWaypointOrder(&v->current_order);
}
_old_waypoints.Reset();
}
示例13: Fixture
Fixture() :
msg1(1, "msg1", "content1"),
clientSetup("localhost", "2222"),
serverSetup("2222"),
clientChannel(boost::make_shared<TCPClient>(clientSetup)),
serverChannel(boost::make_shared<TCPServer>(serverSetup)),
orderReceive(boost::make_shared<ReceiveOrder>(1, 250)),
orderSend(boost::make_shared<SendOrder>(msg1)),
orderWait(boost::make_shared<WaitOrder>(50))
{
ordersClient.Add(orderReceive);
ordersServer.Add(orderWait);
ordersServer.Add(orderSend);
behaviourClient = boost::make_shared<DeviceBehaviour>("Test Behaviour", clientChannel, ordersClient);
behaviourServer = boost::make_shared<DeviceBehaviour>("Test Behaviour2", serverChannel, ordersServer);
};