Leviathan  0.8.0.0
Leviathan game engine
ObjectFile.cpp
Go to the documentation of this file.
1 #include "Include.h"
2 // ------------------------------------ //
3 #include "ObjectFile.h"
4 
6 #include "utf8/checked.h"
7 #if !defined(ALTERNATIVE_EXCEPTIONS_FATAL) || defined(ALLOW_INTERNAL_EXCEPTIONS)
8 #include "Exceptions.h"
9 #endif
10 #ifdef LEVIATHAN_USING_ANGELSCRIPT
11 #include "../Script/ScriptExecutor.h"
12 #include "../Script/ScriptModule.h"
13 #include "../Script/ScriptScript.h"
14 #endif // LEVIATHAN_USING_ANGELSCRIPT
15 
16 using namespace Leviathan;
17 using namespace std;
18 // ------------------------------------ //
19 DLLEXPORT Leviathan::ObjectFile::ObjectFile(NamedVars &stealfrom) : HeaderVars(&stealfrom){
20 
21 }
22 
24 
25 }
26 
28 
29 }
30 // ------------------------------------ //
31 DLLEXPORT bool Leviathan::ObjectFile::AddNamedVariable(shared_ptr<NamedVariableList> var){
32  // Make sure that name is not in use //
33  if(HeaderVars.Find(var->GetName()) < HeaderVars.GetVariableCount()){
34 
35  return false;
36  }
37 
38  // Add it //
39  HeaderVars.AddVar(var);
40  return true;
41 }
42 // ------------------------------------ //
43 DLLEXPORT bool Leviathan::ObjectFile::AddObject(shared_ptr<ObjectFileObject> obj){
44  // Make sure that the name is not in use //
45  if(IsObjectNameInUse(obj->GetName())){
46 
47  return false;
48  }
49 
50  // Add the object //
51  DefinedObjects.push_back(obj);
52  return true;
53 }
54 // ------------------------------------ //
55 DLLEXPORT bool Leviathan::ObjectFile::IsObjectNameInUse(const std::string &name) const{
56  // Try to find an object with the same name //
57  for(size_t i = 0; i < DefinedObjects.size(); i++){
58 
59  if(DefinedObjects[i]->GetName() == name)
60  return true;
61  }
62 
63  // Check for matching template names //
64 
65 
66  // Didn't match anything //
67  return false;
68 }
69 // ------------------------------------ //
71  return &HeaderVars;
72 }
73 // ------------------------------------ //
75  // Return from DefinedObjects if it is in range otherwise from the template instances //
76  if(index < DefinedObjects.size()){
77 
78  return DefinedObjects[index].get();
79  }
80 
81 #ifndef ALTERNATIVE_EXCEPTIONS_FATAL
82  // Invalid index //
83  throw InvalidArgument("index is out of range");
84 #else
85  return nullptr;
86 #endif //ALTERNATIVE_EXCEPTIONS_FATAL
87 }
88 // ------------------------------------ //
90  // Find the first that matches the type //
91  for(size_t i = 0; i < DefinedObjects.size(); i++){
92 
93  if(DefinedObjects[i]->GetTypeName() == typestr)
94  return DefinedObjects[i].get();
95  }
96 
97  // Nothing found //
98  return NULL;
99 }
100 
101 DLLEXPORT std::vector<ObjectFileObject*> Leviathan::ObjectFile::GetAllObjectsWithType(const std::string &type) const {
102 
103  std::vector<ObjectFileObject*> result;
104 
105  for (size_t i = 0; i < DefinedObjects.size(); i++) {
106 
107  if (DefinedObjects[i]->GetTypeName() == type)
108  result.push_back((DefinedObjects[i].get()));
109  }
110 
111  return result;
112 }
113 // ------------------------------------ //
115 {
116  // Create template instances from the templates //
117  for(size_t i = 0; i < TemplateInstantiations.size(); i++){
118 
119  // Find a template definition for this //
120  auto tmpldef = FindTemplateDefinition(TemplateInstantiations[i]->GetNameOfParentTemplate());
121 
122  if(!tmpldef){
123 
124  reporterror->Error("ObjectFile: could not find template definition with name: "
125  +TemplateInstantiations[i]->GetNameOfParentTemplate());
126  return false;
127  }
128 
129  // Try to generate it //
130  auto resultobj = tmpldef->CreateInstanceFromThis(*TemplateInstantiations[i], reporterror);
131 
132  if(!resultobj){
133 
134  reporterror->Error("ObjectFile: could not instantiate template "
135  "(parameter count probably didn't match), name: "
136  +TemplateInstantiations[i]->GetNameOfParentTemplate());
137  return false;
138  }
139 
140  shared_ptr<ObjectFileObject> tmpobj(resultobj.release());
141 
142  // Add it to us //
143  if(!AddObject(tmpobj)){
144 
145  reporterror->Error("ObjectFile: template instance's result was an object whose "
146  "name is already in use, template name: "
147  +TemplateInstantiations[i]->GetNameOfParentTemplate()+", result object: "+
148  tmpobj->GetName());
149  return false;
150  }
151  }
152 
153 
154  // No errors occurred //
155  return true;
156 }
157 // ------------------------------------ //
159  shared_ptr<ObjectFileTemplateInstance> tiobj)
160 {
161  // Template instances may have names that are not present yet, the instance can be before the definition //
162  TemplateInstantiations.push_back(tiobj);
163 }
164 
166  shared_ptr<ObjectFileTemplateDefinition> templatedef)
167 {
168  // Make sure the name is unique //
169  for(size_t i = 0; i < TemplateDefinitions.size(); i++){
170 
171  if(TemplateDefinitions[i]->GetName() == templatedef->GetName()){
172 
173  // Conflicting name //
174  return false;
175  }
176  }
177 
178  // Add it //
179  TemplateDefinitions.push_back(templatedef);
180  return true;
181 }
182 
183 DLLEXPORT std::shared_ptr<ObjectFileTemplateDefinition> Leviathan::ObjectFile::FindTemplateDefinition(
184  const string &name) const
185 {
186  // Try to find one with the exact name //
187  for(size_t i = 0; i < TemplateDefinitions.size(); i++){
188 
189  if(TemplateDefinitions[i]->GetName() == name){
190 
191  // Found a match //
192  return TemplateDefinitions[i];
193  }
194  }
195 
196  // Nothing found //
197  return NULL;
198 }
199 
200 // ------------------ ObjectFileListProper ------------------ //
202  Name(name) {
203 
204 }
205 // ------------------------------------ //
207  return Name;
208 }
209 // ------------------------------------ //
210 DLLEXPORT bool Leviathan::ObjectFileListProper::AddVariable(shared_ptr<NamedVariableList> var) {
211 
212  if (!var)
213  return false;
214 
215  // Make sure that name is not in use //
216  if (Variables.Find(var->GetName()) < Variables.GetVariableCount()) {
217  return false;
218  }
219 
220  // Add it //
221  Variables.AddVar(var);
222  return true;
223 }
224 // ------------------------------------ //
226  return Variables;
227 }
228 // ------------------ ObjectFileList ------------------ //
230 
231 }
232 
234  const std::string &typesname, std::vector<std::unique_ptr<std::string>>&& prefix) :
235  Name(name), TName(typesname), Prefixes(std::move(prefix))
236 {
237 
238 }
239 
241  // Let the script go //
242  Script.reset();
243 
244  // Release memory //
245  SAFE_DELETE_VECTOR(Contents);
246  SAFE_DELETE_VECTOR(TextBlocks);
247 }
248 // ------------------------------------ //
250  return Name;
251 }
252 
254  return TName;
255 }
256 
257 DLLEXPORT std::shared_ptr<ScriptScript> Leviathan::ObjectFileObjectProper::GetScript() const {
258  return Script;
259 }
260 
262  return Prefixes.size();
263 }
264 
265 DLLEXPORT const std::string& Leviathan::ObjectFileObjectProper::GetPrefix(size_t index) const {
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 }
278 
279 DLLEXPORT const std::string* Leviathan::ObjectFileObjectProper::GetPrefixPtr(size_t index) const {
280 
281  if (index >= Prefixes.size()) {
282 
283  return nullptr;
284  }
285 
286  return Prefixes[index].get();
287 }
288 // ------------------------------------ //
289 DLLEXPORT bool Leviathan::ObjectFileObjectProper::AddVariableList(unique_ptr<ObjectFileList>&& list) {
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 }
305 
306 DLLEXPORT bool Leviathan::ObjectFileObjectProper::AddTextBlock(unique_ptr<ObjectFileTextBlock>&& tblock) {
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 }
322 
323 DLLEXPORT void Leviathan::ObjectFileObjectProper::AddScriptScript(shared_ptr<ScriptScript> script) {
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 }
334 // ------------------------------------ //
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 }
346 
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 }
358 
360  return Contents.size();
361 }
362 
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 }
376 
378  return TextBlocks.size();
379 }
380 
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 }
394 
395 DLLEXPORT std::string Leviathan::ObjectFileObjectProper::Serialize(size_t indentspaces /*= 0*/) const {
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 }
463 
465  return false;
466 }
467 
468 // ------------------ ObjectFileObject ------------------ //
470 
471 }
472 
474  Name(name) {
475 
476 }
477 
479  SAFE_DELETE_VECTOR(Lines);
480 }
481 // ------------------------------------ //
483  return Name;
484 }
485 // ------------------------------------ //
487  return Lines.size();
488 }
489 
490 DLLEXPORT const string& Leviathan::ObjectFileTextBlockProper::GetLine(size_t index) const {
491  // Check the index //
492  if (index >= Lines.size()) {
493  #ifndef ALTERNATIVE_EXCEPTIONS_FATAL
494  throw InvalidArgument("index is out of range");
495  #else
496  LEVIATHAN_ASSERT(false, "index is over Lines.size()");
497  #endif
498  }
499 
500  return *Lines[index];
501 }
502 // ------------------------------------ //
504  Lines.push_back(new string(line));
505 }
506 
507 // ------------------ ObjectFileTextBlock ------------------ //
509 
510 }
511 
513  std::vector<unique_ptr<string>> &parameters, std::shared_ptr<ObjectFileObject> obj) :
514  Name(name), Parameters(move(parameters)), RepresentingObject(obj) {
515 
516 }
517 // ------------------------------------ //
519  return Name;
520 }
521 // ------------------------------------ //
522 DLLEXPORT std::shared_ptr<ObjectFileTemplateDefinition>
524  std::shared_ptr<ObjectFileObject> obj, std::vector<unique_ptr<string>> &templateargs) {
525  // This could be changed to a function that tears down the object and creates mess
526  // of templating objects
527  auto resultobj = make_shared<ObjectFileTemplateDefinition>(name, templateargs, obj);
528 
529  return resultobj;
530 }
533 
534  std::string result = "template<";
535 
536  bool first = true;
537 
538  // Parameter names for the template //
539  for (const auto& paramstr : Parameters) {
540 
541  if (!first)
542  result += ", ";
543 
544  result += *paramstr;
545  first = false;
546  }
547 
548  result += "> " + Name + ": \n";
549 
550  // The object associated with the template //
551  result += RepresentingObject->Serialize(4);
552 
553  return result;
554 
555 }
557 DLLEXPORT std::unique_ptr<Leviathan::ObjectFileTemplateObject> ObjectFileTemplateDefinition::CreateInstanceFromThis(
558  const ObjectFileTemplateInstance &instanceargs, LErrorReporter* reporterror /*= nullptr*/) {
559  // First make sure that template counts match, return NULL otherwise //
560  if (Parameters.size() != instanceargs.Arguments.size()) {
561 
562  return NULL;
563  }
564 
565 
566  // Make sure these are not templated //
567  std::string newname = RepresentingObject->GetName();
568  std::string newtype = RepresentingObject->GetTypeName();
569 
570  std::vector<std::unique_ptr<std::string>> newprefixes;
571 
572  ReplaceStringWithTemplateArguments(newname, instanceargs.Arguments);
573 
574 
575  ReplaceStringWithTemplateArguments(newtype, instanceargs.Arguments);
576 
577  for (size_t i = 0; i < RepresentingObject->GetPrefixesCount(); i++) {
578 
579  unique_ptr<std::string> newprefix(new std::string(RepresentingObject->GetPrefix(i)));
580 
581  ReplaceStringWithTemplateArguments(*newprefix, instanceargs.Arguments);
582 
583  newprefixes.push_back(std::move(newprefix));
584  }
585 
586 
587  // We somehow need to detect all places that might have the template parameters and
588  // change them
589  unique_ptr<ObjectFileTemplateObject> internalobj(new ObjectFileTemplateObject(newname,
590  newtype, std::move(newprefixes)));
591 
592  // Do the contents the same way //
593  for (size_t i = 0; i < RepresentingObject->GetListCount(); i++) {
594 
595  // Copy the data from the list replacing all the templates with values //
596  ObjectFileList* curlist = RepresentingObject->GetList(i);
597 
598  std::string actlistname = curlist->GetName();
599 
600  ReplaceStringWithTemplateArguments(actlistname, instanceargs.Arguments);
601 
602  unique_ptr<ObjectFileList> listobj(new ObjectFileListProper(actlistname));
603 
604  const std::vector<shared_ptr<NamedVariableList>>& vallist =
605  *curlist->GetVariables().GetVec();
606 
607  // Add the values replacing template arguments //
608  for (size_t a = 0; a < vallist.size(); a++) {
609 
610  // First check the name //
611  std::string newvarlistname = vallist[a]->GetName();
612 
613  ReplaceStringWithTemplateArguments(newvarlistname, instanceargs.Arguments);
614 
615  vector<VariableBlock*> newvaluesforthing;
616  newvaluesforthing.reserve(vallist[a]->GetVariableCount());
617 
618  // Try to replace values that are strings //
619  for (size_t b = 0; b < vallist[a]->GetVariableCount(); b++) {
620 
621  VariableBlock* processblock = vallist[a]->GetValueDirect(b);
622 
623  auto typval = processblock->GetBlock()->Type;
624 
625  // Non-string types don't need replacing //
626  if (typval != DATABLOCK_TYPE_STRING && typval != DATABLOCK_TYPE_WSTRING) {
627 
628  newvaluesforthing.push_back(new
629  VariableBlock(processblock->GetBlock()->AllocateNewFromThis()));
630 
631  } else {
632 
633  // Try replacing stuff //
634  std::string valstring;
635 
636  if (!processblock->ConvertAndAssingToVariable<std::string>(valstring)) {
637 
638  DEBUG_BREAK;
639  }
640 
641  // Try to replace //
642  ReplaceStringWithTemplateArguments(valstring, instanceargs.Arguments);
643 
644  // Parse the result into a variable block //
645  try {
646 
647  unique_ptr<VariableBlock> tmpblock(new VariableBlock(valstring, NULL));
648 
649  newvaluesforthing.push_back(tmpblock.release());
650 
651  }
652  catch (const InvalidArgument &e) {
653 
654  if (reporterror) {
655 
656  reporterror->Warning("ObjectFileTemplates: a templated list has an "
657  "invalid value to parse, using empty string instead:");
658  e.Print(reporterror);
659  }
660 
661  newvaluesforthing.push_back(new VariableBlock(new StringBlock(
662  new std::string())));
663  continue;
664  }
665  }
666  }
667 
668  // Add the variable list //
669  listobj->AddVariable(shared_ptr<NamedVariableList>(new
670  NamedVariableList(newvarlistname, newvaluesforthing)));
671  }
672 
673  // Add the list to the new object //
674  internalobj->AddVariableList(std::move(listobj));
675 
676  }
677 
678  // Process the text blocks //
679  for (size_t i = 0; i < RepresentingObject->GetTextBlockCount(); i++) {
680 
681  // Copy the data from the list replacing all the templates with values //
682  ObjectFileTextBlock* curblock = RepresentingObject->GetTextBlock(i);
683 
684  std::string actblockname = curblock->GetName();
685 
686  ReplaceStringWithTemplateArguments(actblockname, instanceargs.Arguments);
687 
688  unique_ptr<ObjectFileTextBlock> textblock(new ObjectFileTextBlockProper(actblockname));
689 
690  // Replace all the lines //
691 
692 
693  for (size_t a = 0; a < curblock->GetLineCount(); a++) {
694 
695  std::string curline = curblock->GetLine(a);
696 
697  ReplaceStringWithTemplateArguments(curline, instanceargs.Arguments);
698 
699  textblock->AddTextLine(curline);
700  }
701 
702  // Add to the object //
703  internalobj->AddTextBlock(std::move(textblock));
704  }
705 
706  // Process the script source //
707 
708 
709  // Only the first segment should be used //
710 #ifdef LEVIATHAN_USING_ANGELSCRIPT
711  auto scrptwrap = RepresentingObject->GetScript();
712  if (scrptwrap) {
713 
714  auto scrptmodule = scrptwrap->GetModuleSafe();
715 
716  if (scrptmodule && scrptmodule->GetScriptSegmentCount() > 0) {
717 
718  // We can try to specialize the code //
719  auto onlysegment = scrptmodule->GetScriptSegment(0);
720 
721  const string& resultingsource = *onlysegment->SourceCode;
722 
723  const string& newsource = ReplaceStringTemplateArguments(resultingsource,
724  instanceargs.Arguments);
725 
726  std::string newname = scrptmodule->GetName();
727 
728  ReplaceStringWithTemplateArguments(newname, instanceargs.Arguments);
729 
730  shared_ptr<ScriptScript> newscript(new
731  ScriptScript(ScriptExecutor::Get()->CreateNewModule(newname,
732  scrptmodule->GetSource())));
733 
734  // Add the new script to the object //
735  shared_ptr<ScriptSourceFileData> newsourcesegment(new
736  ScriptSourceFileData(onlysegment->SourceFile, onlysegment->StartLine, newsource));
737 
738  auto newmod = newscript->GetModuleSafe();
739 
740  newmod->AddScriptSegment(newsourcesegment);
741  newmod->SetBuildState(SCRIPTBUILDSTATE_READYTOBUILD);
742 
743  internalobj->AddScriptScript(newscript);
744  }
745  }
746 #endif // LEVIATHAN_USING_ANGELSCRIPT
747 
748  // Return the object //
749  return internalobj;
750 }
751 // ------------------------------------ //
753  std::string &target, const std::vector<std::unique_ptr<std::string>> &args) {
754 
755  LEVIATHAN_ASSERT(Parameters.size() == args.size(), "ReplaceStringWithTemplateArguments arguments size mismatch");
756 
757  // Look for strings matching our parameters //
758  for (size_t i = 0; i < Parameters.size(); i++) {
759 
760  target = StringOperations::Replace<std::string>(target, *Parameters[i], *args[i]);
761  }
762 }
763 
765  const string &target, const std::vector<unique_ptr<string>> &args) {
766 
767  LEVIATHAN_ASSERT(Parameters.size() == args.size(), "ReplaceStringTemplateArguments arguments size mismatch");
768 
769  string result;
770 
771  if (Parameters.size() == 0)
772  return target;
773 
774  result = StringOperations::Replace<string>(target, *Parameters[0], *args[0]);
775 
776  // Look for strings matching our parameters //
777  for (size_t i = 1; i < Parameters.size(); i++) {
778 
779  result = StringOperations::Replace<string>(result, *Parameters[i], *args[i]);
780  }
781 
782  return result;
783 }
784 // ------------------ ObjectFileTemplateInstance ------------------ //
786  const string &mastertmplname, std::vector<unique_ptr<string>> &templateargs) :
787  TemplatesName(mastertmplname), Arguments(move(templateargs)) {
788 
789 }
790 DLLEXPORT std::string Leviathan::ObjectFileTemplateInstance::Serialize(size_t indentspaces) const {
791 
792  constexpr auto BlockIndent = 4;
793 
794  const std::string indentation = StringOperations::Indent<std::string>(indentspaces);
795  const std::string contentindentation = StringOperations::Indent<std::string>(BlockIndent);
796 
797  std::string result = indentation + "template<> " + TemplatesName + "<";
798 
799  bool first = true;
800 
801  for (const auto& argument : Arguments) {
802 
803  if (!first)
804  result += ", ";
805 
806  result += *argument;
807  first = false;
808  }
809 
810  result += ">\n";
811  return result;
812 }
813 // ------------------ ObjectFileTemplateObject ------------------ //
815  const std::string &typesname, vector<std::unique_ptr<std::string>>&& prefix) :
816  ObjectFileObjectProper(name, typesname, std::move(prefix)) {
817 
818 }
DLLEXPORT bool IsObjectNameInUse(const std::string &name) const
Checks whether the given name is in use.
Definition: ObjectFile.cpp:55
virtual DLLEXPORT ~ObjectFileList()
Definition: ObjectFile.cpp:229
Interface for object file lists to implement.
Definition: ObjectFile.h:21
DLLEXPORT ObjectFileList * GetList(size_t index) const override
Gets a list from an index ExceptionInvalidArgument when the index is out of bounds.
Definition: ObjectFile.cpp:363
std::vector< std::unique_ptr< std::string > > Arguments
Template arguments.
Definition: ObjectFile.h:302
hosts one or more VariableBlocks keeping only one name for all of them
Definition: NamedVars.h:27
DLLEXPORT size_t GetListCount() const override
Gets the number of lists in this object.
Definition: ObjectFile.cpp:359
virtual DLLEXPORT size_t GetLineCount() const =0
Returns the number of text lines.
DLLEXPORT const std::string * GetPrefixPtr(size_t index) const
Definition: ObjectFile.cpp:279
DLLEXPORT ObjectFileObjectProper(const std::string &name, const std::string &typesname, std::vector< std::unique_ptr< std::string >> &&prefix)
Definition: ObjectFile.cpp:233
virtual DLLEXPORT const std::string & GetLine(size_t index) const
Gets a line from index ExceptionInvalidArgument when the index is out of bounds. ...
Definition: ObjectFile.cpp:490
static StringTypeN IndentLines(const StringTypeN &str, size_t spaces)
Appends spaces number of spaces to each line in str and returns the result.
DLLEXPORT std::shared_ptr< ScriptScript > GetScript() const override
Returns a std::shared_ptr to our script.
Definition: ObjectFile.cpp:257
DLLEXPORT size_t GetPrefixesCount() const override
Gets the number of prefixes.
Definition: ObjectFile.cpp:261
DLLEXPORT ObjectFile()
Definition: ObjectFile.cpp:23
virtual DLLEXPORT bool AddVariable(std::shared_ptr< NamedVariableList > var)
Adds a new variable.
Definition: ObjectFile.cpp:210
Non-template class for working with all types of DataBlocks.
Definition: DataBlock.h:425
virtual DLLEXPORT void AddTextLine(const std::string &line)
Adds an UTF8 encoded line.
Definition: ObjectFile.cpp:503
DLLEXPORT ObjectFileObject * GetObjectFromIndex(size_t index) const
Gets an ObjectFileObject from an index ExceptionInvalidArgument when the index is out of bounds...
Definition: ObjectFile.cpp:74
DLLEXPORT std::vector< ObjectFileObject * > GetAllObjectsWithType(const std::string &type) const
Gets all ObjectFileObjects that have the type.
Definition: ObjectFile.cpp:101
DLLEXPORT std::unique_ptr< ObjectFileTemplateObject > CreateInstanceFromThis(const ObjectFileTemplateInstance &instanceargs, LErrorReporter *reporterror=nullptr)
Creates an instance from this template.
Definition: ObjectFile.cpp:557
DLLEXPORT ObjectFileTextBlock * GetTextBlockWithName(const std::string &name) const override
Gets an ObjectFileTextBlock that matches the name.
Definition: ObjectFile.cpp:347
DLLEXPORT ObjectFileTextBlock * GetTextBlock(size_t index) const override
Gets a text block from an index ExceptionInvalidArgument when the index is out of bounds...
Definition: ObjectFile.cpp:381
DLLEXPORT bool AddNamedVariable(std::shared_ptr< NamedVariableList > var)
Adds a NamedVariableList to this file.
virtual void Warning(const std::string &Text)=0
DLLEXPORT ObjectFileTemplateInstance(const std::string &mastertmplname, std::vector< std::unique_ptr< std::string >> &templateargs)
Definition: ObjectFile.cpp:785
Represents a section of script source file.
Definition: ScriptModule.h:71
STL namespace.
std::shared_ptr< ObjectFileObject > RepresentingObject
The object from which the instances are created.
Definition: ObjectFile.h:356
DLLEXPORT ObjectFileListProper(const std::string &name)
Definition: ObjectFile.cpp:201
DLLEXPORT ObjectFileList * GetListWithName(const std::string &name) const override
Gets an ObjectFileList that matches the name.
Definition: ObjectFile.cpp:335
DLLEXPORT bool AddTextBlock(std::unique_ptr< ObjectFileTextBlock > &&tblock) override
Add a text block to this object.
Definition: ObjectFile.cpp:306
DLLEXPORT std::string Serialize(size_t indentspaces=0) const
Definition: ObjectFile.cpp:790
Implementation of ObjectFileList.
Definition: ObjectFile.h:49
Implementation of ObjectFileTextBlock.
Definition: ObjectFile.h:99
virtual DLLEXPORT bool AddVariable(std::shared_ptr< NamedVariableList > var)=0
Adds a new variable.
virtual DLLEXPORT NamedVars & GetVariables()
Gets a reference to the underlying variables.
Definition: ObjectFile.cpp:225
DLLEXPORT bool GenerateTemplatedObjects(LErrorReporter *reporterror)
Instantiates all all templates to actual objects.
Definition: ObjectFile.cpp:114
Interface for object file text blocks to implement.
Definition: ObjectFile.h:71
DLLEXPORT const std::string & GetName() const
Gets the name of this template.
Definition: ObjectFile.cpp:518
static DLLEXPORT std::shared_ptr< ObjectFileTemplateDefinition > CreateFromObject(const std::string &name, std::shared_ptr< ObjectFileObject > obj, std::vector< std::unique_ptr< std::string >> &templateargs)
Creates a ObjectFileTemplateDefinition from an ObjectFileObject and a parameter list.
Definition: ObjectFile.cpp:523
virtual DLLEXPORT const std::string & GetName() const
Gets the name of this list.
Definition: ObjectFile.cpp:206
DLLEXPORT ObjectFileTextBlockProper(const std::string &name)
Definition: ObjectFile.cpp:473
#define SAFE_DELETE_VECTOR(x)
Definition: Define.h:123
static DLLEXPORT ScriptExecutor * Get()
virtual DLLEXPORT size_t GetLineCount() const
Returns the number of text lines.
Definition: ObjectFile.cpp:486
#define DATABLOCK_TYPE_WSTRING
Definition: DataBlock.h:25
virtual DLLEXPORT ~ObjectFileObject()
Definition: ObjectFile.cpp:469
virtual DLLEXPORT const std::string & GetLine(size_t index) const =0
Gets a line from index ExceptionInvalidArgument when the index is out of bounds. ...
virtual DLLEXPORT void Print(LErrorReporter *errorreport) const noexcept
Definition: Exceptions.cpp:41
Fully defined ObjectFileObject.
Definition: ObjectFile.h:206
bool ConvertAndAssingToVariable(ConvertT &var) const
Definition: DataBlock.h:728
DLLEXPORT void Warning(const std::string &data) override
Definition: Logger.cpp:190
#define DATABLOCK_TYPE_STRING
Definition: DataBlock.h:26
DLLEXPORT bool IsThisTemplated() const override
Returns true when this is a templated object.
Definition: ObjectFile.cpp:464
DLLEXPORT std::string Serialize(size_t indentspaces=0) const override
Definition: ObjectFile.cpp:395
DLLEXPORT ObjectFileTemplateObject(const std::string &name, const std::string &typesname, std::vector< std::unique_ptr< std::string >> &&prefix)
Creates an ObjectFileTemplateObject as a wrapper around an ObjectFileObject.
Definition: ObjectFile.cpp:814
DLLEXPORT ObjectFileObject * GetObjectWithType(const std::string &typestr) const
Gets an ObjectFileObject matching the type name.
Definition: ObjectFile.cpp:89
virtual DLLEXPORT DataBlockAll * AllocateNewFromThis() const =0
DLLEXPORT bool AddTemplate(std::shared_ptr< ObjectFileTemplateDefinition > templatedef)
Adds a ObjectFileTemplateInstance to this file.
Definition: ObjectFile.cpp:165
DLLEXPORT const std::string & GetPrefix(size_t index) const override
Gets a prefix prom an index ExceptionInvalidArgument when the index is out of bounds.
Definition: ObjectFile.cpp:265
virtual DLLEXPORT const std::string & GetName() const
Gets the name of this text block.
Definition: ObjectFile.cpp:482
DLLEXPORT const std::string & GetTypeName() const override
Gets the name of the type.
Definition: ObjectFile.cpp:253
DataBlockAll * GetBlock()
Definition: DataBlock.h:499
std::vector< std::unique_ptr< std::string > > Parameters
Template parameter definitions.
Definition: ObjectFile.h:353
static DLLEXPORT Logger * Get()
Definition: Logger.cpp:106
Class that represents an object created from a template.
Definition: ObjectFile.h:261
Represents a template instantiation.
Definition: ObjectFile.h:281
DLLEXPORT bool AddVariableList(std::unique_ptr< ObjectFileList > &&list) override
Add a variable list to this object.
Definition: ObjectFile.cpp:289
std::string ReplaceStringTemplateArguments(const std::string &target, const std::vector< std::unique_ptr< std::string >> &args)
Definition: ObjectFile.cpp:764
virtual DLLEXPORT NamedVars & GetVariables()=0
Gets a reference to the underlying variables.
Interface for object file objects to implement.
Definition: ObjectFile.h:122
DLLEXPORT ~ObjectFile()
Definition: ObjectFile.cpp:27
virtual void Error(const std::string &Text)=0
virtual DLLEXPORT void AddTextLine(const std::string &line)=0
Adds an UTF8 encoded line.
DLLEXPORT size_t GetTextBlockCount() const override
Gets the number of text blocks in this object.
Definition: ObjectFile.cpp:377
#define DLLEXPORT
Definition: Include.h:115
DataBlock< std::string > StringBlock
Definition: DataBlock.h:386
virtual DLLEXPORT const std::string & GetName() const =0
Gets the name of this list.
DLLEXPORT std::shared_ptr< ObjectFileTemplateDefinition > FindTemplateDefinition(const std::string &name) const
Finds the template definition matching the name.
Definition: ObjectFile.cpp:183
DLLEXPORT NamedVars * GetVariables()
Returns a raw pointer to HeaderVars.
Definition: ObjectFile.cpp:70
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
DLLEXPORT bool AddObject(std::shared_ptr< ObjectFileObject > obj)
Adds a ObjectFileObject to this file.
DLLEXPORT void AddScriptScript(std::shared_ptr< ScriptScript > script) override
Add a script block to this object.
Definition: ObjectFile.cpp:323
virtual DLLEXPORT ~ObjectFileTextBlock()
Definition: ObjectFile.cpp:508
DLLEXPORT std::vector< std::shared_ptr< NamedVariableList > > * GetVec()
Definition: NamedVars.cpp:1246
DLLEXPORT ObjectFileTemplateDefinition(const std::string &name, std::vector< std::unique_ptr< std::string >> &parameters, std::shared_ptr< ObjectFileObject > obj)
Creates a ObjectFileTemplateDefinition.
Definition: ObjectFile.cpp:512
DLLEXPORT void AddTemplateInstance(std::shared_ptr< ObjectFileTemplateInstance > tiobj)
Adds a ObjectFileTemplateInstance to this file.
Definition: ObjectFile.cpp:158
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
DLLEXPORT std::string Serialize() const
Definition: ObjectFile.cpp:532
void ReplaceStringWithTemplateArguments(std::string &target, const std::vector< std::unique_ptr< std::string >> &args)
Definition: ObjectFile.cpp:752