Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
Java2Cpp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Glaser
Java2Cpp
Commits
90ad67d5
Commit
90ad67d5
authored
3 years ago
by
tobiglaser
Browse files
Options
Downloads
Patches
Plain Diff
update List to WS2 + resolve polymorphism hiccups
parent
3659d430
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/CommandListOWN.h
+22
-4
22 additions, 4 deletions
src/CommandListOWN.h
src/Element.h
+3
-2
3 additions, 2 deletions
src/Element.h
with
25 additions
and
6 deletions
src/CommandListOWN.h
+
22
−
4
View file @
90ad67d5
...
...
@@ -5,12 +5,15 @@
#include
"Command.h"
#include
"Element.h"
#include
"Gear.h"
#include
"Direction.h"
#include
"Pause.h"
class
CommandList
{
private:
std
::
shared_ptr
<
Element
>
root
=
std
::
make_shared
<
Element
>
(
Command
(
"root"
)
);
std
::
shared_ptr
<
Element
>
root
=
std
::
make_shared
<
Element
>
();
std
::
shared_ptr
<
Element
>
getElement
(
unsigned
int
_pos
);
public:
...
...
@@ -20,12 +23,14 @@ public:
int
getPos
(
std
::
shared_ptr
<
Command
>
_cmd
);
std
::
shared_ptr
<
Command
>
getCommand
(
unsigned
int
_pos
);
std
::
shared_ptr
<
Command
>
add
(
Command
_cmd
);
template
<
class
Type
>
std
::
shared_ptr
<
Command
>
add
(
const
Type
_cmd
);
std
::
shared_ptr
<
Command
>
remove
(
unsigned
int
_pos
);
std
::
shared_ptr
<
Command
>
moveUp
(
unsigned
int
_pos
);
std
::
shared_ptr
<
Command
>
moveDown
(
unsigned
int
_pos
);
void
createCommands
();
void
printCommands
();
};
...
...
@@ -54,7 +59,8 @@ void CommandList::clear()
}
}
std
::
shared_ptr
<
Command
>
CommandList
::
add
(
Command
_cmd
)
template
<
class
Type
>
std
::
shared_ptr
<
Command
>
CommandList
::
add
(
const
Type
_cmd
)
{
std
::
shared_ptr
<
Element
>
newElement
=
std
::
make_shared
<
Element
>
(
_cmd
);
std
::
shared_ptr
<
Element
>
end
=
getElement
(
getSize
());
...
...
@@ -63,6 +69,18 @@ std::shared_ptr<Command> CommandList::add(Command _cmd)
return
newElement
->
getCommand
();
}
//clears list before adding 5 Commands
void
CommandList
::
createCommands
()
{
clear
();
add
(
Gear
(
10
,
2.71
));
add
(
Direction
(
90
));
add
(
Pause
(
2.5
));
add
(
Direction
(
-
90
));
add
(
Gear
(
-
10
,
2.71
));
}
void
CommandList
::
printCommands
()
{
std
::
shared_ptr
<
Element
>
current
=
root
;
...
...
@@ -70,7 +88,7 @@ void CommandList::printCommands()
{
//In this order to not print out the root element.
current
=
current
->
getNext
();
std
::
cout
<<
current
->
getCommand
()
->
get
Name
()
<<
'\n'
;
std
::
cout
<<
current
->
getCommand
()
->
get
Config
()
<<
'\n'
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/Element.h
+
3
−
2
View file @
90ad67d5
...
...
@@ -11,8 +11,9 @@ private:
std
::
shared_ptr
<
Command
>
cmd
;
public:
Element
(
Command
_cmd
)
{
cmd
=
std
::
make_shared
<
Command
>
(
_cmd
);
}
~
Element
()
{
std
::
cout
<<
"~Element - "
<<
cmd
->
getName
()
<<
'\n'
;
}
template
<
class
Type
>
Element
(
Type
_cmd
)
{
cmd
=
std
::
make_shared
<
Type
>
(
_cmd
);
}
Element
()
{}
std
::
shared_ptr
<
Command
>
getCommand
()
{
return
cmd
;
}
void
setNext
(
std
::
shared_ptr
<
Element
>
_next
)
{
next
=
_next
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment