本文整理汇总了C++中Tuple类的典型用法代码示例。如果您正苦于以下问题:C++ Tuple类的具体用法?C++ Tuple怎么用?C++ Tuple使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tuple类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: iterator
void SipPresenceMonitor::publishContent(UtlString& contact, SipPresenceEvent* presenceEvent)
{
bool contentChanged;
// Loop through all the resource lists
UtlHashMapIterator iterator(mMonitoredLists);
UtlString* listUri;
SipResourceList* list;
Resource* resource;
UtlString id, state;
while (listUri = dynamic_cast <UtlString *> (iterator()))
{
contentChanged = false;
list = dynamic_cast <SipResourceList *> (mMonitoredLists.findValue(listUri));
OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipPresenceMonitor::publishContent listUri %s list %p",
listUri->data(), list);
// Search for the contact in this list
resource = list->getResource(contact);
if (resource)
{
resource->getInstance(id, state);
if (presenceEvent->isEmpty())
{
resource->setInstance(id, STATE_TERMINATED);
}
else
{
UtlString id;
NetMd5Codec::encode(contact, id);
Tuple* tuple = presenceEvent->getTuple(id);
UtlString status;
tuple->getStatus(status);
if (status.compareTo(STATUS_CLOSE) == 0)
{
resource->setInstance(id, STATE_TERMINATED);
}
else
{
resource->setInstance(id, STATE_ACTIVE);
}
}
list->buildBody();
contentChanged = true;
}
if (contentChanged)
{
int numOldContents;
HttpBody* oldContent[1];
// Publish the content to the subscribe server
if (!mSipPublishContentMgr.publish(listUri->data(), PRESENCE_EVENT_TYPE, DIALOG_EVENT_TYPE, 1, (HttpBody**)&list, 1, numOldContents, oldContent))
{
UtlString presenceContent;
int length;
list->getBytes(&presenceContent, &length);
OsSysLog::add(FAC_SIP, PRI_ERR, "SipPresenceMonitor::publishContent PresenceEvent %s\n was not successfully published to the subscribe server",
presenceContent.data());
}
}
}
}
示例2: test_fields_prim
void test_fields_prim() {
Tuple* tuple = new_tuple();
TS_ASSERT_EQUALS(Fixnum::from(3), as<Fixnum>(tuple->fields_prim(state)));
}
示例3: s
ModEvent CPTupleVarImp::assign(Space& home, const Tuple& t) {
TupleSet s(t.arity());
s.add(t);
return exclude(home,s.complement());
}
示例4: test_copy_from_to_empty_this
void test_copy_from_to_empty_this() {
Tuple* tuple = new_tuple();
Tuple* dest = Tuple::create(state, 0);
dest->copy_from(state, tuple, Fixnum::from(0), Fixnum::from(0), Fixnum::from(0));
}
示例5: test_at_prim
void test_at_prim() {
Tuple* tuple = new_tuple();
TS_ASSERT_EQUALS(Fixnum::from(4), as<Fixnum>(tuple->at_prim(state, Fixnum::from(1))));
TS_ASSERT_THROWS_ASSERT(tuple->at_prim(state, Fixnum::from(4)), const RubyException &e,
TS_ASSERT(Exception::object_bounds_exceeded_error_p(state, e.exception)));
}
示例6:
inline bool operator==(const Tuple &l, const tOther &r)
{
return l.equal(r);
}
示例7: mov
// There is no subtlety here: mov just sets velocity directly
void SimpleDynamics::mov(Tuple v) {
flo x = v[0].asNumber();
flo y = v[1].asNumber();
flo z = v.size() > 2 ? v[2].asNumber() : 0;
device->body->set_velocity(x,y,z);
}
示例8: string
bool Tuple_Comparison::operator()(Tuple& tuple1, Tuple& tuple2)
{
if(tuple1.isNull() && tuple2.isNull())
return false;
if((!tuple1.isNull()) && tuple2.isNull())
return true;
if(tuple1.isNull() && (!tuple2.isNull()))
return false;
vector<string>::iterator start = field_names.begin();
vector<string>::iterator stop = field_names.end();
vector<string>::iterator index;
Schema schema_tuple1 = tuple1.getSchema();
Schema schema_tuple2 = tuple2.getSchema();
// cout<< "comparing "<<tuple1<<" "<<tuple2<<endl;
if(schema_tuple1 != schema_tuple2)
throw string("Error!! Tuple comparison failed - Tuple_Comparison::operator()");
for(index = start; index!=stop; index++)
{
string column_name = *index;
FIELD_TYPE field_type = schema_tuple1.getFieldType(column_name);
if(field_type == INT)
{
int value1, value2;
value1 = tuple1.getField(column_name).integer;
value2 = tuple2.getField(column_name).integer;
if(value1 != value2)
return value1<value2;
}
else //FIELD_TYPE == STR20
{
string value1, value2;
value1 = *(tuple1.getField(column_name).str);
value2 = *(tuple2.getField(column_name).str);
if(value1.compare(value2) < 0) return true;
else if(value1.compare(value2) > 0) return false;
}
}
return false;
}
示例9: throw
void SimulatorAtom::retrieve(const Query& query, Answer& answer) throw (PluginError){
RegistryPtr reg = query.interpretation->getRegistry();
const Tuple& params = query.input;
// get ASP filename
std::string programpath = reg->terms.getByID(params[0]).getUnquotedString();
// if we access this file for the first time, parse the content
if (programs.find(programpath) == programs.end()){
DBGLOG(DBG, "Parsing simulation program");
InputProviderPtr ip(new InputProvider());
ip->addFileInput(programpath);
Logger::Levels l = Logger::Instance().getPrintLevels(); // workaround: verbose causes the parse call below to fail (registry pointer is 0)
Logger::Instance().setPrintLevels(0);
programs[programpath].changeRegistry(reg);
ModuleHexParser hp;
hp.parse(ip, programs[programpath]);
Logger::Instance().setPrintLevels(l);
}
ProgramCtx& pc = programs[programpath];
// construct edb
DBGLOG(DBG, "Constructing EDB");
InterpretationPtr edb = InterpretationPtr(new Interpretation(*pc.edb));
// go through all input atoms
DBGLOG(DBG, "Rewriting input");
for(Interpretation::Storage::enumerator it =
query.interpretation->getStorage().first();
it != query.interpretation->getStorage().end(); ++it){
ID ogid(ID::MAINKIND_ATOM | ID::SUBKIND_ATOM_ORDINARYG, *it);
const OrdinaryAtom& ogatom = reg->ogatoms.getByID(ogid);
// check if the predicate matches any of the input parameters to simulator atom
bool found = false;
for (int inp = 1; inp < params.size(); ++inp){
if (ogatom.tuple[0] == params[inp]){
// replace the predicate by "in[inp]"
std::stringstream inPredStr;
inPredStr << "in" << inp;
Term inPredTerm(ID::MAINKIND_TERM | ID::SUBKIND_TERM_CONSTANT, inPredStr.str());
ID inPredID = reg->storeTerm(inPredTerm);
OrdinaryAtom oareplace = ogatom;
oareplace.tuple[0] = inPredID;
// get ID of replaced atom
ID oareplaceID = reg->storeOrdinaryGAtom(oareplace);
// set this atom in the input interpretation
edb->getStorage().set_bit(oareplaceID.address);
found = true;
break;
}
}
assert(found);
}
DBGLOG(DBG, "Grounding simulation program");
OrdinaryASPProgram program(pc.registry(), pc.idb, edb);
InternalGrounderPtr ig = InternalGrounderPtr(new InternalGrounder(pc, program));
OrdinaryASPProgram gprogram = ig->getGroundProgram();
DBGLOG(DBG, "Evaluating simulation program");
GenuineSolverPtr igas = GenuineSolver::getInstance(pc, gprogram);
InterpretationPtr as = igas->getNextModel();
if (as != InterpretationPtr()){
// extract parameters from all atoms over predicate "out"
DBGLOG(DBG, "Rewrting output");
Term outPredTerm(ID::MAINKIND_TERM | ID::SUBKIND_TERM_CONSTANT, "out");
ID outPredID = reg->storeTerm(outPredTerm);
for(Interpretation::Storage::enumerator it =
as->getStorage().first();
it != as->getStorage().end(); ++it){
ID ogid(ID::MAINKIND_ATOM | ID::SUBKIND_ATOM_ORDINARYG, *it);
const OrdinaryAtom& ogatom = reg->ogatoms.getByID(ogid);
if (ogatom.tuple[0] == outPredID){
Tuple t;
for (int ot = 1; ot < ogatom.tuple.size(); ++ot){
t.push_back(ogatom.tuple[ot]);
}
answer.get().push_back(t);
}
}
}
}
示例10: Relation
GenericRelation *Relation::In( ListExpr typeInfo, ListExpr value,
int errorPos, ListExpr& errorInfo,
bool& correct, bool tupleBuf /*=false*/)
{
ListExpr tuplelist, TupleTypeInfo, first;
GenericRelation* rel;
Tuple* tupleaddr;
int tupleno, count;
bool tupleCorrect;
correct = true;
count = 0;
if (tupleBuf)
rel = new TupleBuffer;
else
rel = new Relation( typeInfo );
tuplelist = value;
TupleTypeInfo = nl->TwoElemList(nl->Second(typeInfo),
nl->IntAtom(nl->ListLength(nl->Second(nl->Second(typeInfo)))));
tupleno = 0;
if (nl->IsAtom(value))
{
correct = false;
errorInfo = nl->Append(errorInfo,
nl->ThreeElemList(
nl->IntAtom(70),
nl->SymbolAtom(Relation::BasicType()),
tuplelist));
return rel;
}
else
{ // increase tupleno
while (!nl->IsEmpty(tuplelist))
{
first = nl->First(tuplelist);
tuplelist = nl->Rest(tuplelist);
tupleno++;
tupleaddr = Tuple::In(TupleTypeInfo, first, tupleno,
errorInfo, tupleCorrect);
if (tupleCorrect)
{
rel->AppendTuple(tupleaddr);
tupleaddr->DeleteIfAllowed();
count++;
}
else
{
correct = false;
}
}
if (!correct)
{
errorInfo =
nl->Append(errorInfo,
nl->TwoElemList(
nl->IntAtom(72),
nl->SymbolAtom(Relation::BasicType())));
delete rel;
return 0;
}
else
return rel;
}
}
示例11: main
int main(int argc, char* argv[]) {
std::string file_name;
if (argc < 2) {
std::cerr << "please specify the file name" << std::endl;
return 1;
}
file_name = argv[1];
std::ifstream infile;
#ifdef _MSC_VER
// handling file names with non-ascii characters
wchar_t *wcstring = new wchar_t[file_name.size()+1];
setlocale(LC_ALL, ".OCP");
mbstowcs(wcstring, file_name.c_str(), file_name.size()+1);
infile.open(wcstring);
delete[] wcstring;
setlocale(LC_ALL, "");
#else // _MSC_VER
infile.open(file_name.c_str());
#endif // _MSC_VER
if (!infile.is_open()) {
std::cerr << "cannot open the input file" << std::endl;
return 1;
}
SUTModel sut_model;
Assembler assembler;
try {
ct::lexer lexer(&infile);
assembler.setErrLogger(boost::shared_ptr<ErrLogger>(new ErrLogger_Cerr()));
yy::ct_parser parser(lexer,
sut_model.param_specs_,
sut_model.strengths_,
sut_model.seeds_,
sut_model.constraints_,
assembler);
parser.parse();
} catch (std::runtime_error e) {
std::cerr << e.what() << std::endl;
} catch (...) {
std::cerr << "unhandled exception when parsing input file" << std::endl;
std::cerr << "exiting" << std::endl;
return 1;
}
if (assembler.numErrs() > 0) {
std::cerr << assembler.numErrs() << " errors in the input file, exiting" << std::endl;
return 2;
}
std::cout << "successfully parsed the input file" << std::endl;
std::cout << "# parameters: " << sut_model.param_specs_.size() << std::endl;
std::cout << "# strengths: " << sut_model.strengths_.size() << std::endl;
std::cout << "# seeds: " << sut_model.seeds_.size() << std::endl;
std::cout << "# constraints: " << sut_model.constraints_.size() << std::endl;
std::vector<RawStrength> raw_strengths;
TuplePool tuple_pool;
for (std::size_t i = 0; i < sut_model.strengths_.size(); ++i) {
attach_2_raw_strength(sut_model.strengths_[i], raw_strengths);
}
for (std::size_t i = 0; i < raw_strengths.size(); ++i) {
Tuple tuple;
for (std::size_t j = 0; j < raw_strengths[i].size(); ++j) {
tuple.push_back(PVPair(raw_strengths[i][j], 0));
}
if (tuple.size() <= 0) {
continue;
}
do {
tuple_pool.insert(tuple);
} while (tuple.to_the_next_tuple(sut_model.param_specs_));
}
std::cout << "# target combinations: " << tuple_pool.size() << std::endl;
TuplePool forbidden_tuple_pool;
for (std::size_t i = 0; i < sut_model.constraints_.size(); ++i) {
std::set<std::size_t> rel_pids;
sut_model.constraints_[i]->touch_pids(sut_model.param_specs_, rel_pids);
Tuple tuple;
for (std::set<std::size_t>::const_iterator iter = rel_pids.begin(); iter != rel_pids.end(); iter++) {
tuple.push_back(PVPair(*iter, 0));
}
do {
EvalType_Bool result = sut_model.constraints_[i]->Evaluate(sut_model.param_specs_, tuple);
if (!result.is_valid_ || !result.value_) {
forbidden_tuple_pool.insert(tuple);
}
} while (tuple.to_the_next_tuple_with_ivld(sut_model.param_specs_));
}
std::cout << "# forbidden combinations: " << forbidden_tuple_pool.size() << std::endl;
return 0;
}
示例12: Tuple
Tuple *Tuple::In( ListExpr typeInfo, ListExpr value, int errorPos,
ListExpr& errorInfo, bool& correct )
{
int attrno, algebraId, typeId, noOfAttrs;
Word attr;
bool valueCorrect;
ListExpr first, firstvalue, valuelist, attrlist;
attrno = 0;
noOfAttrs = 0;
Tuple *t = new Tuple( nl->First( typeInfo ) );
attrlist = nl->Second(nl->First(typeInfo));
valuelist = value;
correct = true;
if (nl->IsAtom(valuelist))
{
correct = false;
cout << "Error in reading tuple: an atom instead of a list "
<< "of values." << endl;
cout << "Tuple no." << errorPos << endl;
cout << "The tuple is: " << endl;
nl->WriteListExpr(value);
errorInfo = nl->Append(errorInfo,
nl->FourElemList(
nl->IntAtom(71),
nl->SymbolAtom(Tuple::BasicType()),
nl->IntAtom(1),
nl->IntAtom(errorPos)));
delete t;
return 0;
}
else
{
while (!nl->IsEmpty(attrlist))
{
first = nl->First(attrlist);
attrlist = nl->Rest(attrlist);
algebraId =
t->GetTupleType()->GetAttributeType( attrno ).algId;
typeId =
t->GetTupleType()->GetAttributeType( attrno ).typeId;
attrno++;
if (nl->IsEmpty(valuelist))
{
correct = false;
cout << "Error in reading tuple: list of values is empty."
<< endl;
cout << "Tuple no." << errorPos << endl;
cout << "The tuple is: " << endl;
nl->WriteListExpr(value);
errorInfo = nl->Append(errorInfo,
nl->FourElemList(
nl->IntAtom(71),
nl->SymbolAtom(Tuple::BasicType()),
nl->IntAtom(2),
nl->IntAtom(errorPos)));
delete t;
return 0;
}
else
{
firstvalue = nl->First(valuelist);
valuelist = nl->Rest(valuelist);
attr = (am->InObj(algebraId, typeId))
(nl->First(nl->Rest(first)), firstvalue,
attrno, errorInfo, valueCorrect);
if (valueCorrect)
{
correct = true;
t->PutAttribute(attrno - 1, (Attribute *)attr.addr);
noOfAttrs++;
}
else
{
correct = false;
cout << "Error in reading tuple: "
<< "wrong attribute value representation." << endl;
cout << "Tuple no." << errorPos << endl;
cout << "The tuple is: " << endl;
nl->WriteListExpr(value);
cout << endl << "The attribute is: " << endl;
nl->WriteListExpr(firstvalue);
cout << endl;
errorInfo = nl->Append(errorInfo,
nl->FiveElemList(
nl->IntAtom(71),
nl->SymbolAtom(Tuple::BasicType()),
nl->IntAtom(3),
nl->IntAtom(errorPos),
//.........这里部分代码省略.........
示例13: Insert
Relation* Insert(vector<string> &words, string &line, SchemaManager &schema_manager, MainMemory &mem){
Relation* relation_ptr = schema_manager.getRelation(words[2]);
vector<string>::iterator it = find(words.begin(), words.end(), "SELECT");
// no select
if (it == words.end()){
// get insert vals
vector<string> content = splitBy(line, "()");
vector<string> fields = splitBy(content[1], ", ");
vector<string> vals = splitBy(content[3], ",");
//preProcess(vector<string>(1, words[2]), fields, schema_manager);
preProcess(vector<string>(1, words[2]), vals, schema_manager);
assert(fields.size() == vals.size());
Tuple tuple = relation_ptr->createTuple();
// standard insert doesn't have table names
vector<string> col_names = nakedFieldNames(relation_ptr);
// comparing
for (int i = 0; i < fields.size(); i++){
for (int j = 0; j < col_names.size(); j++){
// this is a match
if (fields[i] == col_names[j]){
if (tuple.getSchema().getFieldType(j) == INT){
tuple.setField(j, atoi(vals[i].c_str()));
}
else{
tuple.setField(j, vals[i]);
}
break;
}
}
}
appendTupleToRelation(relation_ptr, mem, tuple);
}
// with SELECT
else{
vector<string> SFW(it, words.end());
Relation* new_relation = Select(SFW, schema_manager, mem);
assert(new_relation);
vector<string> new_field_names = nakedFieldNames(new_relation);
vector<string> field_names = nakedFieldNames(relation_ptr);
// mapping: index of new_field_names to field_names
vector<int> mapping(new_field_names.size(), -1);
for (int i = 0; i < new_field_names.size(); i++){
for (int j = 0; j < field_names.size(); j++){
if (new_field_names[i] == field_names[j]){
mapping[i] = j;
break;
}
}
}
int new_field_size = new_relation->getSchema().getNumOfFields();
// warning: new_relation and relation_ptr might be the same!
// get all tuples from the new_relation in one run
vector<Tuple> new_tuples;
for (int i = 0; i < new_relation->getNumOfBlocks(); i++){
assert(!free_blocks.empty());
int memory_block_index = free_blocks.front();
free_blocks.pop();
// read the relation block by block
new_relation->getBlock(i, memory_block_index);
Block* block_ptr = mem.getBlock(memory_block_index);
assert(block_ptr);
vector<Tuple> block_tuples = block_ptr->getTuples();
new_tuples.insert(new_tuples.end(), block_tuples.begin(), block_tuples.end());
if(new_tuples.empty()){
cerr<<"Warning: Insert from SFW, No tuples in the current mem block!"<<endl;
}
free_blocks.push(memory_block_index);
}
for (int j = 0; j < new_tuples.size(); j++){
Tuple tuple = relation_ptr->createTuple();
for (int k = 0; k < new_field_size; k++){
if (mapping[k] != -1){
int idx = mapping[k];
assert(idx < relation_ptr->getSchema().getNumOfFields() && idx >= 0);
if (tuple.getSchema().getFieldType(idx) == INT){
int val = new_tuples[j].getField(k).integer;
tuple.setField(field_names[idx], val);
}
else{
string *str = new_tuples[j].getField(k).str;
tuple.setField(field_names[idx], *str);
}
}
}
appendTupleToRelation(relation_ptr, mem, tuple);
}
cout<<*relation_ptr<<endl;
}
//.........这里部分代码省略.........
示例14: if
Relation Relation::select(vector<Token>& inputTokens)
{
Relation newRelation = (*this);
set<Tuple>* newTuples = new set<Tuple>();
map<Token, vector<int> > myMap;
for(int i = 0; i < inputTokens.size(); i++)
{
if(inputTokens[i].getTokenType() == ID)
{
bool inserted = false;
for(map<Token, vector<int> >::iterator it = myMap.begin(); it != myMap.end(); it++)
{
if(it->first.getTokensValue() == inputTokens[i].getTokensValue())
{
it->second.push_back(i);
inserted = true;
}
}
if(!inserted)
{
vector<int> newVec;
newVec.push_back(i);
myMap.insert(pair<Token, vector<int> >(inputTokens[i], newVec) );
}
}
}
//Goes through all Tuples in THIS relation, checks if all query strings match, and adds matching tuples to the returned relation
for(set<Tuple>::iterator it = tuples->begin(); it != tuples->end(); it++) //for all tuples in THIS
{
bool isTrue = true;
Tuple tempTuple = (*it);
Tuple thisTuple = tempTuple;
for(int j = 0; j < thisTuple.getPairVectorSize(); j++) //for all pairs in this tuple
{
for(int i = 0; i < inputTokens.size(); i++) //for all parameters in the query
{
//CHECKS FOR TUPLES WITH CORRECT STRING COMBINATIONS
if(inputTokens[i].getTokenType() == STRING && j == i) //if this parameter is the placeholder string
{
if(inputTokens[i].getTokensValue() != thisTuple.getTokenFromPairAt(j).getTokensValue()) //if the values don't match
{
isTrue = false; //do not add to the new relation
}
}
//CHECK FOR TUPLES WITH DUPLICATE VALUES FOR DUPLICATE IDs IN QUERY
else if(inputTokens[i].getTokenType() == ID)
{
for(map<Token, vector<int> >::iterator mit = myMap.begin(); mit != myMap.end(); mit++)
{
for(int k = 0; k < thisTuple.getPairVectorSize(); k++)
{
for(int h = 0; h < mit->second.size(); h++)
{
if(k == mit->second[h])
{
for(int n = 0; n < mit->second.size(); n++)
{
if(thisTuple.getPairs()[k].second.getTokensValue() != thisTuple.getPairs()[mit->second[n]].second.getTokensValue())
{
isTrue = false;
}
}
}
}
}
}
}
}
}
if(isTrue) //otherwise add the tuple to the new relation
{
newTuples->insert(thisTuple);
}
}
set<Tuple>* deleteSet = newRelation.getTuples();
newRelation.setTuples(newTuples);
delete deleteSet;
return newRelation;
}
示例15: start_line
int CompiledMethod::start_line(STATE) {
if(lines_->nil_p()) return -1;
if(lines_->num_fields() < 1) return -1;
Tuple* top = as<Tuple>(lines_->at(state, 0));
return as<Fixnum>(top->at(state, 2))->to_native();
}