本文整理汇总了C++中Transaction类的典型用法代码示例。如果您正苦于以下问题:C++ Transaction类的具体用法?C++ Transaction怎么用?C++ Transaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Transaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: gen_rules
// Generate Transactions
//
void gen_rules(TransPar &par)
{
StringSet *lits;
StringSetIter *patterns;
Transaction *trans;
poisson_distribution<LINT> tlen(par.tlen - 1);
ofstream data_fp;
ofstream pat_fp;
data_fp.open(data_file, ios::trunc);
pat_fp.open(pat_file, ios::trunc);
lits = new StringSet(par.nitems, par.lits);
// Reset random seed generator before generating transactions
if (par.seed < 0) generator.seed(par.seed);
par.write(pat_fp);
lits->display(pat_fp);
patterns = new StringSetIter(*lits);
for (LINT i = 0; i < par.ntrans; i ++)
{
trans = mk_tran(*patterns, tlen(generator) + 1);
if (par.ascii)
trans->write_asc(data_fp);
else
trans->write(data_fp);
delete trans;
}
data_fp.close();
pat_fp.close();
}
示例2: buildQueue
bool TransactionQueue::buildQueue(ifstream& transFile) {
// temporary members to store input for processing
char act;
int a1, a1t, a2, a2t, amt, tmp;
a1 = a1t = a2 = a2t = amt = tmp = 0;
transFile >> act;
//loop through file
for (;;) {
// get action indicator first to guide action
//cout << act << "|";
// test if valid action, otherwise abort for this line
if (act == 'D' || act == 'W' || act == 'M' || act == 'H') {
transFile >> tmp;
//cout << tmp << "|";
if (act == 'H') { // for History, store acct#/type & done
a1 = tmp;
} else { // all others need at least a first
a1 = tmp / 10; // acct#, acct type, and amount
a1t = tmp % 10;
transFile >> amt;
if (act == 'M') { // finally, if Move get second
transFile >> tmp; // acct# and acct type
a2 = tmp / 10;
a2t = tmp % 10;
}
}
// build object and enqueue, then move on to next line
Transaction* t = new Transaction;
t->setData(act, a1, a1t, a2, a2t, amt);
transQueue.push_back(t);
a1 = a1t = a2 = a2t = amt = tmp = 0;
} else {
示例3: Transfer
void Bank::Transfer(const Transaction& tr)
{
Account info;
Account* from = NULL;
Account* to = NULL;
string acc = tr.GetAccount();
string num = acc.substr(0, acc.length() - 1);
info.SetNumber(num);
if (!tree.Retrieve(info, from))
{
cerr << "ERROR: Account " << num
<< " not found. Transferal refused." << endl;
return;
}
string acc2 = tr.GetAccount2();
string num2 = acc2.substr(0, acc2.length() - 1);
info.SetNumber(num2);
if (!tree.Retrieve(info, to))
{
cerr << "ERROR: Account " << num2
<< " not found. Transferal refused." << endl;
return;
}
if (from->Transfer(tr, true))
{
to->Transfer(tr, false);
}
}
示例4: s3fs_chown
int s3fs_chown(const char *path, uid_t uid, gid_t gid) {
#ifdef DEBUG
syslog(LOG_INFO, "chown[%s] uid[%d] gid[%d]", path, uid, gid);
#endif
try {
Transaction t;
t.getExisting(path);
// uid or gid < 0 indicates no change
if ((int) uid >= 0 && t.file->info->uid != uid) {
t.file->info->uid = uid;
t.file->dirty_metadata = true;
}
if ((int) gid >= 0 && t.file->info->gid != gid) {
t.file->info->gid = gid;
t.file->dirty_metadata = true;
}
return 0;
} catch (int e) {
syslog(LOG_INFO, "chown[%s]: %s", path, strerror(e));
return e;
}
}
示例5: fromAccount
void Transact::on_debug_clicked()
{
// Secret s = findSecret(value() + fee());
Address from = fromAccount();
auto b = ethereum()->balanceAt(from, PendingBlock);
if (!from || b < value() + fee())
{
QMessageBox::critical(this, "Transaction Failed", "Couldn't make transaction: account doesn't contain at least the required amount.");
return;
}
try
{
Block postState(ethereum()->postState());
Transaction t = isCreation() ?
Transaction(value(), gasPrice(), gas(), m_data, postState.transactionsFrom(from)) :
Transaction(value(), gasPrice(), gas(), toAccount().first, m_data, postState.transactionsFrom(from));
t.forceSender(from);
Debugger dw(m_main, this);
Executive e(postState, ethereum()->blockChain(), 0);
dw.populate(e, t);
dw.exec();
}
catch (dev::Exception const& _e)
{
QMessageBox::critical(this, "Transaction Failed", "Couldn't make transaction. Low-level error: " + QString::fromStdString(diagnostic_information(_e)));
// this output is aimed at developers, reconsider using _e.what for more user friendly output.
}
}
示例6: replaceGas
void MixClient::executeTransaction(Transaction const& _t, Block& _block, bool _call, bool _gasAuto, Secret const& _secret)
{
Transaction t = _gasAuto ? replaceGas(_t, m_postMine.gasLimitRemaining()) : _t;
// do debugging run first
EnvInfo envInfo(bc().info(), bc().lastHashes());
ExecutionResult d = debugTransaction(t, _block.state(), envInfo, _call);
// execute on a state
if (!_call)
{
t = _gasAuto ? replaceGas(_t, d.gasUsed, _secret) : _t;
eth::ExecutionResult const& er = _block.execute(envInfo.lastHashes(), t);
if (t.isCreation() && _block.state().code(d.contractAddress).empty())
BOOST_THROW_EXCEPTION(OutOfGas() << errinfo_comment("Not enough gas for contract deployment"));
d.gasUsed = er.gasUsed + er.gasRefunded + er.gasForDeposit + c_callStipend;
LocalisedLogEntries logs;
TransactionReceipt const& tr = _block.receipt(_block.pending().size() - 1);
LogEntries le = tr.log();
if (le.size())
for (unsigned j = 0; j < le.size(); ++j)
logs.insert(logs.begin(), LocalisedLogEntry(le[j]));
d.logs = logs;
}
WriteGuard l(x_executions);
m_executions.emplace_back(std::move(d));
}
示例7: s3fs_rmdir
int s3fs_rmdir(const char *path) {
#ifdef DEBUG
syslog(LOG_INFO, "rmdir[%s]", path);
#endif
try {
Transaction t;
t.getExisting(path);
// sync any deleted files inside this directory
Filecache::sync();
// make sure the directory is empty
std::string marker;
stringlist entries;
S3request::get_directory(path, marker, entries, 1);
if (entries.size() > 0)
throw -ENOTEMPTY;
t.file->deleted = true;
return 0;
} catch (int e) {
syslog(LOG_INFO, "rmdir[%s]: %s", path, strerror(e));
return e;
}
}
示例8: Transaction
// Generate a transaction
//
Transaction *mk_tran(StringSetIter &lits, // table of patterns
LINT tlen, // transaction length
LINT NPATS, Taxonomy *tax)
{
Transaction *trans;
StringP pat;
if (tlen > Transaction::MAXNITEMS)
tlen = Transaction::MAXNITEMS; //MJZ: can't exceed nitems
trans = new Transaction(tlen);
LINT patcnt = 0; //MJZ
while (trans->size() < tlen && patcnt < NPATS)
{
patcnt++;
//cout << trans->size() << " " << tlen << " HERE2\n";
pat = lits.get_pat(); // get a pattern
if (!trans->add(*pat))
{
// this pattern didn't fit in the transaction
lits.unget_pat();
break;
}
}
return trans;
}
示例9: apply
bool Manager::apply()
{
Transaction *tx = m_reapack->setupTransaction();
if(!tx)
return false;
if(m_autoInstall)
m_config->install()->autoInstall = m_autoInstall.value();
if(m_bleedingEdge)
m_config->install()->bleedingEdge = m_bleedingEdge.value();
for(const auto &pair : m_enableOverrides) {
const Remote &remote = pair.first;
const bool enable = pair.second;
if(m_uninstall.find(remote) == m_uninstall.end())
m_reapack->setRemoteEnabled(enable, remote);
}
for(const Remote &remote : m_uninstall)
m_reapack->uninstall(remote);
tx->runTasks();
m_config->write();
reset();
return true;
}
示例10: TEST_F
TEST_F(TestStream, Simple)
{
Connection c = Connection::create(m_engine);
Transaction tx = Transaction::create(c);
ib_stream_pump_t *pump;
ASSERT_EQ(IB_OK,
ib_stream_pump_create(&pump, m_reg, tx.ib())
);
ASSERT_EQ(IB_OK,
ib_stream_pump_processor_add(pump, "inflate")
);
ASSERT_EQ(IB_OK,
ib_stream_pump_processor_add(pump, "collector")
);
ASSERT_EQ(IB_OK,
ib_stream_pump_flush(pump)
);
ASSERT_EQ(IB_OK,
ib_stream_pump_process(pump, compressed_data, 3)
);
ASSERT_EQ(IB_OK,
ib_stream_pump_process(pump,
compressed_data + 3,
compressed_data_len - 3)
);
ASSERT_EQ(IB_OK,
ib_stream_pump_flush(pump)
);
ASSERT_EQ(0,
m_collector.compare(0, std::string::npos,
reinterpret_cast<const char*>(uncompressed_data),
uncompressed_data_len));
}
示例11: get_user_index_table
uid_t YChatDB::addUser(const string& username, const string& password) {
Storage* uind_store = get_user_index_table();
Storage* user_store = get_user_table();
if (uind_store == NULL || user_store == NULL) return 0;
Transaction txn;
uid_t uid = 0;
try {
if (!inc_and_get_curr_max_uid(uind_store, txn, uid)) {
txn.abort();
return 0;
}
OctetsStream key, value;
key << username, value << password << uid;
uind_store->insert(key, value, txn);
User user(uid, username);
OctetsStream key2, value2;
key2 << uid, value2 << user.toString();
user_store->insert(key2, value2, txn);
} catch (...) {
txn.abort();
return 0;
}
return uid;
}
示例12: process_commit
void
process_commit() {
/*
Loop through all the maps and add to new map in each transaction.
Once that is done, what we have is the new final transaction.
Erase trans_stack and add this new final transaction as tid 0
*/
vector<Transaction*>::iterator t_stack_it;
map<string, int> tr_start_varMap;
map<int,int> tr_start_valMap;
Transaction *t = new Transaction(0);
Transaction* tr_start;
for (t_stack_it = trans_stack.begin(); t_stack_it != trans_stack.end(); ++t_stack_it) {
tr_start = *t_stack_it;
// get all varMap and valMapentries from tr_start to t
tr_start_varMap = tr_start->get_varMap();
//tr_start_valMap = tr_start->get_valMap();
t->populate_vmaps(tr_start_varMap);
//clear the copy buffers
tr_start_valMap.erase(tr_start_valMap.begin(), tr_start_valMap.end());
tr_start_varMap.erase(tr_start_varMap.begin(), tr_start_varMap.end());
}
trans_stack.erase(trans_stack.begin(), trans_stack.end());
trans_stack.push_back(t);
}
示例13: while
void TransactionHandler::work()
{
//std::lock_guard<std::mutex> guard(m);
//m.lock();
int i = 0;
while (!mQueue.empty())
{
//m.unlock();
//m.lock();
Transaction* t = mQueue.front();
mQueue.pop();
//m.unlock();
t->call();
//m1.lock();
//std::cout << std::this_thread::get_id() << ": " << i << std::endl;
//m1.unlock();
i++;
}
//delete t;
//m1.lock();
//std::cout << "I am " << std::this_thread::get_id() << " and I did " << i << " transactions. " << std::endl;
//m1.unlock();
}
示例14: assert
void AspEventHandler::report_topsortedtx() {
char buff[256];
assert(ASP_ROOT != NULL);
sprintf(buff, "%s/asp/analysis/work/%s/%s", ASP_ROOT, test_name_, TRACE_FILE);
FILE* trace_file = fopen(buff, "w");
if(!trace_file) {
printf("Error in opening the trace file /tmp/trace.txt !");
exit(-1);
}
for(TransactionPtrList::iterator itr = txlist_sorted_.begin(); itr != txlist_sorted_.end(); ++itr) {
Transaction* tx = (*itr);
fprintf(report_file_, "%s\n", TXID_ToString(tx->txid()).c_str());
// write to Richard's trace file format
AccessBasePtrList* accesses = tx->accesses();
for(AccessBasePtrList::iterator iter = accesses->begin(); iter < accesses->end(); ++iter) {
AccessBase* access = (*iter);
if(access->is_array() && access->is_write()) {
fprintf(trace_file, "_asp_log_write(%s, %d, %s, %.4f)\n",
access->base_name(), access->offset(), "_my_in_img", access->double_value());
}
}
}
fclose(trace_file);
}
示例15: s3fs_getattr
int s3fs_getattr(const char *path, struct stat *stbuf) {
#ifdef DEBUG
syslog(LOG_INFO, "getattr[%s]", path);
#endif
try {
Transaction t;
t.getExisting(path);
if (t.file->deleted)
throw -ENOENT;
t.file->info->toStat(stbuf);
return 0;
} catch (int e) {
if (e == -ENOENT) {
// getattr is used to check if a file exists, so
// getting a File Not Found error is nothing to worry about
#ifdef DEBUG
syslog(LOG_INFO, "getattr[%s]: File not found", path);
#endif
} else {
syslog(LOG_INFO, "getattr[%s]: %s", path, strerror(e));
}
return e;
}
}