00001 /* 00002 * CCListModel Class 00003 * Crown and Cutlass 00004 */ 00005 00006 #include <guichan.hpp> 00007 #include <string> 00008 #include <vector> 00009 #include "../Log.h" 00010 #include "CCListModel.h" 00011 00012 using namespace std; 00013 00014 CCListModel::CCListModel() { 00015 Log::s_log->DebugMessage("Creating CCListModel!"); 00016 m_List.reserve(20); 00017 } 00018 00019 CCListModel::~CCListModel() { 00020 Log::s_log->DebugMessage("Deleting CCListModel!"); 00021 } 00022 00023 void CCListModel::AddItem(std::string Item) { 00024 Log::s_log->DebugMessage("Adding %s", Item.c_str()); 00025 m_List.push_back(Item.c_str()); 00026 } 00027 00028 void CCListModel::AddItem(std::string Item, int Position) { 00029 vector<const char*>::iterator i; 00030 i = m_List.begin(); 00031 i = i + Position; 00032 m_List.insert(i, Item.c_str()); 00033 } 00034 00035 void CCListModel::RemoveItem(std::string Item) { 00036 std::vector<const char*>::iterator i; 00037 00038 for (i = m_List.begin(); 00039 i != m_List.end(); 00040 i++) 00041 if (*i == Item) { 00042 m_List.erase(i); 00043 break; 00044 } 00045 } 00046 00047 void CCListModel::RemoveItem(int Position) { 00048 if ((Position < 0) || (Position >= (int)m_List.size())) { 00049 Log::s_log->DebugMessage("CCListModel: Index out of bounds in RemoveItem"); 00050 return; 00051 } 00052 RemoveItem(m_List[Position]); 00053 } 00054 00055 int CCListModel::getNumberOfElements() { 00056 return (int)m_List.size(); 00057 } 00058 00059 std::string CCListModel::getElementAt(int i) { 00060 string Result; 00061 if ((i < 0) || (i >= (int)m_List.size())) { 00062 Log::s_log->Message("CCListModel: Index out of bounds in getElementAt"); 00063 throw 10000; 00064 } 00065 Result = m_List[i]; 00066 return Result; 00067 }
1.4.7