www.digitalmars.com         C & C++   DMDScript  

c++ - Ok so maybe this C++ stuff is ok...

reply Michael Comperchio <mcmprch adelphia.net> writes:
I've been playing with the STL..really neat to be able to create dynamic 
arrays, dictionaries, and linked lists!!! with a couple a lines of code. 
It's the linked list I have a question about. I'm trying to maintain 
"ordered maps" if you will using the list template. I have it working by 
creating a class to associate the two things (a date, and a 
recordnumber). I think I may have overkilled the class (I created ALL 
the operators). Any suggestions for a 'bare bones' class that will work 
with list template?..

Another question: any way to force the automatic sorting of lists?

Another question: I'm creating record struct pointers on the fly. 
Basically read in the whole file creating dynamic structs and storing 
the addresses in a vector...I have a feeling that when I hack this into 
the MFC doc class I'm going to get burned by this...just can't think of how.

Another question: Could I create a vector of lists...
struct DataRecord
{
   int RecordNumber;
	char Task[256];
	char DueDate[10];
	char Priority[2];
	int Completed;
	char Notes[2048];
   int Deleted;
} ;

vector<struct DataRecord * > MyStuff; // my data file goes in here

list<int > OrderByRecordNumber; // simply walk through in order
list<DateOrder > OrderByDate;  // walk through by due date
list<PriorityOrder > OrderByPriority: // walk through by priority

vector <list > MyDisplaySorts; // this is the question... I'd like to 
simply set a flag and automagically use the right list for my sorting...

Any input would be appreciated...

Thanks
Michael
Jul 01 2002
next sibling parent reply Pavel Minayev <evilone omen.ru> writes:
On Mon, 01 Jul 2002 14:42:14 -0400 Michael Comperchio <mcmprch adelphia.net> 
wrote:

 I've been playing with the STL..really neat to be able to create dynamic 
 arrays, dictionaries, and linked lists!!! with a couple a lines of code. 
 It's the linked list I have a question about. I'm trying to maintain 
 "ordered maps" if you will using the list template. I have it working by 
 creating a class to associate the two things (a date, and a 
 recordnumber). I think I may have overkilled the class (I created ALL 
 the operators). Any suggestions for a 'bare bones' class that will work 
 with list template?..
I wonder why you need to write that "ordered map", if std::map is already ordered by key?
 Another question: any way to force the automatic sorting of lists?
No. Either you calculate the place to insert new item yourself (although there might be some STL algorithms to help in this task), or resort the list whenever needed.
 list<int > OrderByRecordNumber; // simply walk through in order
 list<DateOrder > OrderByDate;  // walk through by due date
 list<PriorityOrder > OrderByPriority: // walk through by priority
 
 vector <list > MyDisplaySorts; // this is the question... I'd like to 
 simply set a flag and automagically use the right list for my sorting...
Since all your lists are of different type, I don't see any way (pointer, reference, stub etc) to do that.
Jul 01 2002
parent Michael Comperchio <mcmprch adelphia.net> writes:
Pavel Minayev wrote:
 On Mon, 01 Jul 2002 14:42:14 -0400 Michael Comperchio <mcmprch adelphia.net> 
 wrote:
 
 
I've been playing with the STL..really neat to be able to create dynamic 
arrays, dictionaries, and linked lists!!! with a couple a lines of code. 
It's the linked list I have a question about. I'm trying to maintain 
"ordered maps" if you will using the list template. I have it working by 
creating a class to associate the two things (a date, and a 
recordnumber). I think I may have overkilled the class (I created ALL 
the operators). Any suggestions for a 'bare bones' class that will work 
with list template?..
I wonder why you need to write that "ordered map", if std::map is already ordered by key?
'cuz this is really just for my fun...and linked list is more my natural way of thinking...
  
 
Another question: any way to force the automatic sorting of lists?
No. Either you calculate the place to insert new item yourself (although there might be some STL algorithms to help in this task), or resort the list whenever needed.
darn...
 
list<int > OrderByRecordNumber; // simply walk through in order
list<DateOrder > OrderByDate;  // walk through by due date
list<PriorityOrder > OrderByPriority: // walk through by priority

vector <list > MyDisplaySorts; // this is the question... I'd like to 
simply set a flag and automagically use the right list for my sorting...
Since all your lists are of different type, I don't see any way (pointer, reference, stub etc) to do that.
I didn't see any way either...but thought I might have been missing the obvious again.. thanks!! Michael
Jul 01 2002
prev sibling parent Jan Knepper <jan smartsoft.cc> writes:
Michael Comperchio wrote:

 I've been playing with the STL..really neat to be able to create dynamic
 arrays, dictionaries, and linked lists!!! with a couple a lines of code.
 It's the linked list I have a question about. I'm trying to maintain
 "ordered maps" if you will using the list template. I have it working by
 creating a class to associate the two things (a date, and a
 recordnumber). I think I may have overkilled the class (I created ALL
 the operators). Any suggestions for a 'bare bones' class that will work
 with list template?..

 Another question: any way to force the automatic sorting of lists?
Of lists... No. Use a 'map' instead! map < Key, Data *, less < Key > > ...
 Another question: I'm creating record struct pointers on the fly.
 Basically read in the whole file creating dynamic structs and storing
 the addresses in a vector...I have a feeling that when I hack this into
 the MFC doc class I'm going to get burned by this...just can't think of how.
No it won't. If you are experienced enough with C++ it's no problem.
 Another question: Could I create a vector of lists...
Yes! class DataList : public list < DataRecord * > { }; class DataListVector : public vector < DataList * > { }; class
 struct DataRecord
 {
    int RecordNumber;
         char Task[256];
         char DueDate[10];
         char Priority[2];
         int Completed;
         char Notes[2048];
    int Deleted;
 } ;

 vector<struct DataRecord * > MyStuff; // my data file goes in here

 list<int > OrderByRecordNumber; // simply walk through in order
 list<DateOrder > OrderByDate;  // walk through by due date
 list<PriorityOrder > OrderByPriority: // walk through by priority

 vector <list > MyDisplaySorts; // this is the question... I'd like to
 simply set a flag and automagically use the right list for my sorting...
What I would do in this case is use a 'set' to do the adminitration of the allocated pointers. Than you map's to 'map' <g> key's to the pointers. Thus class DataSet : public set < DataRecord *, less < DataRecord * > > { }; class NumberDataSetMap : public map < int, DataRecord *, less < int > > { }; class StringDataSetMap : public map < CString, DataRecord *, less < CStrng > > { }; HTH Jan
Jul 01 2002