Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/util/object_manager.cc @ 4501

Last change on this file since 4501 was 4485, checked in by bensch, 19 years ago

orxonox/trunk: more documentation in util

File size: 3.1 KB
RevLine 
[4245]1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Patrick Boenzli
13*/
14
15#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_OBJECT_MANAGER
16
17#include "object_manager.h"
[4288]18#include "garbage_collector.h"
[4286]19#include "list.h"
[4245]20
[4288]21
[4245]22using namespace std;
23
24
25/**
26   \brief standard constructor
27*/
28ObjectManager::ObjectManager () 
29{
[4320]30  this->setClassID(CL_OBJECT_MANAGER, "ObjectManager");
[4286]31 
32  this->managedObjectList = new tList<BaseObject>*[CL_NUMBER];
[4318]33  for(int i = 0; i < CL_NUMBER; ++i)
34    {
35      this->managedObjectList[i] = NULL;
36    }
[4288]37
38  this->garbageCollector = GarbageCollector::getInstance();
[4245]39}
40
[4322]41
[4245]42/**
43   \brief the singleton reference to this class
44*/
45ObjectManager* ObjectManager::singletonRef = NULL;
46
47/**
48   \returns a Pointer to this Class
49*/
50ObjectManager* ObjectManager::getInstance(void)
51{
52  if (!ObjectManager::singletonRef)
53    ObjectManager::singletonRef = new ObjectManager();
54  return ObjectManager::singletonRef;
55}
56
[4285]57
[4245]58/**
59   \brief standard deconstructor
60*/
61ObjectManager::~ObjectManager () 
62{
63  ObjectManager::singletonRef = NULL;
[4285]64}
[4245]65
[4485]66/**
67   \brief adds an element to the list of dead objects
68   \param index: The type of object to add
69   \param object: pointer to the object at hand
70*/
[4322]71void ObjectManager::addToDeadList(int index, BaseObject* object)
[4288]72{
73  if( likely(this->managedObjectList[index] != NULL))
74    this->managedObjectList[index]->add(object);
75  else
[4324]76    PRINTF(0)(" Critical: unable to add object to the list nr. %i: no list initialized - ignoring\n", index);
[4288]77}
[4285]78
[4485]79/**
80   \brief resurects an object
81   \param index: the type of resource to load
82   \param number: how many of them
[4285]83
[4485]84   \todo if it is unable to get an object from the deadList, it should create it
85*/
[4322]86BaseObject* ObjectManager::getFromDeadList(int index, int number)
[4289]87{
88  if( likely(this->managedObjectList[index] != NULL))
89    {
90      BaseObject* obj = this->managedObjectList[index]->firstElement();
91      this->managedObjectList[index]->remove(obj);
[4324]92      if( unlikely(obj == NULL))
93        {
94          PRINTF(0)("Critical: there was no object anymore in the dead list! This could result in Segfaults\n");
95        }
[4289]96      return obj;
97    }
98  else
[4324]99    PRINTF(0)(" Critical: unable to get object from the list nr. %i: no elements initialized - ignoring\n", index);
100  return NULL;
[4289]101}
[4287]102
[4485]103/**
104   \brief outputs some simple debug information about the ObjectManage
105*/
106void ObjectManager::debug(void) const
[4287]107{
108  PRINT(0)("\n==========================| ObjectManager::debug() |===\n");
109  PRINT(0)("=  Number of registerable classes: %i\n", CL_NUMBER ); 
110  PRINT(0)("=  Currently cached objects: \n");
111  for(int i = 0; i < CL_NUMBER; ++i)
112    {
[4318]113      if( this->managedObjectList[i] != NULL)
[4287]114        PRINT(0)("=   o Class Nr. %i has cached %i object(s)\n", i, this->managedObjectList[i]->getSize());
115      else
116        PRINT(0)("=   o Class Nr. %i has cached 0 object(s)\n", i);
117    }
118  PRINT(0)("=======================================================\n");
119}
Note: See TracBrowser for help on using the repository browser.