GEOSX
DataContext.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
7  * Copyright (c) 2018-2020 TotalEnergies
8  * Copyright (c) 2019- GEOSX Contributors
9  * All rights reserved
10  *
11  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
12  * ------------------------------------------------------------------------------------------------------------
13  */
14 
19 #ifndef GEOS_DATAREPOSITORY_DATACONTEXT_HPP_
20 #define GEOS_DATAREPOSITORY_DATACONTEXT_HPP_
21 
22 #include "common/DataTypes.hpp"
23 #include "common/Logger.hpp"
24 #include "xmlWrapper.hpp"
25 #include "common/Format.hpp"
26 
27 namespace geos
28 {
29 namespace dataRepository
30 {
31 
32 
42 {
43 public:
44 
49  DataContext( string const & targetName );
50 
54  virtual ~DataContext() {}
55 
60  virtual string toString() const = 0;
61 
65  string getTargetName() const
66  { return m_targetName; }
70  friend std::ostream & operator<<( std::ostream & os, const DataContext & ctx );
71 
72 protected:
73  // GroupContext & WrapperContext are friend class to be able to access to the protected method on other instances.
74  friend class GroupContext;
75  friend class WrapperContext;
76 
78  string const m_targetName;
79 
82  struct ToStringInfo
83  {
85  string m_targetName;
87  string m_filePath;
90 
97  ToStringInfo( string const & targetName, string const & filePath, size_t line );
102  ToStringInfo( string const & targetName );
106  bool hasInputFileInfo() const
107  { return !m_filePath.empty() && m_line != xmlWrapper::xmlDocument::npos; }
108  };
109 
115  virtual ToStringInfo getToStringInfo() const = 0;
116 
117 };
118 
125 class DataFileContext final : public DataContext
126 {
127 public:
128 
134  DataFileContext( xmlWrapper::xmlNode const & targetNode, xmlWrapper::xmlNodePos const & nodePos );
142  xmlWrapper::xmlAttributePos const & attPos );
143 
147  string toString() const override;
148 
152  string getTypeName() const
153  { return m_typeName; }
154 
158  string getFilePath() const
159  { return m_filePath; }
160 
164  size_t getLine() const
165  { return m_line; }
166 
171  size_t getOffsetInLine() const
172  { return m_offsetInLine; }
173 
178  size_t getOffset() const
179  { return m_offset; }
180 
181 private:
182 
184  string const m_typeName;
186  string const m_filePath;
188  size_t const m_line;
190  size_t const m_offsetInLine;
192  size_t const m_offset;
193 
197  ToStringInfo getToStringInfo() const override;
198 
199 };
200 
201 
202 } /* namespace dataRepository */
203 } /* namespace geos */
204 
205 
206 
211 template<>
212 struct GEOS_FMT_NS::formatter< geos::dataRepository::DataContext > : GEOS_FMT_NS::formatter< std::string >
213 {
220  auto format( geos::dataRepository::DataContext const & dataContext, format_context & ctx )
221  {
222  return GEOS_FMT_NS::formatter< std::string >::format( dataContext.toString(), ctx );
223  }
224 };
225 
226 #endif /* GEOS_DATAREPOSITORY_DATACONTEXT_HPP_ */
virtual ToStringInfo getToStringInfo() const =0
This method exposes the raw data of a DataContext, in order to access and format it (notably in toStr...
virtual string toString() const =0
DataContext(string const &targetName)
Construct a new DataContext object.
friend std::ostream & operator<<(std::ostream &os, const DataContext &ctx)
Insert contextual information in the provided stream.
virtual ~DataContext()
Destroy the DataContext object.
Definition: DataContext.hpp:54
DataFileContext(xmlWrapper::xmlNode const &targetNode, xmlWrapper::xmlAttribute const &att, xmlWrapper::xmlAttributePos const &attPos)
Construct the file context of a Group from an xml node.
DataFileContext(xmlWrapper::xmlNode const &targetNode, xmlWrapper::xmlNodePos const &nodePos)
Construct the file context of a Group from an xml node.
string toString() const override
static constexpr size_t npos
Error value for when an offset / line position is undefined.
Definition: xmlWrapper.hpp:148
pugi::xml_node xmlNode
Definition: xmlWrapper.hpp:57
pugi::xml_attribute xmlAttribute
Definition: xmlWrapper.hpp:62
auto format(geos::dataRepository::DataContext const &dataContext, format_context &ctx)
Format the specified DataContext to a string.
ToStringInfo(string const &targetName, string const &filePath, size_t line)
Construct a new ToStringInfo object from a DataContext that has input file info.
size_t m_line
the file line of the DataFileContext, if it exists (an empty string otherwise)
Definition: DataContext.hpp:89
ToStringInfo(string const &targetName)
Construct a new ToStringInfo object from a DataContext that has no input file info.
string m_filePath
the file path of the DataFileContext, if it exists (an empty string otherwise)
Definition: DataContext.hpp:87
string m_targetName
the targetName of the DataContext
Definition: DataContext.hpp:85