Click here to Skip to main content
13,146,014 members (41,379 online)
Click here to Skip to main content

Stats

23.5K views
997 downloads
37 bookmarked
Posted 29 Jun 2009

REG file parser using the Boost Spirit Parser Framework

This article describes a sample parser of reg files using the Boost Spirit Parser Framework. We'll discuss why we use the curtain libraries and make one or another solution, algorithm, and also tests.
RegFileParser_bin
bin
RegFileParserAutoTest.exe
RegFileParserTestCmd.exe
RegFileParser_source
src
boost_libs
libboost_program_options-vc90-mt-s-1_38.lib
libboost_program_options-vc90-mt-sgd-1_38.lib
RegFileParserAutoTest
TestFiles
RegFileParserLib
RegFileParserTestCmd
RegFileParserTestCmd.idc
RegFileParser_source_no_boost
src
RegFileParserAutoTest
TestFiles
RegFileParserLib
RegFileParserTestCmd
RegFileParserTestCmd.idc
#ifndef __STATUS_OBSERVER_H_INCLUDED__
#define __STATUS_OBSERVER_H_INCLUDED__

#include "IRegFileObserver.hpp"
#include <string>

namespace reg_parser
{

template<class charT,class streamT>
class CRegStatusObserver:public IRegFileObserver<charT>
{
    size_t bufferStart_;
    size_t bufferSize_;
    size_t previousStatus_;

	streamT& out_;
public:
    CRegStatusObserver(size_t bufferStart,
					   size_t bufferSize,
					   streamT& out)
        : bufferStart_(bufferStart)
		, bufferSize_(bufferSize)
		, previousStatus_(0)
		, out_(out)
    {}
	
    void OnKeyFound(const charT* begin, const charT* end)
    {
        UpdateStatus((size_t)end);
    }

    void OnValueFound(const charT* nameBegin, const charT* nameEnd,
                      const charT* dataBegin, const charT* dataEnd)
    {
        UpdateStatus((size_t)dataEnd);
    }
private:
    void UpdateStatus(size_t end)
    {
        float percent = (float)((size_t)end - bufferStart_)/bufferSize_;
        size_t status = (size_t)percent*100;
        if( (previousStatus_) < status )
        {
            previousStatus_ = status;
            out_ << "\r     " << "\r" << status << "%"; 
        }
    }
};

}//namespace reg_parser

#endif // __STATUS_OBSERVER_H_INCLUDED__

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Authors

Apriorit Inc
Apriorit Inc.
Hungary Hungary
This member doesn't quite have enough reputation to be able to display their biography and homepage.
Group type: Organisation

32 members


Ivan Romanenko
Software Developer Codedgers Inc
Ukraine Ukraine
No Biography provided

You may also be interested in...

Pro
Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170915.1 | Last Updated 30 Jun 2009
Article Copyright 2009 by Apriorit Inc, Ivan Romanenko
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid