I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
Index » Programming » New Module Ideas »

robsc\′s Photo
25 Sep 05, 1:56PM
hi, i thought about what you wrote and concluded that an efficient implementation must define at least two basic classes: one class that will be associated to the file and define a simple interface for reading and writing and another class that will put some constraints on the type of element. Furtheron it might be possible to inherit the first class from "vector" and thus provide a much more powerful tool. Have a look at the pieces of code below.

robert

//that's the save-binary-file-interface
class SaveBinary : std::vector
{
        public SaveBinary * read(int index);
        public SaveBinary * write(int index);
 
        //lots of member functions have to be overwritten
}
class SaveableType
{
        //force the user to define that function
        protected virtual int load(int) = 0;
}

//that's what a user is going to do with the interface
class MyClass : SaveableType
{
        //define the "load" function
        int load(int position)
        {
                //code
        }
 
        //more code
}
int main()
{
        MyClass mc1,mc2;
        SaveBinary<MyClass> sb;
 
        mc1.do_something();
        mc2.do_other();
 
 
        sb.push_back(mc1);
        sb.push_back(mc2);
 
 
        //probably you will NOT do this, but some other stl-algorithm
        //might perform something really elegant on "b"
        sort(b);
 
        return (0);
 
}

Currently you need to be logged in to leave a message.