summaryrefslogtreecommitdiffstats
path: root/Source/cmXCOFF.h
blob: f6d9d94ec8b55148e62b6ba047cc2a0325938e29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
#pragma once

#include "cmConfigure.h" // IWYU pragma: keep

#include <iosfwd>
#include <memory>
#include <string>

#include <cm/optional>
#include <cm/string_view>

#if !defined(CMake_USE_XCOFF_PARSER)
#  error "This file may be included only if CMake_USE_XCOFF_PARSER is enabled."
#endif

class cmXCOFFInternal;

/** \class cmXCOFF
 * \brief XCOFF parser.
 */
class cmXCOFF
{
public:
  enum class Mode
  {
    ReadOnly,
    ReadWrite
  };

  /** Construct with the name of the XCOFF input file to parse.  */
  cmXCOFF(const char* fname, Mode = Mode::ReadOnly);

  /** Destruct.   */
  ~cmXCOFF();

  cmXCOFF(cmXCOFF&&) noexcept;
  cmXCOFF(cmXCOFF const&) = delete;
  cmXCOFF& operator=(cmXCOFF&&) noexcept;
  cmXCOFF& operator=(cmXCOFF const&) = delete;

  /** Get the error message if any.  */
  std::string const& GetErrorMessage() const { return this->ErrorMessage; }

  /** Boolean conversion.  True if the XCOFF file is valid.  */
  explicit operator bool() const { return this->Valid(); }

  /** Get the LIBPATH (RPATH) parsed from the file, if any.  */
  cm::optional<cm::string_view> GetLibPath() const;

  /** Set the LIBPATH (RPATH).
      Works only if cmXCOFF was constructed with Mode::ReadWrite.  */
  bool SetLibPath(cm::string_view libPath);

  /** Remove the LIBPATH (RPATH).
      Works only if cmXCOFF was constructed with Mode::ReadWrite.  */
  bool RemoveLibPath();

private:
  friend class cmXCOFFInternal;
  bool Valid() const;
  std::unique_ptr<cmXCOFFInternal> Internal;
  std::string ErrorMessage;
};