L
LeTubs
Hi
I'm having a bit of trouble with maps (I'm a c programmer making the
transistion).
Now I want to do it this way as I won't know how many files/names untill
runtime, not bothered
by access (ie logrithimic/constant/linear) time unless the program goes way
slow!.so trying to
use STL that can grow grow and shrink as required.
Now
The layer is unqiue (ie 0 -> say 100 )
the filename is unique (ie file01.txt is unique )
but each layer can have multiple files ie layer 1 can
have file01.txt, file02.txt,....
struct is a simple stuct which holds status
information which is unique to that file ( & hence
layer).
I've include some sample code below...which I have been trying to get to
work.
basically so I can address the data like
layer_info[0]["file01.txt"].condvar;
layer_info[0]["file02.txt"].condvar;
layer_info[0]["file02.txt"].condvar;
( 0 -> layer, file01.txt -> file, and the filled out variable).
Any tips or pointers would be greatly appreciated.
Many Thanks
David
-------- cut --------------- filename test.cxx
#include <map>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
typedef struct layer_struct{
int condvar;
int predicate;
} layer_struct;
typedef map< string, layer_struct> layer_map;
map < int, vector <layer_map> >a_layer;
layer_struct FilledOut;
int main(){
FilledOut.condvar = 1;
FilledOut.predicate = 1;
// load the record for file.txt into layer 1
a_layer[0, layer_map["File.txt",FilledOut]];
// ideally print out 1
cout << a_layer[0]["File.txt"].condvar << endl;
exit(0);
}
-------- cut-------------------
gcc test.cxx -o testw -lstdc++
OS : Red Hat.
I'm having a bit of trouble with maps (I'm a c programmer making the
transistion).
Now I want to do it this way as I won't know how many files/names untill
runtime, not bothered
by access (ie logrithimic/constant/linear) time unless the program goes way
slow!.so trying to
use STL that can grow grow and shrink as required.
Now
The layer is unqiue (ie 0 -> say 100 )
the filename is unique (ie file01.txt is unique )
but each layer can have multiple files ie layer 1 can
have file01.txt, file02.txt,....
struct is a simple stuct which holds status
information which is unique to that file ( & hence
layer).
I've include some sample code below...which I have been trying to get to
work.
basically so I can address the data like
layer_info[0]["file01.txt"].condvar;
layer_info[0]["file02.txt"].condvar;
layer_info[0]["file02.txt"].condvar;
( 0 -> layer, file01.txt -> file, and the filled out variable).
Any tips or pointers would be greatly appreciated.
Many Thanks
David
-------- cut --------------- filename test.cxx
#include <map>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
typedef struct layer_struct{
int condvar;
int predicate;
} layer_struct;
typedef map< string, layer_struct> layer_map;
map < int, vector <layer_map> >a_layer;
layer_struct FilledOut;
int main(){
FilledOut.condvar = 1;
FilledOut.predicate = 1;
// load the record for file.txt into layer 1
a_layer[0, layer_map["File.txt",FilledOut]];
// ideally print out 1
cout << a_layer[0]["File.txt"].condvar << endl;
exit(0);
}
-------- cut-------------------
gcc test.cxx -o testw -lstdc++
OS : Red Hat.