#ifndef VGS_PROCTOOLS_EXTRACT_H
#define VGS_PROCTOOLS_EXTRACT_H

#include <sstream>
#include <string>

namespace proctools_broken
{

	class extract
	{
	public:
		extract(const std::string& value);

		template<typename T>
		extract& operator>>(T& target);

		template<typename T>
		extract& operator>>(const T& target);

		extract& operator>>(const char* literal);

		//template<typename To>
		//To as(void);

		//void ignore(const std::string& what_);
		//void clear(void) { m_parser.clear(); m_parser << m_val; }

		operator bool() { return m_parser.good() || m_parser.eof(); }

	private:
		std::stringstream m_parser;
	};

	template<typename T>
	extract& extract::operator>>(T& target)
	{
		if (m_parser.good())
			m_parser >> target;
		return *this;
	}

	template<typename T>
	extract& extract::operator>>(const T& what)
	{
		if (m_parser.good()) {
			T target(what);
			m_parser >> target;
		}
		return *this;
	}

	/*template<typename From>
	template<typename To>
	To extract<From>::as(void)
	{
		if (!m_parser.good())
			return To();

		To result;
		m_parser >> result;
		return result;
	}

	template<typename From>
	void extract<From>::ignore(const std::string& what_)
	{
		if (!m_parser.good())
			return;

		char buffer[what_.length()];
		int count = m_parser.readsome(buffer, what_.length());

		std::string text(buffer, count);
		if (text != what_)
			m_parser.setstate(std::ios::failbit);
	}*/

}

#endif // VGS_PROCTOOLS_EXTRACT_H
