Belle II Software  release-05-02-19
StringHandler.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2011 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <framework/gearbox/InputHandler.h>
14 #include <sstream>
15 
16 namespace Belle2 {
21  namespace gearbox {
23  class StringContext: public InputContext {
24  public:
26  explicit StringContext(const std::string& data): m_stream(data) {};
28  virtual int readXmlData(char* buffer, int buffsize) override
29  {
30  m_stream.read(buffer, buffsize);
31  return m_stream.gcount();
32  }
33  protected:
35  std::istringstream m_stream;
36  };
37 
44  class StringHandler: public InputHandler {
45  public:
47  explicit StringHandler(const std::string& uri): InputHandler(uri) {}
49  virtual ~StringHandler() {}
51  virtual InputContext* open(const std::string& path) override;
52  };
53  }
55 }
Belle2::gearbox::StringContext::readXmlData
virtual int readXmlData(char *buffer, int buffsize) override
Return a block of the data.
Definition: StringHandler.h:36
Belle2::gearbox::StringContext::StringContext
StringContext(const std::string &data)
Take an XML fragment as parameter and create a context for it.
Definition: StringHandler.h:34
Belle2::gearbox::StringHandler::~StringHandler
virtual ~StringHandler()
empty, virtual destructor
Definition: StringHandler.h:57
Belle2::gearbox::InputHandler::InputHandler
InputHandler(const std::string &uri)
Constructor accepting the uri for the InputHandler.
Definition: InputHandler.h:73
Belle2::gearbox::StringHandler
InputHandler which just takes the uri as XML data.
Definition: StringHandler.h:52
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::gearbox::StringHandler::StringHandler
StringHandler(const std::string &uri)
Create a new InputHandler which always returns uri as XML content.
Definition: StringHandler.h:55
Belle2::gearbox::StringHandler::open
virtual InputContext * open(const std::string &path) override
Create a new context, path will be ignored.
Definition: StringHandler.cc:19
Belle2::gearbox::StringContext::m_stream
std::istringstream m_stream
Assigned data string.
Definition: StringHandler.h:43
Belle2::gearbox::InputHandler
Class to provide an InputContext for a given XML resource name.
Definition: InputHandler.h:57