2018-08-28 08:16:52 +01:00
|
|
|
/* This file is part of the sirit project.
|
|
|
|
* Copyright (c) 2018 ReinUsesLisp
|
|
|
|
* This software may be used and distributed according to the terms of the GNU
|
2018-11-16 07:10:10 +00:00
|
|
|
* Lesser General Public License version 3 or any later version.
|
2018-08-28 08:16:52 +01:00
|
|
|
*/
|
|
|
|
|
2019-06-08 09:23:15 +01:00
|
|
|
#include <functional>
|
2018-11-01 00:22:00 +00:00
|
|
|
#include <string>
|
2019-03-11 06:26:21 +00:00
|
|
|
#include "common_types.h"
|
|
|
|
#include "literal_string.h"
|
2018-08-28 08:16:52 +01:00
|
|
|
|
|
|
|
namespace Sirit {
|
|
|
|
|
2019-03-14 06:52:54 +00:00
|
|
|
LiteralString::LiteralString(std::string string) : string{std::move(string)} {
|
2018-08-28 08:16:52 +01:00
|
|
|
operand_type = OperandType::String;
|
|
|
|
}
|
|
|
|
|
|
|
|
LiteralString::~LiteralString() = default;
|
|
|
|
|
|
|
|
void LiteralString::Fetch(Stream& stream) const {
|
2018-10-23 09:09:17 +01:00
|
|
|
for (std::size_t i = 0; i < string.size(); i++) {
|
2018-08-28 08:16:52 +01:00
|
|
|
stream.Write(static_cast<u8>(string[i]));
|
|
|
|
}
|
2018-10-23 09:09:17 +01:00
|
|
|
for (std::size_t i = 0; i < 4 - (string.size() % 4); i++) {
|
2018-08-28 08:16:52 +01:00
|
|
|
stream.Write(static_cast<u8>(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u16 LiteralString::GetWordCount() const {
|
|
|
|
return static_cast<u16>(string.size() / 4 + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LiteralString::operator==(const Operand& other) const {
|
|
|
|
if (operand_type == other.GetType()) {
|
|
|
|
return dynamic_cast<const LiteralString&>(other).string == string;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-06-08 09:23:15 +01:00
|
|
|
std::size_t LiteralString::Hash() const {
|
|
|
|
return Operand::Hash() ^ std::hash<std::string>{}(string);
|
|
|
|
}
|
|
|
|
|
2018-08-28 08:16:52 +01:00
|
|
|
} // namespace Sirit
|