2011-11-08 17:06:32 -05:00
|
|
|
#ifndef _POS_DB_H_
|
|
|
|
#define _POS_DB_H_
|
|
|
|
#include "sha1.h"
|
|
|
|
#include "log.h"
|
2011-11-08 20:38:06 -05:00
|
|
|
#include "nameserver.h"
|
2011-11-08 17:06:32 -05:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
class PosDb {
|
|
|
|
public:
|
|
|
|
PosDb(const char * fn);
|
|
|
|
uint32_t getAccountFromHash(const SHA1Hash & hash);
|
|
|
|
std::list<std::string> getHashesFromAccount(uint32_t account);
|
2011-11-08 20:38:06 -05:00
|
|
|
std::list<std::string> getHashesFromAccount(std::string account);
|
2011-11-08 17:06:32 -05:00
|
|
|
|
|
|
|
int32_t getAccountBalance(const SHA1Hash & hash);
|
|
|
|
int32_t getAccountBalance(uint32_t account);
|
2011-11-08 20:38:06 -05:00
|
|
|
int32_t getAccountBalance(std::string account);
|
2011-11-08 17:06:32 -05:00
|
|
|
|
|
|
|
uint64_t associateHash(const SHA1Hash & hash, uint32_t account);
|
2011-11-08 20:38:06 -05:00
|
|
|
uint64_t associateHash(const SHA1Hash & hash, std::string account);
|
2011-11-08 17:06:32 -05:00
|
|
|
uint64_t deassociateHash(const SHA1Hash & hash);
|
|
|
|
|
2011-11-10 15:17:17 -05:00
|
|
|
int32_t getUPCPrice(UPC upc);
|
|
|
|
uint64_t setUPCPrice(UPC upc, int32_t price);
|
|
|
|
|
2011-11-08 17:06:32 -05:00
|
|
|
uint64_t doTransaction(const SHA1Hash & hash, int32_t delta);
|
2011-11-08 20:38:06 -05:00
|
|
|
uint64_t doTransaction(const uint32_t account, int32_t delta);
|
|
|
|
uint64_t doTransaction(std::string account, int32_t delta);
|
2011-11-08 17:06:32 -05:00
|
|
|
uint64_t revertTransaction(uint64_t serial);
|
|
|
|
|
|
|
|
int32_t getStock(UPC upc);
|
|
|
|
uint64_t doStockChange(UPC upc, int32_t delta);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void acceptLogEntry(const LogEntry & l);
|
|
|
|
|
2011-11-08 20:38:06 -05:00
|
|
|
std::multimap<uint32_t, SHA1Hash> account_to_hash;
|
2011-11-08 17:06:32 -05:00
|
|
|
std::map<uint32_t, int32_t> account_to_balance;
|
|
|
|
|
|
|
|
std::map<UPC, int32_t, UPCLess> upc_to_stock;
|
2011-11-10 15:17:17 -05:00
|
|
|
std::map<UPC, int32_t, UPCLess> upc_to_price;
|
2011-11-08 17:06:32 -05:00
|
|
|
|
2011-11-08 20:38:06 -05:00
|
|
|
std::map<uint64_t, LogEntry> serial_to_object;
|
2011-11-08 17:06:32 -05:00
|
|
|
|
|
|
|
Log log;
|
2011-11-08 20:38:06 -05:00
|
|
|
NameServer ns;
|
2011-11-08 17:06:32 -05:00
|
|
|
};
|
|
|
|
|
2011-11-08 20:38:06 -05:00
|
|
|
typedef std::multimap<uint32_t, SHA1Hash>::iterator ath_it;
|
|
|
|
typedef std::map<uint32_t, int32_t>::iterator atb_it;
|
|
|
|
typedef std::map<UPC, int32_t, UPCLess>::iterator uts_it;
|
|
|
|
typedef std::map<uint64_t, LogEntry>::iterator sto_it;
|
|
|
|
typedef std::pair<ath_it, ath_it> ath_it_r;
|
|
|
|
|
2011-11-08 17:06:32 -05:00
|
|
|
#endif
|
|
|
|
|