main.cpp/physics.h: add some (somewhat icky) compile fixes for OS X
[openc2e.git] / AgentRef.cpp
blob1d8f478e732898078fa73da40ae9eac6b1e12fb2
1 /*
2 * AgentRef.cpp
3 * openc2e
5 * Created by Bryan Donlan on The Apr 11 2005
6 * Copyright (c) 2005 Bryan Donlan. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
20 #include "AgentRef.h"
21 #include "Agent.h"
22 #include <cassert>
23 #include <iostream>
25 void AgentRef::checkLife() const {
26 assert(ref.expired() || !(ref.lock()->isDying()));
29 void AgentRef::set(Agent *a) {
30 if (a && !a->isDying())
31 set(a->shared_from_this());
32 else
33 ref.reset();
36 void AgentRef::dump() const {
37 std::cerr << "AgentRef " << (void *)this << " pointing to " << (void *)ref.lock().get() << std::endl;
40 boost::shared_ptr<Agent> AgentRef::lock() const {
41 boost::shared_ptr<Agent> p = ref.lock();
42 if (p && p->isDying())
43 p.reset();
44 return p;
47 /* vim: set noet: */