Reputation: 43014
I was able to use Boost Iterator Facade to build a custom Single Pass Iterator to iterate (in a C++ way) through the values contained in a Windows registry key, wrapping the C API RegEnumValue
.
E.g.:
// For each value 'v' under the given registry key 'hKey':
for (const auto& v : RegistryValueIterator(hKey))
{
...
}
Basically, the iterator's increment
method calls RegEnumValue
increasing the dwIndex
parameter (initially set to 0 in the iterator class constructor), and when ERROR_NO_MORE_ITEMS
is returned, that is mapped to the "end" iterator.
I've used the boost::single_pass_traversal_tag
:
class RegistryValueIterator
: public boost::iterator_facade< RegistryValueIterator,
RegistryValueEntry,
boost::single_pass_traversal_tag >
{
...
Boost.Filesystem's directory_iterator
, which wraps the FindNextFile
API in the Windows implementation, is implemented as a single-pass iterator, too. And similarly, the std::experimental::filesystem::directory_iterator
is an Input Iterator as well (not a Forward Iterator).
So, would it be possible for registry enumeration to upgrade the iterator category to a Forward Traversal Iterator? What steps should I follow to achieve that goal?
In other words, would it be possible to implement a multi-pass traversal required by Forward Traversal Iterators using the Windows registry APIs like RegEnumValue
? If so, how?
P.S. I've discussed registry value enumeration/iteration, but things are very similar for enumerating/iterating through registry keys as well, using the RegEnumKeyEx
API.
Upvotes: 1
Views: 235