TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ScriptRegistry< TScript > Class Template Reference

Public Types

typedef std::map< uint32,
TScript * > 
ScriptMap
 
typedef ScriptMap::iterator ScriptMapIterator
 

Static Public Member Functions

static void AddScript (TScript *const script, bool addToDeleteContainer=true)
 
static TScript * GetScriptById (uint32 id)
 

Static Public Attributes

static ScriptMap ScriptPointerList
 
static std::vector< TScript * > Scripts
 

Static Private Member Functions

static void AddScript (std::true_type, TScript *const script)
 
static void AddScript (std::false_type, TScript *const script)
 

Static Private Attributes

static uint32 _scriptIdCounter = 0
 

Member Typedef Documentation

template<class TScript >
typedef std::map<uint32, TScript*> ScriptRegistry< TScript >::ScriptMap
template<class TScript >
typedef ScriptMap::iterator ScriptRegistry< TScript >::ScriptMapIterator

Member Function Documentation

template<class TScript >
static void ScriptRegistry< TScript >::AddScript ( TScript *const  script,
bool  addToDeleteContainer = true 
)
inlinestatic
112  {
113  ASSERT(script);
114 
115  // See if the script is using the same memory as another script. If this happens, it means that
116  // someone forgot to allocate new memory for a script.
117  for (ScriptMapIterator it = ScriptPointerList.begin(); it != ScriptPointerList.end(); ++it)
118  {
119  if (it->second == script)
120  {
121  TC_LOG_ERROR("scripts", "Script '%s' has same memory pointer as '%s'.",
122  script->GetName().c_str(), it->second->GetName().c_str());
123 
124  return;
125  }
126  }
127 
129  if (addToDeleteContainer)
130  Scripts.push_back(script);
131  }
static ScriptMap ScriptPointerList
Definition: ScriptMgr.cpp:108
static void AddScript(TScript *const script, bool addToDeleteContainer=true)
Definition: ScriptMgr.cpp:111
ScriptMap::iterator ScriptMapIterator
Definition: ScriptMgr.cpp:104
static std::vector< TScript * > Scripts
Definition: ScriptMgr.cpp:109
#define ASSERT
Definition: Errors.h:55
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
Definition: ScriptMgr.cpp:46

+ Here is the caller graph for this function:

template<class TScript >
static void ScriptRegistry< TScript >::AddScript ( std::true_type  ,
TScript *const  script 
)
inlinestaticprivate
147  {
148  // Get an ID for the script. An ID only exists if it's a script that is assigned in the database
149  // through a script name (or similar).
150  uint32 id = sObjectMgr->GetScriptId(script->GetName());
151  if (id)
152  {
153  // Try to find an existing script.
154  bool existing = false;
155  for (ScriptMapIterator it = ScriptPointerList.begin(); it != ScriptPointerList.end(); ++it)
156  {
157  // If the script names match...
158  if (it->second->GetName() == script->GetName())
159  {
160  // ... It exists.
161  existing = true;
162  break;
163  }
164  }
165 
166  // If the script isn't assigned -> assign it!
167  if (!existing)
168  {
169  ScriptPointerList[id] = script;
170  sScriptMgr->IncrementScriptCount();
171 
172  #ifdef SCRIPTS
173  UnusedScriptNamesContainer::iterator itr = std::lower_bound(UnusedScriptNames.begin(), UnusedScriptNames.end(), script->GetName());
174  if (itr != UnusedScriptNames.end() && *itr == script->GetName())
175  UnusedScriptNames.erase(itr);
176  #endif
177  }
178  else
179  {
180  // If the script is already assigned -> delete it!
181  TC_LOG_ERROR("scripts", "Script '%s' already assigned with the same script name, so the script can't work.",
182  script->GetName().c_str());
183 
184  ABORT(); // Error that should be fixed ASAP.
185  }
186  }
187  else
188  {
189  // The script uses a script name from database, but isn't assigned to anything.
190  TC_LOG_ERROR("sql.sql", "Script named '%s' does not have a script name assigned in database.", script->GetName().c_str());
191  }
192  }
static ScriptMap ScriptPointerList
Definition: ScriptMgr.cpp:108
#define sObjectMgr
Definition: ObjectMgr.h:1567
uint32_t uint32
Definition: Define.h:150
ScriptMap::iterator ScriptMapIterator
Definition: ScriptMgr.cpp:104
#define ABORT
Definition: Errors.h:56
#define sScriptMgr
Definition: ScriptMgr.h:837
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
UnusedScriptNamesContainer UnusedScriptNames
Definition: ScriptMgr.cpp:40
template<class TScript >
static void ScriptRegistry< TScript >::AddScript ( std::false_type  ,
TScript *const  script 
)
inlinestaticprivate
196  {
197  // We're dealing with a code-only script; just add it.
199  sScriptMgr->IncrementScriptCount();
200  }
static uint32 _scriptIdCounter
Definition: ScriptMgr.cpp:203
static ScriptMap ScriptPointerList
Definition: ScriptMgr.cpp:108
#define sScriptMgr
Definition: ScriptMgr.h:837
template<class TScript >
static TScript* ScriptRegistry< TScript >::GetScriptById ( uint32  id)
inlinestatic
135  {
136  ScriptMapIterator it = ScriptPointerList.find(id);
137  if (it != ScriptPointerList.end())
138  return it->second;
139 
140  return NULL;
141  }
static ScriptMap ScriptPointerList
Definition: ScriptMgr.cpp:108
arena_t NULL
Definition: jemalloc_internal.h:624
ScriptMap::iterator ScriptMapIterator
Definition: ScriptMgr.cpp:104

+ Here is the caller graph for this function:

Member Data Documentation

template<class TScript >
uint32 ScriptRegistry< TScript >::_scriptIdCounter = 0
staticprivate
template<class TScript >
std::map< uint32, TScript * > ScriptRegistry< TScript >::ScriptPointerList
static
template<class TScript >
std::vector< TScript * > ScriptRegistry< TScript >::Scripts
static

The documentation for this class was generated from the following file: