Colobot
program_storage_impl.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 
22 #include "object/interface/program_storage_object.h"
23 
24 #include "math/vector.h"
25 
26 #include <sstream>
27 
28 class CObject;
29 
31 {
32 public:
33  explicit CProgramStorageObjectImpl(ObjectInterfaceTypes& types, CObject* object);
34  virtual ~CProgramStorageObjectImpl();
35 
36  bool IntroduceVirus() override;
37  void SetActiveVirus(bool bActive) override;
38  bool GetActiveVirus() override;
39 
40  bool ReadProgram(Program* program, const std::string& filename) override;
41  bool WriteProgram(Program* program, const std::string& filename) override;
42  bool GetCompile(Program* program) override;
43 
44  Program* AddProgram() override;
45  void AddProgram(std::unique_ptr<Program> program) override;
46  void RemoveProgram(Program* program) override;
47  Program* CloneProgram(Program* program) override;
48 
49  std::vector<std::unique_ptr<Program>>& GetPrograms() override;
50  int GetProgramCount() override;
51  Program* GetProgram(int index) override;
52  Program* GetOrAddProgram(int index) override;
53  int GetProgramIndex(Program* program) override;
54 
55  void SetProgramStorageIndex(int programStorageIndex) override;
56  int GetProgramStorageIndex() override;
57 
58  void SaveAllUserPrograms(const std::string& userSource) override;
59  void LoadAllProgramsForLevel(CLevelParserLine* levelSource, const std::string& userSource, bool loadSoluce) override;
60 
61  void SaveAllProgramsForSavedScene(CLevelParserLine* levelSourceLine, const std::string& levelSource) override;
62  void LoadAllProgramsForSavedScene(CLevelParserLine* levelSourceLine, const std::string& levelSource) override;
63 
64 private:
65  CObject* m_object;
66 
67 private:
68  std::vector<std::unique_ptr<Program>> m_program;
69 
70  bool m_activeVirus;
71 
72  int m_programStorageIndex;
73  bool m_allowProgramSave;
74 };
bool WriteProgram(Program *program, const std::string &filename) override
Write program to a given file.
Definition: program_storage_impl.cpp:194
void SetActiveVirus(bool bActive) override
Definition: program_storage_impl.cpp:85
void RemoveProgram(Program *program) override
Remove program.
Definition: program_storage_impl.cpp:118
bool ReadProgram(Program *program, const std::string &filename) override
Read program from a given file.
Definition: program_storage_impl.cpp:187
int GetProgramStorageIndex() override
Return index that is used while saving programs.
Definition: program_storage_impl.cpp:213
int GetProgramCount() override
Return count of all programs.
Definition: program_storage_impl.cpp:146
Program * GetOrAddProgram(int index) override
Return program at the given index (creating it and all previous ones as needed)
Definition: program_storage_impl.cpp:171
void LoadAllProgramsForLevel(CLevelParserLine *levelSource, const std::string &userSource, bool loadSoluce) override
Load all programs when loading the level including previously saved user programs.
Definition: program_storage_impl.cpp:253
Definition: parserline.h:37
bool IntroduceVirus() override
Definition: program_storage_impl.cpp:68
void LoadAllProgramsForSavedScene(CLevelParserLine *levelSourceLine, const std::string &levelSource) override
Load all programs when loading the saved scene.
Definition: program_storage_impl.cpp:361
int GetProgramIndex(Program *program) override
Return index in the list of given Program instance.
Definition: program_storage_impl.cpp:151
Interface for objects that store CBOT programs.
Definition: program_storage_object.h:43
bool GetCompile(Program *program) override
Check if program was compiled successfully.
Definition: program_storage_impl.cpp:201
void SaveAllUserPrograms(const std::string &userSource) override
Save all user programs.
Definition: program_storage_impl.cpp:218
std::vector< std::unique_ptr< Program > > & GetPrograms() override
Return a std::vector of all available programs.
Definition: program_storage_impl.cpp:141
Vector struct and related functions.
bool GetActiveVirus() override
Checks virus active status.
Definition: program_storage_impl.cpp:95
Definition: program_storage_impl.h:30
Program * AddProgram() override
Add a new program.
Definition: program_storage_impl.cpp:101
void SetProgramStorageIndex(int programStorageIndex) override
Set index for use in filename for saved programs (-1 to disable)
Definition: program_storage_impl.cpp:208
Program * CloneProgram(Program *program) override
Clone a program.
Definition: program_storage_impl.cpp:128
Base class for all 3D in-game objects.
Definition: object.h:63
void SaveAllProgramsForSavedScene(CLevelParserLine *levelSourceLine, const std::string &levelSource) override
Save all programs when saving the saved scene.
Definition: program_storage_impl.cpp:316
Program * GetProgram(int index) override
Return program with the given index.
Definition: program_storage_impl.cpp:163
Definition: program_storage_object.h:31