CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
SourcePosition.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
11
14
15#include <memory>
16
18
26
28
29 // This class stores the position in a source code file.
31 private:
34
36
37 public:
38 // Invalid source position.
39 static const SourcePosition ignore;
40
41 SourcePosition() = default;
42 SourcePosition(UInt32 row, UInt32 column, const SourceOriginPtr& origin = nullptr);
43
44 public:
45 // Returns the source position as string in the format "Row:Column", e.g. "75:10".
46 [[nodiscard]] String toString(bool printFilename = true) const;
47
48 // Increases the row by 1 and sets the column to 0.
50
51 // Increases the column by 1.
53
54 // Returns true if this is a valid source position. False if row and column are 0.
55 [[nodiscard]] bool isValid() const;
56
57 // Reset the source position to (0:0).
58 void reset();
59
60 // Makes a strict-weak-order comparison between the two source positions.
61 bool operator<(const SourcePosition& rhs) const;
62
63 // Returns the row of the source position, beginning with 1.
64 [[nodiscard]] inline UInt32 getRow() const { return mRow; }
65
66 // Returns the column of the source position, beginning with 1.
67 [[nodiscard]] inline UInt32 getColumn() const { return mColumn; }
68
69 // Sets the new source origin.
70 inline void setOrigin(const SourceOriginPtr& origin) { mOrigin = origin; }
71
72 // Returns the current origin.
73 [[nodiscard]] inline const SourceOrigin* getOrigin() const { return mOrigin.get(); }
74
75 // Equivalent to a call to 'IsValid()'.
76 inline explicit operator bool() const { return isValid(); }
77 };
78
79} // namespace CeresEngine::ShaderCompiler
Definition SourcePosition.hpp:30
UInt32 mRow
Definition SourcePosition.hpp:32
UInt32 mColumn
Definition SourcePosition.hpp:33
SourcePosition(UInt32 row, UInt32 column, const SourceOriginPtr &origin=nullptr)
UInt32 getColumn() const
Definition SourcePosition.hpp:67
static const SourcePosition ignore
Definition SourcePosition.hpp:39
const SourceOrigin * getOrigin() const
Definition SourcePosition.hpp:73
SourceOriginPtr mOrigin
Definition SourcePosition.hpp:35
UInt32 getRow() const
Definition SourcePosition.hpp:64
bool operator<(const SourcePosition &rhs) const
void setOrigin(const SourceOriginPtr &origin)
Definition SourcePosition.hpp:70
String toString(bool printFilename=true) const
Definition AST.hpp:33
SPtr< SourceOrigin > SourceOriginPtr
Definition SourcePosition.hpp:27
std::shared_ptr< T > SPtr
SPtr is a smart pointer that retains shared ownership of an object through a pointer.
Definition SmartPtr.hpp:37
std::int32_t Int32
Definition DataTypes.hpp:21
std::uint32_t UInt32
Definition DataTypes.hpp:23
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Source code origin with filename and line offset.
Definition SourcePosition.hpp:22
String filename
Definition SourcePosition.hpp:23
Int32 lineOffset
Definition SourcePosition.hpp:24