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

SceneObjectManagerTemplate.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Lamp : Open source game middleware
00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //------------------------------------------------------------------------------
00019 
00020 /** @file
00021  * シーンオブジェクトマネージャテンプレートヘッダ
00022  * @author Junpee
00023  */
00024 
00025 #ifndef SCENE_OBJECT_MANAGER_TEMPLATE_H_
00026 #define SCENE_OBJECT_MANAGER_TEMPLATE_H_
00027 
00028 #include <Graphics/Scene/Scene.h>
00029 #include <Core/Renamer/Renamer.h>
00030 #include <Core/Container/HashMap.h>
00031 #include <Core/Container/ArrayList.h>
00032 
00033 namespace Lamp{
00034 
00035 //------------------------------------------------------------------------------
00036 /**
00037  * シーンオブジェクトマネージャテンプレート
00038  */
00039 template <typename Type>
00040 class SceneObjectManagerTemplate : public Renamer::Database{
00041 friend class Scene;
00042 public:
00043     /**
00044      * オブジェクトの破棄
00045      * @param object 破棄するオブジェクト
00046      * @return 破棄するオブジェクトのリファレンスカウンタ。0なら破棄されている
00047      */
00048     virtual int destroy(Type* object){
00049         // 参照が残っていれば削除しない
00050         int referenceCount = object->getReferenceCount();
00051         Assert(referenceCount >= 0);
00052         if(referenceCount != 0){ return referenceCount; }
00053         // データベースから検索して削除
00054         if(array_.removeByValue(object) == -1){
00055             ErrorOut("SceneObjectManagerTemplate::destroy() "
00056                 "Not found object in array");
00057         }
00058         if(database_.remove(object->getName()) == NULL){
00059             ErrorOut("SceneObjectManagerTemplate::destroy() "
00060                 "Not found object in hashmap");
00061         }
00062         delete object;
00063         return 0;
00064     }
00065 
00066     //--------------------------------------------------------------------------
00067     /**
00068      * シーンの取得
00069      * @return シーン
00070      */
00071     virtual Scene* getScene() const{ return scene_; }
00072 
00073     //--------------------------------------------------------------------------
00074     /**
00075      * オブジェクト数の取得
00076      * @return オブジェクト数
00077      */
00078     virtual int getCount(){ return array_.getCount(); }
00079 
00080     /**
00081      * オブジェクトの取得
00082      * @param index オブジェクトのインデクス
00083      * @return オブジェクト
00084      */
00085     virtual Type* get(int index){ return array_.get(index); }
00086 
00087     /**
00088      * オブジェクトの検索
00089      * @param name 検索するオブジェクト名
00090      * @return オブジェクト
00091      */
00092     virtual Type* search(const String& name){ return database_.get(name); }
00093 
00094     //--------------------------------------------------------------------------
00095     // リネーム関係
00096     //--------------------------------------------------------------------------
00097     /**
00098      * 名前が存在するかどうか
00099      * @param name 存在するかどうか調べる名前
00100      * @return 名前が存在すればtrue
00101      */
00102     virtual bool existName(const String& name){ return (search(name) != NULL); }
00103 
00104     /**
00105      * リネーム
00106      * @param sourceName 元となる名前
00107      * @return 重複していない名前
00108      */
00109     virtual String rename(const String& sourceName){
00110         return scene_->getRenamer()->rename(this, sourceName);
00111     }
00112 
00113     //--------------------------------------------------------------------------
00114 protected:
00115     /**
00116      * コンストラクタ
00117      * @param scene シーン
00118      */
00119     SceneObjectManagerTemplate(Scene* scene) :
00120          database_(256, 0.75f), array_(256), scene_(scene){
00121     }
00122 
00123     /**
00124      * デストラクタ
00125      */
00126     virtual ~SceneObjectManagerTemplate(){
00127         Assert(database_.getCount() == 0);
00128         Assert(array_.getCount() == 0);
00129         if(getCount() != 0){ clear(); }
00130     }
00131 
00132     /**
00133      * 名前のチェック
00134      * @param name チェックする名前
00135      * @return 正常な名前ならtrueを返す
00136      */
00137     bool checkName(String name){
00138         // 名前の長さチェック
00139         if(name.getSize() == 0){
00140             ErrorOut("SceneObjectManager::checkName() name.getSize() == 0");
00141             return false;
00142         }
00143         // 名前の重複チェック
00144         if(existName(name)){
00145             ErrorOut("SceneObjectManager::checkName() repetition name %s",
00146                 name.getBytes());
00147             return false;
00148         }
00149         return true;
00150     }
00151 
00152     /**
00153      * データベースへの追加
00154      * @param name 名前
00155      * @param object オブジェクト
00156      */
00157     virtual void addDatabase(const String& name, Type* object){
00158         database_.put(name, object);
00159         array_.add(object);
00160     }
00161 
00162     /**
00163      * クリア
00164      * @return 削除したオブジェクト数
00165      */
00166     virtual int clear(){
00167         int result = getCount();
00168         // 要素の削除
00169         for(int i = 0; i < result; i++){ delete array_.get(i); }
00170         array_.clear();
00171         database_.clear();
00172         return result;
00173     }
00174 
00175     //--------------------------------------------------------------------------
00176     /// データベース
00177     HashMap<String, Type*> database_;
00178     /// 配列
00179     ArrayList<Type*> array_;
00180     /// シーン
00181     Scene* scene_;
00182 
00183     //--------------------------------------------------------------------------
00184 private:
00185     // コピーコンストラクタの隠蔽
00186     SceneObjectManagerTemplate(const SceneObjectManagerTemplate& copy);
00187 
00188     // 代入コピーの隠蔽
00189     void operator =(const SceneObjectManagerTemplate& copy);
00190 
00191 };
00192 
00193 //------------------------------------------------------------------------------
00194 } // End of namespace Lamp
00195 #endif // End of SCENE_OBJECT_MANAGER_TEMPLATE_H_
00196 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:35 2005 for Lamp by doxygen 1.3.2