Colobot
program_storage_object.h
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2015, 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 };
virtual bool GetCompile(Program *program)=0
Check if program was compiled successfully.
virtual Program * AddProgram()=0
Add a new program.
virtual bool ReadProgram(Program *program, const std::string &filename)=0
Read program from a given file.
virtual void SetActiveVirus(bool bActive)=0
virtual Program * GetProgram(int index)=0
Return program with the given index.
Definition: parserline.h:37
virtual void SaveAllProgramsForSavedScene(CLevelParserLine *levelSourceLine, const std::string &levelSource)=0
Save all programs when saving the saved scene.
virtual std::vector< std::unique_ptr< Program > > & GetPrograms()=0
Return a std::vector of all available programs.
Interface for objects that store CBOT programs.
Definition: program_storage_object.h:43
virtual void LoadAllProgramsForLevel(CLevelParserLine *levelSource, const std::string &userSource, bool loadSoluce)=0
Load all programs when loading the level including previously saved user programs.
virtual void RemoveProgram(Program *program)=0
Remove program.
objects that store CBOT programs
virtual int GetProgramCount()=0
Return count of all programs.
virtual bool IntroduceVirus()=0
virtual void LoadAllProgramsForSavedScene(CLevelParserLine *levelSourceLine, const std::string &levelSource)=0
Load all programs when loading the saved scene.
virtual int GetProgramIndex(Program *program)=0
Return index in the list of given Program instance.
virtual int GetProgramStorageIndex()=0
Return index that is used while saving programs.
ObjectInterfaceType enum.
virtual Program * GetOrAddProgram(int index)=0
Return program at the given index (creating it and all previous ones as needed)
Definition: script.h:58
virtual bool GetActiveVirus()=0
Checks virus active status.
virtual bool WriteProgram(Program *program, const std::string &filename)=0
Write program to a given file.
virtual void SaveAllUserPrograms(const std::string &userSource)=0
Save all user programs.
virtual void SetProgramStorageIndex(int programStorageIndex)=0
Set index for use in filename for saved programs (-1 to disable)
Definition: program_storage_object.h:31
virtual Program * CloneProgram(Program *program)=0
Clone a program.