Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

object.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002 
00003    this file is part of rcssserver3D
00004    Fri May 9 2003
00005    Copyright (C) 2002,2003 Koblenz University
00006    Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group
00007    $Id: object.cpp,v 1.10 2004/05/14 16:00:46 fruit Exp $
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; version 2 of the License.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021 */
00022 #include "object.h"
00023 #include "class.h"
00024 #include "core.h"
00025 #include "leaf.h"
00026 #include <iostream>
00027 #include <boost/version.hpp>
00028 
00029 using namespace boost;
00030 using namespace std;
00031 using namespace zeitgeist;
00032 
00033 Object::Object()
00034 {
00035 }
00036 
00037 Object::~Object()
00038 {
00039     if (mClass.get())
00040     {
00041         mClass->DetachInstance(GetSelf());
00042     }
00043 }
00044 
00045 bool Object::Construct(const boost::shared_ptr<Object>& self, const boost::shared_ptr<Class>& creator)
00046 {
00047     mSelf       = self;
00048     mClass      = creator;
00049 
00050     // give each object a chance to do something
00051     return ConstructInternal();
00052 }
00053 
00054 boost::shared_ptr<Class> Object::GetClass() const
00055 {
00056     if (mClass.get() == 0)
00057     {
00058         const Leaf* leaf = dynamic_cast<const Leaf*>(this);
00059 
00060         if (leaf != 0)
00061         {
00062             if (leaf->GetFullPath() != "ClassClass")
00063             {
00064                 std::cerr << "(Object) ERROR: failed to get Class object "
00065                           << "for '" << leaf->GetName()
00066                           << "' installed at '"
00067                           << leaf->GetFullPath() << "'\n";
00068             }
00069         } else {
00070             std::cerr << "(Object) ERROR: failed to get Class object for unknown\n";
00071         }
00072     }
00073     return mClass;
00074 }
00075 
00076 boost::weak_ptr<Object>& Object::GetSelf()
00077 {
00078     return mSelf;
00079 }
00080 
00081 const boost::weak_ptr<Object>& Object::GetSelf() const
00082 {
00083     return mSelf;
00084 }
00085 
00086 boost::shared_ptr<Core> Object::GetCore() const
00087 {
00088     assert(mClass.get() != NULL);
00089     boost::shared_ptr<Core> core = mClass->GetCore();
00090 
00091     if (core.get() == 0)
00092       {
00093           std::cout << "(Object) ERROR: failed to get zeitgeist core ";
00094           const Leaf* leaf = dynamic_cast<const Leaf*>(this);
00095 
00096           if (leaf != 0)
00097               {
00098                   std::cout << "for '" << leaf->GetName()
00099                             << std::cout << "' installed at '"
00100                             << leaf->GetFullPath()
00101                             << "'";
00102               }
00103 
00104           std::cout << std::endl;
00105       }
00106 
00107     return mClass->GetCore();
00108 }
00109 
00110 void Object::Dump() const
00111 {
00112     cout << "Object: " << (void*) this;
00113     if (shared_ptr<Object> self = mSelf.lock())
00114     {
00115         cout << " " << (void*) self.get();
00116     } else {
00117         cout << " " << "(expired)";
00118     }
00119     cout << " - use count = " << mSelf.use_count() << endl;
00120 }
00121 
00122 void Object::Invoke(const std::string &functionName, const ParameterList& parameter)
00123 {
00124     Class::TCmdProc cmd = mClass->GetCmdProc(functionName);
00125     if (cmd != NULL)
00126       {
00127         if (shared_ptr<Object> self = GetSelf().lock())
00128           {
00129             GCValue out = cmd(self.get(), parameter);
00130           }
00131       }
00132 }
00133 
00134 const boost::shared_ptr<FileServer>& Object::GetFile() const
00135 {
00136     return GetCore()->GetFileServer();
00137 }
00138 
00139 const boost::shared_ptr<LogServer>& Object::GetLog() const
00140 {
00141     return GetCore()->GetLogServer();
00142 }
00143 
00144 const boost::shared_ptr<ScriptServer>& Object::GetScript() const
00145 {
00146     return GetCore()->GetScriptServer();
00147 }
00148 
00149 bool Object::ConstructInternal()
00150 {
00151     return true;
00152 }

Generated on Thu Apr 6 15:25:39 2006 for rcssserver3d by  doxygen 1.4.4