Ref and Src are not supposed to be derived from sync.
I was trying to get around an issue where Ref and Src rely on each other to be defined already by pulling some of the structs and typedefs out of Ref and Src and wrapping it in Sync to be "pre-defined" before Src and Ref used them.
Sorry, guess I should have taken the time to explain in a little more detail what I'm trying to accomplish.
I'm trying to create two kinds of lists that can be syncronized together.
I would like them to be wrapped in a templated Sync_List class.
Sync_List object cannot actually be created(private ctor).
Src_List - The Source List contains a list of struct Data:
1 2 3 4 5 6 7 8 9 10 11
|
class Src_List
{
struct Data //element
{
T data;
std::list<Ref_List::iterator> link;
};
std::list<Data> list_;
typedef std::list<Data>::iterator iterator; //Src_List::iterator
};
|
A Src_List's data is always inserted at the end, maintaining a new-to-old order.
The user should never be able to sort Src_List.
Ref_List - The Reference List contains a list of T* and a second list of Src_List::iterators.
1 2 3 4 5 6 7
|
class Ref_List
{
std::list<T*> list_;
std::list<Src_List::iterator> tracker_;
typedef std::list<T*>::iterator iterator //Ref_List::iterator
};
|
A Ref_List's data can only point to T in a Src_List.
Ref_List can be sorted in any order the user wants.
Ref_List methods
1 2 3
|
Ref_List::sync(Src_List _src); //syncs the Ref_List with the Src_List
Ref_List::sync() //syncs all Src_Lists the Ref_List has been previously synced with
Ref_List::desync(Src_List _src); //desyncs Ref_List from Src_List, removes all data pointers
|
Iterators
When a Src_list and Ref_List are synced together, they must be able to track some information about each other. This is where the iterators come in.
std::list<Ref_List::iterator> link
When a Src_List element is deleted, every Ref_List::T* that points to that element must also be deleted. A list of Ref_List::iterators paired with a Src_List::T is used to accomplish this.(struct Ref_List::Data)
std::list<Src_List::iterator> tracker
When a Ref_List::sync() call is made, the Ref_List must keep track of the last Src_List element since the last call to Ref_List::sync(). This is done with a Src_List::iterator.
Issue
Ref_List relies on Src_List::iterator being defined
Src_List relies on Ref_List::iterator being defined
Need to find a way to work around this. Currently looking over the solution from my previous post. Ran into some iterator issues but might just be a syntax thing. Still looking for suggestions.
Goal
Ability to use Sync_Lists like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include "Sync_List.h"
int main
{
Sync_List<int>::Src_List src_list;
Sync_List<int>::Ref_List ref_list;
src_list.push_back(25); //add to src
src_list.push_back(342); //add to src
src_list.push_back(-79); //add to src
std::cout << "src_list: |" << src_list << std::endl;
std::cout << "ref_list: |" << ref_list << std::endl;
std::endl;
ref_list.sync(src_list); //sync ref with src
std::cout << "src_list: |" << src_list << std::endl;
std::cout << "ref_list: |" << ref_list << std::endl;
std::endl;
src_list.remove(342); //remove from src(and ref)
src_list.push_back(222); //add to src(ref not syncd)
std::cout << "src_list: |" << src_list << std::endl;
std::cout << "ref_list: |" << ref_list << std::endl;
std::endl;
ref_list.sync(); //sync ref
std::cout << "src_list: |" << src_list << std::endl;
std::cout << "ref_list: |" << ref_list << std::endl;
return 0;
}
|
output:
src_list: |25|342|-79|
ref_list: |empty|
src_list: |25|342|-79|
ref_list: |25|342|-79|
src_list: |25|-79|222|
ref_list: |25|-79|
src_list: |25|-79|222|
ref_list: |25|-79|222|
|