1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/foreach.hpp>
#include <string>
#include <set>
#include <exception>
#include <iostream>
using namespace std;
class Order{
protected:
string m_StationName,m_Expires, m_ReportedTime, m_OrderID;
int m_Region, m_Station, m_Security, m_Range, m_Price, m_VolRemain, m_MinVolume;
public:
//constructor
Order(string orderID, string stationName, string expires,string reported, int region, int station,int security, int range, int price, int volremain, int minvolume){
m_OrderID = orderID;
m_StationName = stationName;
m_Expires = expires;
m_ReportedTime = reported;
m_Region = region;
m_Station = station;
m_Security = security;
m_Range = range;
m_Price = price;
m_VolRemain = volremain;
m_MinVolume = minvolume;
}
bool operator< ( const Order& that ) const { return m_OrderID < that.m_OrderID ; }
string getStationName(){return m_StationName;};
string getExpires(){return m_Expires;};
string getReportedTime(){return m_ReportedTime;};
int getRegion(){return m_Region;};
int getStation(){return m_Station;};
int getSecurity(){return m_Security;};
int getRange(){return m_Range;};
int getPrice(){return m_Price;};
int getVolRemain(){return m_VolRemain;};
int getMinVolume(){return m_MinVolume;};
};
class MarketItem{
protected:
int m_ItemID, m_Hours, m_Minqty;
string m_ItemName;
//unigue Order IDs
std::set<Order> m_SellOrders, m_BuyOrders;
public:
//get the data from the XML parser and extract the data
void load(int, string);
int getItemID(){return m_ItemID;};
int getHours(){return m_Hours;};
int getMinqty(){return m_Minqty;};
string getItemName(){return m_ItemName;};
//they don't need to change thereof const &
const std::set<Order>& getSellOrders(){const std::set<Order>& temp = m_SellOrders; return temp;};
const std::set<Order>& getBuyOrders(){const std::set<Order>& temp = m_BuyOrders; return temp;};
};
void MarketItem::load(int itemID, string filename){
using boost::property_tree::ptree;
ptree pt;
read_xml(filename , pt);
//load all the values
m_ItemID = pt.get<int>("quicklook.item");
m_ItemName = pt.get<std::string>("quicklook.itemname");
m_Hours = pt.get<int>("quicklook.hours");
m_Minqty = pt.get<int>("quicklook.minqty");
BOOST_FOREACH(ptree::value_type const& v, pt.get_child("quicklook.sell_orders")){
if(v.first == "order"){
m_SellOrders.insert(Order(v.second.get<std::string>("<xmlattr.id>"), v.second.get<std::string>("station"), v.second.get<std::string>("expires"), v.second.get<std::string>("reported_time"),
v.second.get<int>("region"), v.second.get<int>("station"), v.second.get<int>("security"), v.second.get<int>("range"), v.second.get<int>("price"),
v.second.get<int>("vol_remain"), v.second.get<int>("min_volume")));
}
}
}
|