Colobot
program_storage_object.h
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
20 #pragma once
21 
23 
24 #include <memory>
25 #include <string>
26 #include <vector>
27 
28 class CScript;
29 class CLevelParserLine;
30 
31 struct Program
32 {
33  std::unique_ptr<CScript> script;
34  bool readOnly = false;
35  bool runnable = true;
36  std::string filename;
37 };
38 
44 {
45 public:
46  explicit CProgramStorageObject(ObjectInterfaceTypes& types)
47  {
48  types[static_cast<int>(ObjectInterfaceType::ProgramStorage)] = true;
49  }
50  virtual ~CProgramStorageObject()
51  {}
52 
57  virtual bool IntroduceVirus() = 0;
62  virtual void SetActiveVirus(bool bActive) = 0;
64  virtual bool GetActiveVirus() = 0;
65 
67  virtual bool ReadProgram(Program* program, const std::string& filename) = 0;
69  virtual bool WriteProgram(Program* program, const std::string& filename) = 0;
71  virtual bool GetCompile(Program* program) = 0;
72 
74  virtual Program* AddProgram() = 0;
76  virtual void AddProgram(std::unique_ptr<Program> program) = 0;
78  virtual void RemoveProgram(Program* program) = 0;
80  virtual Program* CloneProgram(Program* program) = 0;
81 
83  virtual std::vector<std::unique_ptr<Program>>& GetPrograms() = 0;
85  virtual int GetProgramCount() = 0;
87  virtual Program* GetProgram(int index) = 0;
89  virtual Program* GetOrAddProgram(int index) = 0;
91  virtual int GetProgramIndex(Program* program) = 0;
92 
94  virtual void SetProgramStorageIndex(int programStorageIndex) = 0;
96  virtual int GetProgramStorageIndex() = 0;
97 
99  virtual void SaveAllUserPrograms(const std::string& userSource) = 0;
101  virtual void LoadAllProgramsForLevel(CLevelParserLine* levelSource, const std::string& userSource, bool loadSoluce) = 0;
102 
104  virtual void SaveAllProgramsForSavedScene(CLevelParserLine* levelSourceLine, const std::string& levelSource) = 0;
106  virtual void LoadAllProgramsForSavedScene(CLevelParserLine* levelSourceLine, const std::string& levelSource) = 0;
107 };
Definition: parserline.h:37
Interface for objects that store CBOT programs.
Definition: program_storage_object.h:43
objects that store CBOT programs
ObjectInterfaceType enum.
Definition: script.h:58
Definition: program_storage_object.h:31