Leviathan  0.8.0.0
Leviathan game engine
Leviathan::ObjectFileObjectProper Class Reference

Fully defined ObjectFileObject. More...

#include <ObjectFile.h>

+ Inheritance diagram for Leviathan::ObjectFileObjectProper:

Public Member Functions

DLLEXPORT ObjectFileObjectProper (const std::string &name, const std::string &typesname, std::vector< std::unique_ptr< std::string >> &&prefix)
 
DLLEXPORT ~ObjectFileObjectProper ()
 
DLLEXPORT const std::string & GetName () const override
 Gets the name of this object. More...
 
DLLEXPORT bool AddVariableList (std::unique_ptr< ObjectFileList > &&list) override
 Add a variable list to this object. More...
 
DLLEXPORT bool AddTextBlock (std::unique_ptr< ObjectFileTextBlock > &&tblock) override
 Add a text block to this object. More...
 
DLLEXPORT void AddScriptScript (std::shared_ptr< ScriptScript > script) override
 Add a script block to this object. More...
 
DLLEXPORT const std::string & GetTypeName () const override
 Gets the name of the type. More...
 
DLLEXPORT ObjectFileListGetListWithName (const std::string &name) const override
 Gets an ObjectFileList that matches the name. More...
 
DLLEXPORT ObjectFileTextBlockGetTextBlockWithName (const std::string &name) const override
 Gets an ObjectFileTextBlock that matches the name. More...
 
DLLEXPORT std::shared_ptr< ScriptScriptGetScript () const override
 Returns a std::shared_ptr to our script. More...
 
DLLEXPORT size_t GetPrefixesCount () const override
 Gets the number of prefixes. More...
 
DLLEXPORT const std::string & GetPrefix (size_t index) const override
 Gets a prefix prom an index ExceptionInvalidArgument when the index is out of bounds. More...
 
DLLEXPORT const std::string * GetPrefixPtr (size_t index) const
 
DLLEXPORT bool IsThisTemplated () const override
 Returns true when this is a templated object. More...
 
DLLEXPORT size_t GetListCount () const override
 Gets the number of lists in this object. More...
 
DLLEXPORT ObjectFileListGetList (size_t index) const override
 Gets a list from an index ExceptionInvalidArgument when the index is out of bounds. More...
 
DLLEXPORT size_t GetTextBlockCount () const override
 Gets the number of text blocks in this object. More...
 
DLLEXPORT ObjectFileTextBlockGetTextBlock (size_t index) const override
 Gets a text block from an index ExceptionInvalidArgument when the index is out of bounds. More...
 
DLLEXPORT std::string Serialize (size_t indentspaces=0) const override
 
- Public Member Functions inherited from Leviathan::ObjectFileObject
virtual DLLEXPORT ~ObjectFileObject ()
 

Protected Attributes

std::string Name
 
std::string TName
 
std::vector< std::unique_ptr< std::string > > Prefixes
 
std::vector< ObjectFileList * > Contents
 
std::vector< ObjectFileTextBlock * > TextBlocks
 
std::shared_ptr< ScriptScriptScript
 

Additional Inherited Members

- Protected Member Functions inherited from Leviathan::ObjectFileObject
 ObjectFileObject ()
 

Detailed Description

Fully defined ObjectFileObject.

See also
ObjectFileObject

Definition at line 206 of file ObjectFile.h.

Constructor & Destructor Documentation

◆ ObjectFileObjectProper()

DLLEXPORT Leviathan::ObjectFileObjectProper::ObjectFileObjectProper ( const std::string &  name,
const std::string &  typesname,
std::vector< std::unique_ptr< std::string >> &&  prefix 
)

Definition at line 233 of file ObjectFile.cpp.

234  :
235  Name(name), TName(typesname), Prefixes(std::move(prefix))
236 {
237 
238 }
std::vector< std::unique_ptr< std::string > > Prefixes
Definition: ObjectFile.h:251

◆ ~ObjectFileObjectProper()

DLLEXPORT Leviathan::ObjectFileObjectProper::~ObjectFileObjectProper ( )

Definition at line 240 of file ObjectFile.cpp.

240  {
241  // Let the script go //
242  Script.reset();
243 
244  // Release memory //
247 }
#define SAFE_DELETE_VECTOR(x)
Definition: Define.h:165
std::vector< ObjectFileList * > Contents
Definition: ObjectFile.h:252
std::vector< ObjectFileTextBlock * > TextBlocks
Definition: ObjectFile.h:253
std::shared_ptr< ScriptScript > Script
Definition: ObjectFile.h:255

Member Function Documentation

◆ AddScriptScript()

DLLEXPORT void Leviathan::ObjectFileObjectProper::AddScriptScript ( std::shared_ptr< ScriptScript script)
overridevirtual

Add a script block to this object.

Note
Only the last set ScriptScript will remain

Implements Leviathan::ObjectFileObject.

Definition at line 323 of file ObjectFile.cpp.

323  {
324  // Warn if we already have a script //
325  if (Script) {
326  #ifndef LEVIATHAN_UE_PLUGIN
327  Logger::Get()->Warning("ObjectFileObject: already has a script, overwrote old one, name: "
328  + Name);
329  #endif
330  }
331 
332  Script = script;
333 }
DLLEXPORT void Warning(const std::string &data) override
Definition: Logger.cpp:190
static DLLEXPORT Logger * Get()
Definition: Logger.cpp:106
std::shared_ptr< ScriptScript > Script
Definition: ObjectFile.h:255

◆ AddTextBlock()

DLLEXPORT bool Leviathan::ObjectFileObjectProper::AddTextBlock ( std::unique_ptr< ObjectFileTextBlock > &&  tblock)
overridevirtual

Add a text block to this object.

Returns
False when the name collides
Postcondition
The tblock variable will be empty

Implements Leviathan::ObjectFileObject.

Definition at line 306 of file ObjectFile.cpp.

306  {
307 
308  unique_ptr<ObjectFileTextBlock> holder = std::move(tblock);
309 
310  // Make sure name is unique //
311  for (size_t i = 0; i < TextBlocks.size(); i++) {
312 
313  if (TextBlocks[i]->GetName() == holder->GetName()) {
314  return false;
315  }
316  }
317 
318  // Add it //
319  TextBlocks.push_back(holder.release());
320  return true;
321 }
std::vector< ObjectFileTextBlock * > TextBlocks
Definition: ObjectFile.h:253
virtual DLLEXPORT const std::string & GetName() const =0
Gets the name of this text block.
DLLEXPORT const std::string & GetName() const override
Gets the name of this object.
Definition: ObjectFile.cpp:249

◆ AddVariableList()

DLLEXPORT bool Leviathan::ObjectFileObjectProper::AddVariableList ( std::unique_ptr< ObjectFileList > &&  list)
overridevirtual

Add a variable list to this object.

Returns
False when the name collides
Postcondition
The list variable will be empty

Implements Leviathan::ObjectFileObject.

Definition at line 289 of file ObjectFile.cpp.

289  {
290 
291  unique_ptr<ObjectFileList> holder = std::move(list);
292 
293  // Make sure name is unique //
294  for (size_t i = 0; i < Contents.size(); i++) {
295 
296  if (Contents[i]->GetName() == holder->GetName()) {
297  return false;
298  }
299  }
300 
301  // Add it //
302  Contents.push_back(holder.release());
303  return true;
304 }
std::vector< ObjectFileList * > Contents
Definition: ObjectFile.h:252
virtual DLLEXPORT const std::string & GetName() const =0
Gets the name of this list.
DLLEXPORT const std::string & GetName() const override
Gets the name of this object.
Definition: ObjectFile.cpp:249

◆ GetList()

DLLEXPORT ObjectFileList * Leviathan::ObjectFileObjectProper::GetList ( size_t  index) const
overridevirtual

Gets a list from an index ExceptionInvalidArgument when the index is out of bounds.

Implements Leviathan::ObjectFileObject.

Definition at line 363 of file ObjectFile.cpp.

363  {
364  // Check the index //
365  if (index >= Contents.size()) {
366 
367  #ifndef ALTERNATIVE_EXCEPTIONS_FATAL
368  throw InvalidArgument("index is out of range");
369  #else
370  return nullptr;
371  #endif
372  }
373 
374  return Contents[index];
375 }
std::vector< ObjectFileList * > Contents
Definition: ObjectFile.h:252

◆ GetListCount()

DLLEXPORT size_t Leviathan::ObjectFileObjectProper::GetListCount ( ) const
overridevirtual

Gets the number of lists in this object.

Implements Leviathan::ObjectFileObject.

Definition at line 359 of file ObjectFile.cpp.

359  {
360  return Contents.size();
361 }
std::vector< ObjectFileList * > Contents
Definition: ObjectFile.h:252

◆ GetListWithName()

DLLEXPORT ObjectFileList * Leviathan::ObjectFileObjectProper::GetListWithName ( const std::string &  name) const
overridevirtual

Gets an ObjectFileList that matches the name.

Returns
The object if it exists or NULL

Implements Leviathan::ObjectFileObject.

Definition at line 335 of file ObjectFile.cpp.

335  {
336  // Loop and compare names //
337  for (size_t i = 0; i < Contents.size(); i++) {
338 
339  if (Contents[i]->GetName() == name)
340  return Contents[i];
341  }
342 
343  // Not found //
344  return NULL;
345 }
std::vector< ObjectFileList * > Contents
Definition: ObjectFile.h:252
DLLEXPORT const std::string & GetName() const override
Gets the name of this object.
Definition: ObjectFile.cpp:249

◆ GetName()

DLLEXPORT const std::string & Leviathan::ObjectFileObjectProper::GetName ( ) const
overridevirtual

Gets the name of this object.

Implements Leviathan::ObjectFileObject.

Definition at line 249 of file ObjectFile.cpp.

249  {
250  return Name;
251 }

◆ GetPrefix()

DLLEXPORT const std::string & Leviathan::ObjectFileObjectProper::GetPrefix ( size_t  index) const
overridevirtual

Gets a prefix prom an index ExceptionInvalidArgument when the index is out of bounds.

See also
GetPrefixesCount

Implements Leviathan::ObjectFileObject.

Definition at line 265 of file ObjectFile.cpp.

265  {
266  // Check the index //
267  if (index >= Prefixes.size()) {
268 
269  #ifndef ALTERNATIVE_EXCEPTIONS_FATAL
270  throw InvalidArgument("index is out of range");
271  #else
272  LEVIATHAN_ASSERT(0, "index is out of range");
273  #endif
274  }
275 
276  return *Prefixes[index];
277 }
std::vector< std::unique_ptr< std::string > > Prefixes
Definition: ObjectFile.h:251
#define LEVIATHAN_ASSERT(x, msg)
Definition: Define.h:92

◆ GetPrefixesCount()

DLLEXPORT size_t Leviathan::ObjectFileObjectProper::GetPrefixesCount ( ) const
overridevirtual

Gets the number of prefixes.

Implements Leviathan::ObjectFileObject.

Definition at line 261 of file ObjectFile.cpp.

261  {
262  return Prefixes.size();
263 }
std::vector< std::unique_ptr< std::string > > Prefixes
Definition: ObjectFile.h:251

◆ GetPrefixPtr()

DLLEXPORT const std::string * Leviathan::ObjectFileObjectProper::GetPrefixPtr ( size_t  index) const

Definition at line 279 of file ObjectFile.cpp.

279  {
280 
281  if (index >= Prefixes.size()) {
282 
283  return nullptr;
284  }
285 
286  return Prefixes[index].get();
287 }
std::vector< std::unique_ptr< std::string > > Prefixes
Definition: ObjectFile.h:251

◆ GetScript()

DLLEXPORT std::shared_ptr< ScriptScript > Leviathan::ObjectFileObjectProper::GetScript ( ) const
overridevirtual

Returns a std::shared_ptr to our script.

Implements Leviathan::ObjectFileObject.

Definition at line 257 of file ObjectFile.cpp.

257  {
258  return Script;
259 }
std::shared_ptr< ScriptScript > Script
Definition: ObjectFile.h:255

◆ GetTextBlock()

DLLEXPORT ObjectFileTextBlock * Leviathan::ObjectFileObjectProper::GetTextBlock ( size_t  index) const
overridevirtual

Gets a text block from an index ExceptionInvalidArgument when the index is out of bounds.

Implements Leviathan::ObjectFileObject.

Definition at line 381 of file ObjectFile.cpp.

381  {
382  // Check the index //
383  if (index >= TextBlocks.size()) {
384 
385  #ifndef ALTERNATIVE_EXCEPTIONS_FATAL
386  throw InvalidArgument("index is out of range");
387  #else
388  return nullptr;
389  #endif
390  }
391 
392  return TextBlocks[index];
393 }
std::vector< ObjectFileTextBlock * > TextBlocks
Definition: ObjectFile.h:253

◆ GetTextBlockCount()

DLLEXPORT size_t Leviathan::ObjectFileObjectProper::GetTextBlockCount ( ) const
overridevirtual

Gets the number of text blocks in this object.

Implements Leviathan::ObjectFileObject.

Definition at line 377 of file ObjectFile.cpp.

377  {
378  return TextBlocks.size();
379 }
std::vector< ObjectFileTextBlock * > TextBlocks
Definition: ObjectFile.h:253

◆ GetTextBlockWithName()

DLLEXPORT ObjectFileTextBlock * Leviathan::ObjectFileObjectProper::GetTextBlockWithName ( const std::string &  name) const
overridevirtual

Gets an ObjectFileTextBlock that matches the name.

Returns
The object if it exists or NULL

Implements Leviathan::ObjectFileObject.

Definition at line 347 of file ObjectFile.cpp.

347  {
348  // Loop and compare names //
349  for (size_t i = 0; i < TextBlocks.size(); i++) {
350 
351  if (TextBlocks[i]->GetName() == name)
352  return TextBlocks[i];
353  }
354 
355  // Not found //
356  return NULL;
357 }
std::vector< ObjectFileTextBlock * > TextBlocks
Definition: ObjectFile.h:253
DLLEXPORT const std::string & GetName() const override
Gets the name of this object.
Definition: ObjectFile.cpp:249

◆ GetTypeName()

DLLEXPORT const std::string & Leviathan::ObjectFileObjectProper::GetTypeName ( ) const
overridevirtual

Gets the name of the type.

Implements Leviathan::ObjectFileObject.

Definition at line 253 of file ObjectFile.cpp.

253  {
254  return TName;
255 }

◆ IsThisTemplated()

DLLEXPORT bool Leviathan::ObjectFileObjectProper::IsThisTemplated ( ) const
overridevirtual

Returns true when this is a templated object.

This is used while saving to a file to avoid writing template objects

Implements Leviathan::ObjectFileObject.

Reimplemented in Leviathan::ObjectFileTemplateObject.

Definition at line 464 of file ObjectFile.cpp.

464  {
465  return false;
466 }

◆ Serialize()

DLLEXPORT std::string Leviathan::ObjectFileObjectProper::Serialize ( size_t  indentspaces = 0) const
overridevirtual
Returns
A string representation of this object

Implements Leviathan::ObjectFileObject.

Definition at line 395 of file ObjectFile.cpp.

395  {
396 
397  constexpr auto BlockIndent = 4;
398 
399  const std::string indentation = StringOperations::Indent<std::string>(indentspaces);
400  const std::string contentindentation = StringOperations::Indent<std::string>(BlockIndent);
401 
402  std::string result = indentation + "o ";
403 
404  if (TName.size())
405  result += TName + " ";
406 
407  for (const auto& prefix : Prefixes) {
408 
409  result += *prefix + " ";
410  }
411 
412  result += "\"" + Name + "\"{\n\n";
413 
414  // First lists //
415  for (ObjectFileList* list : Contents) {
416 
417  result += indentation + contentindentation + "l " + list->GetName() + " {\n";
418 
419  result += list->GetVariables().Serialize(indentation + contentindentation + contentindentation);
420 
421  result += indentation + contentindentation + "} // End " + list->GetName() + "\n\n";
422  }
423 
424  // Then text blocks //
425  for (ObjectFileTextBlock* block : TextBlocks) {
426 
427  result += indentation + contentindentation + "t " + block->GetName() + " {\n";
428 
429  for (size_t i = 0; i < block->GetLineCount(); ++i) {
430 
431  result += indentation + contentindentation + contentindentation + block->GetLine(i) + "\n";
432  }
433 
434  result += indentation + contentindentation + "} // End " + block->GetName() + "\n\n";
435  }
436 
437  if (Script) {
438 
439  #ifndef LEVIATHAN_USING_ANGELSCRIPT
440  LEVIATHAN_ASSERT(0, "saving an ObjectFile object that has scripts without scripting support compiled in");
441  #else
442  if (!Script->GetModule()) {
443 
444  DEBUG_BREAK;
445 
446  } else {
447 
448  DEBUG_BREAK;
449  // Don't add a name if it is just a generic generated name //
450  result += indentation + contentindentation + "s " + Script->GetModule()->GetName() + "{\n";
451 
452  result += StringOperations::IndentLines(Script->GetModule()->GetIncompleteSourceCode(),
453  BlockIndent + indentspaces);
454 
455  result += indentation + contentindentation + "@%};\n\n";
456  }
457  #endif //LEVIATHAN_USING_ANGELSCRIPT
458  }
459 
460  result += "} // End Object "+ Name + "\n\n";
461  return result;
462 }
Interface for object file lists to implement.
Definition: ObjectFile.h:21
static StringTypeN IndentLines(const StringTypeN &str, size_t spaces)
Appends spaces number of spaces to each line in str and returns the result.
Interface for object file text blocks to implement.
Definition: ObjectFile.h:71
std::vector< std::unique_ptr< std::string > > Prefixes
Definition: ObjectFile.h:251
#define LEVIATHAN_ASSERT(x, msg)
Definition: Define.h:92
std::vector< ObjectFileList * > Contents
Definition: ObjectFile.h:252
std::vector< ObjectFileTextBlock * > TextBlocks
Definition: ObjectFile.h:253
std::shared_ptr< ScriptScript > Script
Definition: ObjectFile.h:255

Member Data Documentation

◆ Contents

std::vector<ObjectFileList*> Leviathan::ObjectFileObjectProper::Contents
protected

Definition at line 252 of file ObjectFile.h.

◆ Name

std::string Leviathan::ObjectFileObjectProper::Name
protected

Definition at line 248 of file ObjectFile.h.

◆ Prefixes

std::vector<std::unique_ptr<std::string> > Leviathan::ObjectFileObjectProper::Prefixes
protected

Definition at line 251 of file ObjectFile.h.

◆ Script

std::shared_ptr<ScriptScript> Leviathan::ObjectFileObjectProper::Script
protected

Definition at line 255 of file ObjectFile.h.

◆ TextBlocks

std::vector<ObjectFileTextBlock*> Leviathan::ObjectFileObjectProper::TextBlocks
protected

Definition at line 253 of file ObjectFile.h.

◆ TName

std::string Leviathan::ObjectFileObjectProper::TName
protected

Definition at line 249 of file ObjectFile.h.


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