 |
|
 |
it works, but it worked slower than CFileFind
|
|
|
|
 |
|
 |
Hi there,
neither me nor my compiler (VC++6, no MFC) know the type "reference" in the definition of the operator*:
reference operator*(){
return _strfname;
}
What does that "reference" do? Is it MS-specific? (It is not a C++ keyword!!)
By the way - a smart solution in one step - if I only could compile it
Thanks in advance
bye
Gerald
|
|
|
|
 |
|
 |
I changed reference to std::string and everything seems to work.
But really I'm not sure if the substitution is correct.
Ciao!
mario
|
|
|
|
 |
|
 |
The "reference" type is not declared for iterator in VC6. Use the equivalent "value_type&", i.e.
value_type& operator*(){
return _strfname;
}
|
|
|
|
 |
|
 |
* Referencecounting related issues: The presented implementation has a number of issues, and hardly ever works except for the most trivial case. To illustrate this, take a look at this code snippet:win32_file_iterator* pwfit = new win32_file_iterator( "C:\\*.*" );
win32_file_iterator wfit = *pwfit;
delete pwfit;
Similar issues exist for the auto-generated assignment operator. A possible solution could be to use a static std::map<HANDLE, unsigned int> _handleReferences; member, and to insert code that deals with self-assignment, both for the copy-c'tor and the assignment operator.
While this solves the issues of reference counting, a more significant issue still remains: since the FindXyzFile API calls aren't stateless, a shared resource introduces a more severe problem. Operating on any given iterator potentially also silently modifies the state of another, in a worst-case scenario even to a point where it's state goes out of sync (see _bEnd).
* operator== and operator!=: First of all, unless there is a reason not to (like performance issues), these operators should always share a common implementation, i.e. operator!= should be expressed in terms of !operator==. More importantly, though, they should expose proper semantics. In the current implementation, all iterators are split in 2 groups, with members in each one comparing equal to any given other of that same group.
* post- and prefix increment operators: Again, the semantics are off. While the prefix operator is fine as it is, the postfix operator should return a temporary value that reflects the state of the iterator prior to the operation.
To sum it up, once you get rid of the shared handles, the remaining troublesome operators will be more natural to implement, and on top of that, expose more accurate semantics.
.f
|
|
|
|
 |
|
 |
A brilliant use of the STL iterator!
|
|
|
|
 |
|
 |
For the internal handle, you could use the boost::shared_ptr handle wrapper idea (posted here on codeproject). That way the FindClose (or any handle closure) is neatly wrapped up within it.
These kinds of articles, simple good ideas, makes me happy
|
|
|
|
 |
|
 |
Thanks for the good idea..
and complement..
Best Regards.
Bektek
|
|
|
|
 |
|
 |
Iterator class looks good and I like it (you got a 5 from me!) ...
In the constructor, the string parameter should be passed as a const reference, otherwise you will incur an unnecessary string copy during iterator creation with this constructor.
|
|
|
|
 |
|
 |
yeah.. exactly..
you're right..
Best Regards.
Bektek
|
|
|
|
 |
|
|
 |
|
 |
It sounds good.. thanks for the good info..
I'll check it out soon..
Best Regards.
Bektek
|
|
|
|
 |
|
 |
Sorry but you've lost me there. The thing about STL is that it is portable, cross-platform. Why would you want to make something so hardbound to Win32?? As good as it might be, if I'm going to learn something else than Win32, I might as well go for a cross-platform approach such as wxWidgets (previously wxWindows) http://www.wxwidgets.com. Else, the shared_ptr approach to Win32 handles suffices nicely.
/Rob
|
|
|
|
 |
|
 |
Hi Rob, Yes I agree. I personally use Boost and STL wherever it makes sense. I don't use WinSTL, however I thought it would be of interest to CP readers. I think some of the other libraries maybe portable, but I've not used any of them so I can't say for sure.
Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
|
|
|
|
 |
|
 |
Robert Bielik wrote:
The thing about STL is that it is portable, cross-platform. Why would you want to make something so hardbound to Win32??
Counter-question: How would you have implemented the iterator in a cross-platform manner?
The short answer is: You cannot.
The longer answer is, that generic programming is about providing a portable interface, rather than a portable implementation. And that's exactly what the STL does itself. Take for example operator new, that directly or indirectly calls into OS specific API's. Would that make it really non-portable? Or wouldn't you agree that the common interface is sufficient for being portable. The same is true for the win32_file_iterator class, which exposes a portable interface, and should you ever find yourself in a situation to port to a different platform, all you really had to do is provide a platform-specific implementation, with the rest of your source base remaining unchanged.
On a similar note, wxWidgest looks exactly the same under the hood. It's just that you never really get in touch with those implementation details. Your mistake, however, is that you deduce from a portable interface that the implementation is equally platform-independent.
.f
|
|
|
|
 |
|
 |
Sorry, no mistake on my part. You must have misunderstood. I have no problem with the _implementation_ being hardwired to the platform. As you said, implementation cannot be cross-platform. Of course it is the interfaces that are to be abstracted. But WinSTL (which was the topic) has some interfaces that only makes sense on a Windows platform (registry/windows directory etc), and rightfully so, since it doesn't purport being cross-platform.
So, again: If you need to learn something NEW, I'd recommend going for a cross-platform library (like wxWidgets f.i.), because that would give a head start if you'd want to write cross-platform software. Otherwise simpler solutions suffice.
|
|
|
|
 |
|
 |
I'll give this a try in my game. I'm using stl and not looking to add boost as well. Was looking for a quick way to get screenshot## and find highest one so I can save yet another. Er before I get too excited is this only for .net? I'm just using regular unleaded c++. Well if not guess I will have to delve into boost.
|
|
|
|
 |
|
|
 |
|
 |
I know, I know as I said
|
|
|
|
 |
|
 |
I did, and decided not to use it, because it does not support Unicode on Win32. That means it only works for file names from a single code page.
Keith
|
|
|
|
 |
|
 |
Further, boost::filesystem has problems while compiling in MS VC6.
Dan.
|
|
|
|
 |
|
 |
It's a bit harsh blaming boost libraries for not being usable with MS VC6. It does not conform to the relevant C++ standards, whereas VC7.1 does.
Keith
|
|
|
|
 |
|
 |
I tried to compile boost library, but i had some prolems... Library compiled without any error, but I couldn't include it into my project.
I'm using VC++ 6 and STLport-4.5.3, I gave right options during compilation (msvc-stlport e STLPORT_PATH) and I inserted the right path for includes and libraries in Options->Directories
When I compile my project in Debug mode, VC gives me this error:
warning: STLPort debug versions are built with /D_STLP_DEBUG=1
c:\librerie\boost_1_32_0\boost\config\auto_link.hpp(170) : fatal error C1189: #error : "Build options aren't compatible with pre-built libraries"
Otherwise, when I compile in Release mode sometimes VC gives me link error - unresolved externals!
Any ideas? Thank you very much
Gianluca Nastasi
|
|
|
|
 |
|
 |
I'm not pretty sure.. anyway are you trying to use boost::filesystem library?
If you are, just try to change the code generation mode to 'multithreaded mode'
I remember I did it, and then succeeded to compile it.
But It caused kinda infinite loop at runtime as I remember,,
It might have some bugs related to boost::thread library with VS6
That's why I changed my IDE to vs.net 2003..
then everything is OK and fine..
I hope it helps you..
Best Regards.
Bektek
|
|
|
|
 |
|
 |
Yes, I'm trying to use boost::filesystem...
I setted the right options in code generation too, but I can't work it out
Thanks a lot!
Sadly, I must use VC++ 6 'couse of my job!
I'd prefer programming for linux with gcc!
Bye
Gianluca Nastasi
|
|
|
|
 |