aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorGravatar Sadie Powell2020-11-03 19:40:42 +0000
committerGravatar Sadie Powell2020-11-03 19:54:13 +0000
commit373bc208ff8f7eceecd944114cd729b5a348d918 (patch)
tree3fc6cc31e70a00cb9670b3724e0c94256f763385 /include
parentReplace ConfigTag::create with a public constructor. (diff)
Move FilePosition to fileutils.h and use in ConfigTag.
Diffstat (limited to 'include')
-rw-r--r--include/configreader.h14
-rw-r--r--include/fileutils.h24
2 files changed, 30 insertions, 8 deletions
diff --git a/include/configreader.h b/include/configreader.h
index bd15dd586..e336e057b 100644
--- a/include/configreader.h
+++ b/include/configreader.h
@@ -51,15 +51,15 @@ public:
public:
const std::string tag;
- const std::string src_name;
- const int src_line;
+
+ /** The position within the source file that this tag was read from. */
+ const FilePosition source;
/** Creates a new ConfigTag instance with the specified tag name, file, and line.
* @param Tag The name of this config tag (e.g. "foo" for \<foo>).
- * @param file The file this config tag was read from.
- * @param line The line of \p file that this config tag exists in.
+ * @param Source The source of this config tag.
*/
- ConfigTag(const std::string& Tag, const std::string& file, int line);
+ ConfigTag(const std::string& Tag, const FilePosition& Source);
/** Get the value of an option, using def if it does not exist */
std::string getString(const std::string& key, const std::string& def, const std::function<bool(const std::string&)>& validator) const;
@@ -98,7 +98,7 @@ public:
std::vector<const char*> enumkeys;
std::transform(enumvals.begin(), enumvals.end(), std::back_inserter(enumkeys), [](const std::pair<const char*, TReturn>& ev) { return ev.first; });
throw ModuleException(val + " is an invalid value for <" + tag + ":" + key + ">; acceptable values are " +
- stdalgo::string::join(enumkeys, ' ') + ", at " + getTagLocation());
+ stdalgo::string::join(enumkeys, ' ') + ", at " + source.str());
}
/** Get the value of an option
@@ -109,8 +109,6 @@ public:
*/
bool readString(const std::string& key, std::string& value, bool allow_newline = false) const;
- std::string getTagLocation() const;
-
/** Retrieves the underlying map of config entries. */
inline const Items& GetItems() const { return items; }
inline Items& GetItems() { return items; }
diff --git a/include/fileutils.h b/include/fileutils.h
index 1bbdf9c01..377a76d75 100644
--- a/include/fileutils.h
+++ b/include/fileutils.h
@@ -20,6 +20,30 @@
#pragma once
+/** Represents the position within a file. */
+class CoreExport FilePosition
+{
+ public:
+ /** The name of the file that the position points to. */
+ std::string name;
+
+ /** The line of the file that this position points to. */
+ unsigned int line;
+
+ /** The column of the file that this position points to. */
+ unsigned int column;
+
+ /** Initialises a new file position with the specified name, line, and column.
+ * @param name The name of the file that the position points to.
+ * @param line The line of the file that this position points to.
+ * @param column The column of the file that this position points to.
+ */
+ FilePosition(const std::string& Name, unsigned int Line = 1, unsigned int Column = 1);
+
+ /** Returns a string that represents this file position. */
+ std::string str() const;
+};
+
/** Provides an easy method of reading a text file into memory. */
class CoreExport FileReader
{