本文整理汇总了C++中Tuple类的典型用法代码示例。如果您正苦于以下问题:C++ Tuple类的具体用法?C++ Tuple怎么用?C++ Tuple使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tuple类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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());
}
}
}
}
开发者ID:John-Chan,项目名称:sipXtapi,代码行数:71,代码来源:SipPresenceMonitor.cpp
示例2: test_fields_prim
void test_fields_prim() {
Tuple* tuple = new_tuple();
TS_ASSERT_EQUALS(Fixnum::from(3), as<Fixnum>(tuple->fields_prim(state)));
}
开发者ID:AndreMeira,项目名称:rubinius,代码行数:4,代码来源:test_tuple.hpp
示例3: s
ModEvent CPTupleVarImp::assign(Space& home, const Tuple& t) {
TupleSet s(t.arity());
s.add(t);
return exclude(home,s.complement());
}
开发者ID:Wushaowei001,项目名称:cprelmaster,代码行数:5,代码来源:varimp.cpp
示例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));
}
开发者ID:AndreMeira,项目名称:rubinius,代码行数:5,代码来源:test_tuple.hpp
示例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)));
}
开发者ID:AndreMeira,项目名称:rubinius,代码行数:6,代码来源:test_tuple.hpp
示例6:
inline bool operator==(const Tuple &l, const tOther &r)
{
return l.equal(r);
}
开发者ID:,项目名称:,代码行数:4,代码来源:
示例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);
}
开发者ID:chazmatazz,项目名称:proto-mirror,代码行数:7,代码来源:simpledynamics.cpp
示例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;
}
开发者ID:ManjushaBolishetty,项目名称:TinySQL-Interperter,代码行数:43,代码来源:TupleProcessing.cpp
示例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);
}
}
}
}
开发者ID:hexhex,项目名称:mergingplugin,代码行数:91,代码来源:HexExecution.cpp
示例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;
}
}
开发者ID:awarematics,项目名称:SECONDO,代码行数:70,代码来源:RelationCommon.cpp
示例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;
}
开发者ID:yanyige,项目名称:ct_common,代码行数:89,代码来源:example.cpp
示例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),
//.........这里部分代码省略.........
开发者ID:awarematics,项目名称:SECONDO,代码行数:101,代码来源:RelationCommon.cpp
示例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;
}
//.........这里部分代码省略.........
开发者ID:tonywang1990,项目名称:TinySQL-implementation,代码行数:101,代码来源:query.cpp
示例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;
}
开发者ID:SchuylerGoodman,项目名称:RelationalDatabase,代码行数:81,代码来源:Relation.cpp
示例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();
}
开发者ID:soaexpert,项目名称:rubinius,代码行数:6,代码来源:compiledmethod.cpp
示例16: Tuple2D
KPoint::KPoint(const Tuple& other)
: Tuple2D(other.at(0), other.at(1))
{
// Nothing;
}
开发者ID:hkhandan,项目名称:knorba-are,代码行数:5,代码来源:CellAutomataAgent.cpp
示例17: testTuple
bool testTuple( Teuchos::FancyOStream &out )
{
using Teuchos::Tuple;
using Teuchos::tuple;
using Teuchos::ArrayView;
using Teuchos::arrayView;
using Teuchos::arrayViewFromVector;
using Teuchos::outArg;
using Teuchos::NullIteratorTraits;
using Teuchos::TypeNameTraits;
using Teuchos::getConst;
using Teuchos::as;
typedef typename ArrayView<T>::size_type size_type;
bool success = true;
out
<< "\n***"
<< "\n*** Testing "<<TypeNameTraits<Tuple<T,N> >::name()<<" of size = "<<N
<< "\n***\n";
Teuchos::OSTab tab(out);
//
out << "\nA) Initial setup testing ...\n\n";
//
Tuple<T,N> t;
TEST_EQUALITY_CONST(t.size(),N);
for( int i = 0; i < N; ++i )
t[i] = i; // tests non-const operator[](i)
{
out << "\nTest that t[i] == i ... ";
const ArrayView<const T> cav2 = t;
bool local_success = true;
for( int i = 0; i < N; ++i ) {
TEST_ARRAY_ELE_EQUALITY( cav2, i, as<T>(i) );
}
if (local_success) out << "passed\n";
else success = false;
}
{
const int n = 1;
out << "\nTest Tuple<T,"<<n<<"> = tuple(...)\n";
Tuple<T,n> tn = tuple<T>(0);
TEST_EQUALITY_CONST(tn.size(),n);
out << "Test that tn[i] == i ... ";
bool local_success = true;
for( int i = 0; i < n; ++i ) {
TEST_ARRAY_ELE_EQUALITY( tn, i, as<T>(i) );
}
if (local_success) out << "passed\n";
else success = false;
}
{
const int n = 2;
out << "\nTest Tuple<T,"<<n<<"> = tuple(...)\n";
Tuple<T,n> tn = tuple<T>(0,1);
TEST_EQUALITY_CONST(tn.size(),n);
out << "Test that tn[i] == i ... ";
bool local_success = true;
for( int i = 0; i < n; ++i ) {
TEST_ARRAY_ELE_EQUALITY( tn, i, as<T>(i) );
}
if (local_success) out << "passed\n";
else success = false;
}
{
const int n = 3;
out << "\nTest Tuple<T,"<<n<<"> = tuple(...)\n";
Tuple<T,n> tn = tuple<T>(0,1,2);
TEST_EQUALITY_CONST(tn.size(),n);
out << "Test that tn[i] == i ... ";
bool local_success = true;
for( int i = 0; i < n; ++i ) {
TEST_ARRAY_ELE_EQUALITY( tn, i, as<T>(i) );
}
if (local_success) out << "passed\n";
else success = false;
}
{
const int n = 4;
out << "\nTest Tuple<T,"<<n<<"> = tuple(...)\n";
Tuple<T,n> tn = tuple<T>(0,1,2,3);
TEST_EQUALITY_CONST(tn.size(),n);
out << "Test that tn[i] == i ... ";
bool local_success = true;
for( int i = 0; i < n; ++i ) {
TEST_ARRAY_ELE_EQUALITY( tn, i, as<T>(i) );
}
if (local_success) out << "passed\n";
else success = false;
}
//.........这里部分代码省略.........
开发者ID:gitter-badger,项目名称:quinoa,代码行数:101,代码来源:Tuple_test.cpp
示例18: find_entry
/** Same as aref(state, key). */
Object* LookupTable::fetch(STATE, Object* key) {
Tuple* entry = find_entry(state, key);
if(entry) return entry->at(state, 1);
return Qnil;
}
开发者ID:marnen,项目名称:rubinius,代码行数:6,代码来源:lookuptable.cpp
示例19: s3
Relation *slowCrossJoin(Relation *rptr1, Relation *rptr2, string r3, vector<string> fields1, vector<string> fields2, vector<string> op)
{
Schema s1, s2;
vector <string> fields_r1, fields_r2, fields_r3;
vector <enum FIELD_TYPE> types_r3;
//Relation *rptr1, *rptr2;
vector<string> values_r3;
int num_blocks_r1, num_blocks_r2, max_blocks;
num_blocks_r1 = rptr1->getNumOfBlocks();
num_blocks_r2 = rptr2->getNumOfBlocks();
max_blocks = mem.getMemorySize();
s1 = rptr1->getSchema();
s2 = rptr2->getSchema();
fields_r1 = s1.getFieldNames();
fields_r2 = s2.getFieldNames();
if(disp)
{
cout<<"#"<<rptr1->getRelationName()<<" ="<<num_blocks_r1<<endl;
cout<<"#"<<rptr2->getRelationName()<<" ="<<num_blocks_r2<<endl;
}
for(int i=0; i<fields_r1.size(); i++)
{
fields_r3.push_back(rptr1->getRelationName() + "." + fields_r1[i]);
types_r3.push_back(s1.getFieldType(fields_r1[i]));
}
for(int i=0; i<fields_r2.size(); i++)
{
fields_r3.push_back(rptr2->getRelationName() + "." + fields_r2[i]);
types_r3.push_back(s2.getFieldType(fields_r2[i]));
}
Schema s3(fields_r3,types_r3);
//string r3 = rptr1->getRelationName() + "." + rptr2->getRelationName() + ".CrossJoin";
Relation *rptr3 = schema_manager.createRelation(r3, s3);
if(disp)
{
cout<<"New Relation: "<<r3<<endl;
cout<<s3<<endl;
}
for(int id = 0; id<num_blocks_r2; id += (max_blocks - 2))
{
//Get tuples of smaller relation into Main Memory, assuming all can fit in
int num_blocks_to_read = ((num_blocks_r2 - id) < (max_blocks - 2))?(num_blocks_r2 - id):(max_blocks-2);
rptr2->getBlocks(id, 0, num_blocks_to_read);
vector<Tuple> tuples_r3, tuples_r2 = mem.getTuples(0, num_blocks_to_read);
//Read one block of relation into Main memory and combine each tuple in the block
//with all the tuples in the other
Block *block_r1 = mem.getBlock(max_blocks - 2);
Block *block_r3 = mem.getBlock(max_blocks - 1);
block_r3->clear();
for(int i=0; i<num_blocks_r1; i++)
{
block_r1->clear();
rptr1->getBlock(i, max_blocks - 2);
vector<Tuple> tuples_r1 = block_r1->getTuples();
for(int j =0; j < tuples_r1.size(); j++)
{
//Check for holes
if(tuples_r1[j].isNull())
continue;
for(int k=0; k < tuples_r2.size(); k++)
{
//Check for holes
if(tuples_r2[k].isNull())
continue;
Tuple tuple = rptr3->createTuple();
if(isJoinTuple(tuples_r1[j], tuples_r2[k], fields1, fields2, op))
{
for(int l =0; l < fields_r1.size(); l++)
{
if(s3.getFieldType(rptr1->getRelationName() + "." + fields_r1[l]) == INT)
tuple.setField(rptr1->getRelationName() + "." + fields_r1[l],tuples_r1[j].getField(fields_r1[l]).integer);
else
tuple.setField(rptr1->getRelationName() + "." + fields_r1[l],*(tuples_r1[j].getField(fields_r1[l]).str));
}
for(int l =0; l < fields_r2.size(); l++)
{
if(s3.getFieldType(rptr2->getRelationName() + "." + fields_r2[l]) == INT)
tuple.setField(rptr2->getRelationName() + "." + fields_r2[l],tuples_r2[k].getField(fields_r2[l]).integer);
else
tuple.setField(rptr2->getRelationName() + "." + fields_r2[l],*(tuples_r2[k].getField(fields_r2[l]).str));
}
if(disp)
cout<<"New Tuple:"<<tuple<<endl;
tuples_r3.push_back(tuple);
block_r3->appendTuple(tuple);
//If main memory block is full, write it to disk and clear that block
if(tuples_r3.size() == s3.getTuplesPerBlock())
{
rptr3->setBlock(rptr3->getNumOfBlocks(),max_blocks - 1);
tuples_r3.clear();
//.........这里部分代码省略.........
开发者ID:v33n,项目名称:tinysql,代码行数:101,代码来源:Join.cpp
示例20: test_at
void test_at() {
Tuple* tuple = new_tuple();
TS_ASSERT_EQUALS(Fixnum::from(4), as<Fixnum>(tuple->at(state, 1)));
TS_ASSERT_EQUALS(Qnil, tuple->at(state, 4));
}
开发者ID:AndreMeira,项目名称:rubinius,代码行数:5,代码来源:test_tuple.hpp
注:本文中的Tuple类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论