|
Last change
on this file since 86b917 was 86b917, checked in by Tillmann Crueger <crueger@…>, 16 years ago |
|
Added descriptors that allow multiple kinds of access to atoms
|
-
Property mode
set to
100644
|
|
File size:
999 bytes
|
| Line | |
|---|
| 1 | /*
|
|---|
| 2 | * AtomDescriptor.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: Feb 5, 2010
|
|---|
| 5 | * Author: crueger
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #include "AtomDescriptor.hpp"
|
|---|
| 9 |
|
|---|
| 10 | #include "World.hpp"
|
|---|
| 11 |
|
|---|
| 12 | #include <boost/bind.hpp>
|
|---|
| 13 |
|
|---|
| 14 | using namespace std;
|
|---|
| 15 |
|
|---|
| 16 | typedef map<int,atom*> atoms_t;
|
|---|
| 17 | typedef atoms_t::iterator atoms_iter_t;
|
|---|
| 18 |
|
|---|
| 19 | AtomDescriptor::AtomDescriptor()
|
|---|
| 20 | {
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | AtomDescriptor::~AtomDescriptor()
|
|---|
| 24 | {
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | atoms_t& AtomDescriptor::getAtoms(){
|
|---|
| 29 | return World::get()->atoms;
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | AtomPredicateDescriptor::AtomPredicateDescriptor()
|
|---|
| 33 | {
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | AtomPredicateDescriptor::~AtomPredicateDescriptor()
|
|---|
| 37 | {
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | atom* AtomPredicateDescriptor::find() {
|
|---|
| 41 | atoms_t atoms = getAtoms();
|
|---|
| 42 | atoms_iter_t res = find_if(atoms.begin(),atoms.end(),boost::bind(&AtomPredicateDescriptor::predicate,this,_1));
|
|---|
| 43 | return (res!=atoms.end())?((*res).second):0;
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | vector<atom*> AtomPredicateDescriptor::findAll() {
|
|---|
| 47 | vector<atom*> res;
|
|---|
| 48 | atoms_t atoms = getAtoms();
|
|---|
| 49 | atoms_iter_t iter;
|
|---|
| 50 | for(iter=atoms.begin();iter!=atoms.end();++iter) {
|
|---|
| 51 | if(predicate(*iter))
|
|---|
| 52 | res.push_back((*iter).second);
|
|---|
| 53 | }
|
|---|
| 54 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.