GEOS
DataContext.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 Total, S.A
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
20 #ifndef GEOS_DATAREPOSITORY_DATACONTEXT_HPP_
21 #define GEOS_DATAREPOSITORY_DATACONTEXT_HPP_
22 
23 #include "common/DataTypes.hpp"
24 #include "common/logger/Logger.hpp"
25 #include "xmlWrapper.hpp"
26 #include "common/format/Format.hpp"
27 
28 namespace geos
29 {
30 namespace dataRepository
31 {
32 
33 
43 {
44 public:
45 
50  DataContext( string const & targetName );
51 
55  virtual ~DataContext() {}
56 
61  virtual string toString() const = 0;
62 
66  string getTargetName() const
67  { return m_targetName; }
71  friend std::ostream & operator<<( std::ostream & os, const DataContext & ctx );
72 
73 protected:
74  // GroupContext & WrapperContext are friend class to be able to access to the protected method on other instances.
75  friend class GroupContext;
76  friend class WrapperContext;
77 
79  string const m_targetName;
80 
83  struct ToStringInfo
84  {
86  string m_targetName;
88  string m_filePath;
91 
98  ToStringInfo( string const & targetName, string const & filePath, size_t line );
103  ToStringInfo( string const & targetName );
107  bool hasInputFileInfo() const
108  { return !m_filePath.empty() && m_line != xmlWrapper::xmlDocument::npos; }
109  };
110 
116  virtual ToStringInfo getToStringInfo() const = 0;
117 
118 };
119 
126 class DataFileContext final : public DataContext
127 {
128 public:
129 
135  DataFileContext( xmlWrapper::xmlNode const & targetNode, xmlWrapper::xmlNodePos const & nodePos );
143  xmlWrapper::xmlAttributePos const & attPos );
144 
148  string toString() const override;
149 
153  string getTypeName() const
154  { return m_typeName; }
155 
159  string getFilePath() const
160  { return m_filePath; }
161 
165  size_t getLine() const
166  { return m_line; }
167 
172  size_t getOffsetInLine() const
173  { return m_offsetInLine; }
174 
179  size_t getOffset() const
180  { return m_offset; }
181 
182 private:
183 
185  string const m_typeName;
187  string const m_filePath;
189  size_t const m_line;
191  size_t const m_offsetInLine;
193  size_t const m_offset;
194 
198  ToStringInfo getToStringInfo() const override;
199 
200 };
201 
202 
203 } /* namespace dataRepository */
204 } /* namespace geos */
205 
206 
207 
212 template<>
213 struct GEOS_FMT_NS::formatter< geos::dataRepository::DataContext > : GEOS_FMT_NS::formatter< std::string >
214 {
221  auto format( geos::dataRepository::DataContext const & dataContext, format_context & ctx ) const
222  {
223  return GEOS_FMT_NS::formatter< std::string >::format( dataContext.toString(), ctx );
224  }
225 };
226 
227 #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:55
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:150
pugi::xml_node xmlNode
Definition: xmlWrapper.hpp:59
pugi::xml_attribute xmlAttribute
Definition: xmlWrapper.hpp:64
auto format(geos::dataRepository::DataContext const &dataContext, format_context &ctx) const
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:90
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:88
string m_targetName
the targetName of the DataContext
Definition: DataContext.hpp:86