GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
EventsRefactorer.h
1 /*
2  * GDevelop Core
3  * Copyright 2008-2016 Florian Rival ([email protected]). All rights
4  * reserved. This project is released under the MIT License.
5  */
6 #ifndef GDCORE_EVENTSREFACTORER_H
7 #define GDCORE_EVENTSREFACTORER_H
8 #include <memory>
9 #include <vector>
10 
11 #include "GDCore/Events/Instruction.h"
12 #include "GDCore/Extensions/Metadata/InstructionMetadata.h"
13 #include "GDCore/String.h"
14 namespace gd {
15 class EventsList;
16 class ObjectsContainer;
17 class ObjectsContainersList;
18 class ProjectScopedContainers;
19 class Platform;
20 class ExternalEvents;
21 class BaseEvent;
22 class Instruction;
23 typedef std::shared_ptr<gd::BaseEvent> BaseEventSPtr;
24 } // namespace gd
25 
26 namespace gd {
27 
34 class GD_CORE_API EventsSearchResult {
35  public:
36  EventsSearchResult(std::weak_ptr<gd::BaseEvent> event_,
37  gd::EventsList* eventsList_,
38  std::size_t positionInList_);
40  ~EventsSearchResult(){};
41 
42  std::weak_ptr<gd::BaseEvent> event;
43  gd::EventsList* eventsList;
44  std::size_t positionInList;
45 
46  bool IsEventsListValid() const { return eventsList != nullptr; }
47 
53  const gd::EventsList& GetEventsList() const { return *eventsList; }
54 
55  std::size_t GetPositionInList() const { return positionInList; }
56 
57  bool IsEventValid() const { return !event.expired(); }
58 
63  const gd::BaseEvent& GetEvent() const { return *event.lock(); }
64 };
65 
76 class GD_CORE_API EventsRefactorer {
77  public:
83  static void RenameObjectInEvents(const gd::Platform& platform,
84  gd::ProjectScopedContainers& projectScopedContainers,
85  gd::EventsList& events,
86  gd::String oldName,
87  gd::String newName);
88 
92  static void RemoveObjectInEvents(const gd::Platform& platform,
93  gd::ProjectScopedContainers& projectScopedContainers,
94  gd::EventsList& events,
95  gd::String name);
96 
103  static std::vector<EventsSearchResult> SearchInEvents(
104  const gd::Platform& platform,
105  gd::EventsList& events,
106  gd::String search,
107  bool matchCase,
108  bool inConditions,
109  bool inActions,
110  bool inEventStrings,
111  bool inEventSentences);
112 
118  static std::vector<EventsSearchResult> ReplaceStringInEvents(
119  gd::ObjectsContainer& project,
120  gd::ObjectsContainer& layout,
121  gd::EventsList& events,
122  gd::String toReplace,
123  gd::String newString,
124  bool matchCase,
125  bool inConditions,
126  bool inActions,
127  bool inEventString);
128 
129  virtual ~EventsRefactorer(){};
130 
131  private:
138  static bool RenameObjectInActions(const gd::Platform& platform,
139  gd::ProjectScopedContainers& projectScopedContainers,
140  gd::InstructionsList& instructions,
141  gd::String oldName,
142  gd::String newName);
143 
150  static bool RenameObjectInConditions(const gd::Platform& platform,
151  gd::ProjectScopedContainers& projectScopedContainers,
152  gd::InstructionsList& instructions,
153  gd::String oldName,
154  gd::String newName);
162  static bool RenameObjectInEventParameters(
163  const gd::Platform& platform,
164  gd::ProjectScopedContainers& projectScopedContainers,
165  gd::Expression& expression,
166  gd::ParameterMetadata parameterMetadata,
167  gd::String oldName,
168  gd::String newName);
169 
175  static bool RemoveObjectInConditions(const gd::Platform& platform,
176  gd::ProjectScopedContainers& projectScopedContainers,
177  gd::InstructionsList& conditions,
178  gd::String name);
179 
185  static bool RemoveObjectInActions(const gd::Platform& platform,
186  gd::ProjectScopedContainers& projectScopedContainers,
187  gd::InstructionsList& conditions,
188  gd::String name);
189 
195  static bool ReplaceStringInConditions(gd::ObjectsContainer& project,
196  gd::ObjectsContainer& layout,
197  gd::InstructionsList& conditions,
198  gd::String toReplace,
199  gd::String newString,
200  bool matchCase);
201 
207  static bool ReplaceStringInActions(gd::ObjectsContainer& project,
208  gd::ObjectsContainer& layout,
209  gd::InstructionsList& conditions,
210  gd::String toReplace,
211  gd::String newString,
212  bool matchCase);
213 
220  static bool ReplaceStringInEventSearchableStrings(
221  gd::ObjectsContainer& project,
222  gd::ObjectsContainer& layout,
223  gd::BaseEvent& event,
224  gd::String toReplace,
225  gd::String newString,
226  bool matchCase);
227 
228  static bool SearchStringInFormattedText(const gd::Platform& platform,
229  gd::Instruction& instruction,
230  gd::String search,
231  bool matchCase,
232  bool isCondition);
233  static bool SearchStringInActions(const gd::Platform& platform,
234  gd::InstructionsList& actions,
235  gd::String search,
236  bool matchCase,
237  bool inSentences);
238  static bool SearchStringInConditions(const gd::Platform& platform,
239  gd::InstructionsList& conditions,
240  gd::String search,
241  bool matchCase,
242  bool inSentences);
243  static bool SearchStringInEvent(gd::BaseEvent& events,
244  gd::String search,
245  bool matchCase);
246 
247  static const gd::String searchIgnoredCharacters;
248 
249  EventsRefactorer(){};
250 };
251 
252 } // namespace gd
253 
254 #endif // GDCORE_EVENTSREFACTORER_H
Base class defining an event.
Definition: Event.h:44
A list of events.
Definition: EventsList.h:33
Class containing functions to do refactoring tasks on events.
Definition: EventsRefactorer.h:76
Class used to return result when calling EventsRefactorer::SearchInEvents.
Definition: EventsRefactorer.h:34
const gd::BaseEvent & GetEvent() const
Get the event pointed by the EventsSearchResult.
Definition: EventsRefactorer.h:63
const gd::EventsList & GetEventsList() const
Get the events list containing the event pointed by the EventsSearchResult.
Definition: EventsRefactorer.h:53
Class representing an expression used as a parameter of a gd::Instruction. This class is nothing more...
Definition: Expression.h:30
An instruction is a member of an event: It can be a condition or an action.
Definition: Instruction.h:30
Definition: InstructionsList.h:25
Used as a base class for classes that will own objects (see gd::Object).
Definition: ObjectsContainer.h:36
Describe a parameter of an instruction (action, condition) or of an expression: type,...
Definition: ParameterMetadata.h:27
Base class for implementing a platform.
Definition: Platform.h:42
Holds references to variables, objects, properties and other containers.
Definition: ProjectScopedContainers.h:30
String represents an UTF8 encoded string.
Definition: String.h:31
Definition: CommonTools.h:24