I tried to edit the post, but the editing option expired. So here's the new version.
MenuItem.h
class MenuItem
{
int type_ID{0};
public:
int getType_ID();
MenuItem(int type){type_ID=type};
};
SubmenuItem.h
#include "MenuItem.h"
#include <vector>
class SubmenuItem
{
std::vector<MenuItem*> menu_addresses;
int fixed_set{0};
int current_index{o};
public:
void add(const MenuItem* set);
MenuItem* getAdress(int index)
{
return menu_addresses[index-1];
}
int getSubMenuSize()
{
return static_cast<int>(manu_addresses.size());
}
};
SubmenuItem.cpp
#include "SubmenuItem.h"
void SubmenuItem::add(const MenuItem* set)
{
menu_addresses.push_back(set);
setType();
}
MenuNavigator.h
#include "SubmenuItem.h"
class MenuNavigator
{
public:
//SubmenuItem iterator
enum class MenuNavigator::subTypes
{
action_call=1,
root=2,
//...
}
//possible applications:
int findFirstType(SubmenuItem& loop_box, int type_wanted)
{
//finds the first of a type
for(int iterator{1};iterator<=loop_box.getSubMenuSize();iterator+=1)
{
if (type_wanted == static_cast<int>(loop_box.getAddress(iterator)->getType()))
{
return iterator;
}
}
return 0;
}
int findAllOfSameType(SubmenuItem& loop_box, int type_wanted)
{
//finds all of the same type, stops after finding 5th menu item
int results{0};
for(int iterator{1};(iterator<=loop_box.getSubMenuSize() && iterator <= 5);iterator+=1)
{
results+=1;
}
return results;
}
};
main.cpp
#include "MenuNavigator.h"
#include <iostream>
std::string getNodeType(int type_wanted)
{
if (static_cast<MenuNavigator::subTypes>(type_wanted) == MenuNavigator::subTypes::root)
{
return "root";
}
if (static_cast<MenuNavigator::subTypes>(type_wanted) == MenuNavigator::subTypes::action_call)
{
return "action call";
}
}
int main()
{
MenuItem a{1};
MenuItem b{1};
MenuItem c{2};
SubmenuItem D;
D.add(&a);
D.add(&b);
D.add(&c);
MenuNavigator E;
//possible use:
//the 1 here means action call
int first_index{ E.loop_findFirstType(D, 1)};
//here it means finding the node type
//this should return 1(searching index result) as MenuItem
//a is the first added MenuItem which has type 1
//after indefying the first MenuItem of action call type index,
//iterate through the Submenu D
std::cout << getNodeType(D.getAdress(1)->getType());