I've been working on version 2 of my FileHandler class. I haven't implemented the read and write yet ( I'm open for suggestions/ideas )
Looking for criticism about style, readability, the system, you know how it goes. I'm pretty tough skinned so if you think it's tripe tell me! Just back up your claim with suggestions.
I won't be home after I post this, so I won't be able to make changed but I can read your comments through email and will reply back. Cheers.
1) Tell us what this class is, why was it created and what problem does it solves.
2) Default constructor is useless: it creates unusable object. If amount of handles is not dynamically changes, remove default constructor altogether. It is way easier to add something to the interface than to remove something.
3) After opening new handle there is no way to tell its id. Make OpenHandle return id.
4) Why do you use manual memory management and not existing automated features (even unique_ptr would help you)
5?) Creating and allocating all handles at once might be counter productive. Allocate uninitialized storage and use in-place construction like vector does. Or just use vector to store streams: automatic memory management and expandable storage.
6) You are violating rule of 5. Missing move and copy constructors and assigment
7) No one want class to litter their console output. It makes your class virtually unusable in any application. If you want you may take additional parameter: reference to output stream which should receive output.
I have created this class to keep track of files within a program. I figured something like a database program or a game would have to keep track of numerous files. I wanted to create a class that could hold and manipulate files from the same place.
2)
I understand the default constructor does nothing as of yet. I can take it out until dynamic memory management is in place for the creation of new handles.
3)
Yes, it's something I am fully aware of. I plan on changing all voids to ints which will return relevant data/error codes.
4)
Again, I am aware of the manual memory management. I cooked this up overly tired within an hour. I plan on changing the memory handling, I might use std::vector or implement my own.
5)
Is something I am going to look in to.
6)
Will be implemented, though I was unsure as the point of the class was to keep things in one place but hey, if people need it. ( Btw this wasn't made for people to use, just for myself. )
7)
Again well aware, was purely for debugging purposes. I have explained the planned behavior previous.
I was unsure as the point of the class was to keep things in one place
If you do not want mpre than one istance to be created, do not let more than one instance to be created. Make it a singleton.
Right now your class should disallow copying, but allow move.
Maybe more open modes? Like ate, app... Or instead of int make it receive (and forward to open() function) open mode, so you can write open mode directly: There is already bunch of predefined enumerations, no need to create another which does the same.
You can stop reinventing the wheel and use standard std::ios_base::openmode. Instead of having to learn your own enumerations, users could just use well known ones:
That's genius. Exactly the kind of advice I'm looking for.
I was going to do the std::string overload. My real concern is the unimplemented Read and Write, I think I'm going to have to make those template functions so I can read into and write from different sources. I don't have much experience with templates but I felt make several of the same functions with differed overloads to perform the same operations overkill. Any ideas?
My ideal usage would be something like:
MyFileHandler.ReadHandle(handleID, char*); // Read handleID into char*
MyFileHandler.WriteHandle(handleID, std::string); // Weire string to handleID
Not sure if possible but a feature I would like:
MyFileHandler.ReadHandle(handleID, std::cout); // read file straight into cout