How high level to go?

I was making an encryption library, and i managed to make 3 stages of level, my first one just took char arrays and encrypted it, and the next took istreams and an ostream and outputted it to the ostream. Then I made one that took file names and did the encryption which is pretty high level. But I didn't find that very practical as I wanted to add some extra stuff to my encrypt program (a GUI program) so I just copied the code onto my main program and did some change arounds. However, now I have problems with the second stage as well, that takes the streams, because I need to display a progress bar. The function just ran until the file was done encrypting. I could quite easily copy the code and add the extra code within my program or I could add like a function pointer the the encrypt function in the library, which would be run every time around the loop. I'm not really sure which to do, as copying the code is easier but maybe if I'd also like to have a nicely lay-outed library which could be quite versatile. My question is in general should you try to add to a general function to work for your case or just copy the code into your program and take the easy way out?

Thanks in advance
Last edited on
You should make the library function work for all common use cases. If it cannot satisfy those, it kind of defeats the purpose of having a library in the first place.
Your particular problem with displaying progress is solved by adding a callback function.

Then I made one that took file names and did the encryption which is pretty high level.

A function that takes streams instead of filenames is higher level - it works for normal files, for data in memory, for data generated on-the-fly by a function, for network streams etc.
Last edited on
Ok thanks for the reply, I'll try to add a callback
Topic archived. No new replies allowed.