cpp-hocon  0.3.0
Public Member Functions | List of all members
hocon::config_origin Class Referenceabstract

Represents the origin (such as filename and line number) of a config_value for use in error messages. More...

Inheritance diagram for hocon::config_origin:
hocon::simple_config_origin

Public Member Functions

virtual LIBCPP_HOCON_EXPORT std::string const & description () const =0
 Returns a string describing the origin of a value or exception. More...
 
virtual LIBCPP_HOCON_EXPORT shared_origin with_line_number (int line_number) const =0
 Returns a. More...
 
virtual LIBCPP_HOCON_EXPORT int line_number () const =0
 Returns a line number where the value or exception originated. More...
 
virtual LIBCPP_HOCON_EXPORT std::vector< std::string > const & comments () const =0
 Returns any comments that appeared to "go with" this place in the file. More...
 
virtual LIBCPP_HOCON_EXPORT shared_origin with_comments (std::vector< std::string > comments) const =0
 Returns a. More...
 

Detailed Description

Represents the origin (such as filename and line number) of a config_value for use in error messages.

Obtain the origin of a value with config_value#origin. Exceptions may have an origin, see config_exception#origin, but be careful because config_exception.origin() may return null.

It's best to use this interface only for debugging; its accuracy is "best effort" rather than guaranteed, and a potentially-noticeable amount of memory could probably be saved if origins were not kept around, so in the future there might be some option to discard origins.

Do not implement this interface; it should only be implemented by the config library. Arbitrary implementations will not work because the library internals assume a specific concrete implementation. Also, this interface is likely to grow new methods over time, so third-party implementations will break.

Definition at line 31 of file config_origin.hpp.

Member Function Documentation

◆ comments()

virtual LIBCPP_HOCON_EXPORT std::vector<std::string> const& hocon::config_origin::comments ( ) const
pure virtual

Returns any comments that appeared to "go with" this place in the file.

Often an empty list, but never null. The details of this are subject to change, but at the moment comments that are immediately before an array element or object field, with no blank line after the comment, "go with" that element or field.

Returns
any comments that seemed to "go with" this origin, empty list if none

Implemented in hocon::simple_config_origin.

◆ description()

virtual LIBCPP_HOCON_EXPORT std::string const& hocon::config_origin::description ( ) const
pure virtual

Returns a string describing the origin of a value or exception.

This will never return null.

Returns
string describing the origin

Implemented in hocon::simple_config_origin.

◆ line_number()

virtual LIBCPP_HOCON_EXPORT int hocon::config_origin::line_number ( ) const
pure virtual

Returns a line number where the value or exception originated.

This will return -1 if there's no meaningful line number.

Returns
line number or -1 if none is available

Implemented in hocon::simple_config_origin.

◆ with_comments()

virtual LIBCPP_HOCON_EXPORT shared_origin hocon::config_origin::with_comments ( std::vector< std::string >  comments) const
pure virtual

Returns a.

config_origin

based on this one, but with the given comments. Does not modify this instance or any

config_value

s with this origin (since they are immutable). To set the returned origin to a

config_value

, use config_value#with_origin.

Note that when the given comments are equal to the comments on this object, a new instance may not be created and

this

is returned directly.

Since
1.3.0
Parameters
commentsthe comments used on the returned origin
Returns
the config_origin with the given comments

Implemented in hocon::simple_config_origin.

◆ with_line_number()

virtual LIBCPP_HOCON_EXPORT shared_origin hocon::config_origin::with_line_number ( int  line_number) const
pure virtual

Returns a.

config_origin

based on this one, but with the given line number. This origin must be a FILE, URL or RESOURCE. Does not modify this instance or any

config_value

s with this origin (since they are immutable). To set the returned origin to a

config_value

, use config_value#withOrigin.

Note that when the given lineNumber are equal to the lineNumber on this object, a new instance may not be created and

this

is returned directly.

Since
1.3.0
Parameters
lineNumberthe new line number
Returns
the created config_origin

Implemented in hocon::simple_config_origin.


The documentation for this class was generated from the following file: