コード例 #1
0
ファイル: Calculator.cpp プロジェクト: alisa-teplouhova/Calc
double Calculator::parseExprSum(std::string_view &ref)
{
	double value = parseExprMul(ref);
	while (true)
	{
		skipSpaces(ref);
		if (!ref.empty() && ref[0] == '+')
		{
			ref.remove_prefix(1);
			value += parseExprMul(ref);
			m_printStrategy->printAddition();
		}
		else if (!ref.empty() && ref[0] == '-')
		{
			ref.remove_prefix(1);
			value -= parseExprMul(ref);
			m_printStrategy->printSubstraction();
		}
		else
		{
			break;
		}
	}

	return value;
}
コード例 #2
0
ファイル: Calculator.cpp プロジェクト: alisa-teplouhova/Calc
double Calculator::parseExprMul(std::string_view &ref)
{
	double value = parseSymbol(ref);
	while (true)
	{
		skipSpaces(ref);
		if (!ref.empty() && ref[0] == '*')
		{
			ref.remove_prefix(1);
			value *= parseSymbol(ref);
			m_printStrategy->printMultiplication();
		}
		else if (!ref.empty() && ref[0] == '/')
		{
			ref.remove_prefix(1);
			value /= parseSymbol(ref);
			m_printStrategy->printDivision();
		}
		else
		{
			break;
		}
	}

	return value;
}
コード例 #3
0
ファイル: Calculator.cpp プロジェクト: alisa-teplouhova/Calc
double Calculator::parseSymbol(std::string_view &ref)
{
	double value = 0;
	skipSpaces(ref);
	if (!ref.empty() && ref[0] == '(')
	{
		ref.remove_prefix(1);
		value = parseExprSum(ref);
		skipSpaces(ref);
		if (!ref.empty() && ref[0] == ')')
		{
			ref.remove_prefix(1);
			return value;
		}
		else
		{
			return std::numeric_limits<double>::quiet_NaN();
		}
	}
	else if (!ref.empty() && !std::isdigit(ref[0]) && ref[0] != '-')
	{
		return parseFunction(ref);
	}
	else
	{
		return parseDouble(ref);
	}
}
コード例 #4
0
ファイル: Calculator.cpp プロジェクト: alisa-teplouhova/Calc
double Calculator::parseDouble(std::string_view &ref)
{
	double value = 0;
	bool isNegative = false;
	bool parsedAny = false;

	skipSpaces(ref);
	if (!ref.empty() && ref[0] == '-')
	{
		isNegative = true;
		ref.remove_prefix(1);
	}
	skipSpaces(ref);

	while (!ref.empty() && std::isdigit(ref[0]))
	{
		parsedAny = true;
		const int digit = ref[0] - '0';
		value = value * 10.0f + double(digit);
		ref.remove_prefix(1);
	}

	if (!parsedAny)
	{
		return std::numeric_limits<double>::quiet_NaN();
	}

	if (isNegative)
	{
		value *= -1;
	}

	if (ref.empty() || (ref[0] != '.'))
	{
		m_printStrategy->printNumber(value);
		return value;
	}

	ref.remove_prefix(1);
	double factor = 1.f;
	while (!ref.empty() && std::isdigit(ref[0]))
	{
		const int digit = ref[0] - '0';
		factor *= 0.1f;
		value += factor * double(digit);
		ref.remove_prefix(1);
	}

	m_printStrategy->printNumber(value);
	return value;
}
コード例 #5
0
ファイル: Dialer.hpp プロジェクト: Jackson-soft/LongDemo
	//连接到网络地址
	bool
	Dial(std::string_view network, std::string_view ip, unsigned short port)
	{
		if (network.empty() || ip.empty() || port <= 0) {
			return false;
		}
		mRemoteAddr = std::move(ip);
		mPort		= port;

		if (!mSocket.NewSocket(network))
			return false;

		return mSocket.Connect(port, ip) == 0 ? true : false;
	}
コード例 #6
0
	void CArchiveExtractCallback::Init(std::string_view pw, std::shared_ptr<ISequentialOutStream> const & outFileStream)
	{
		_outFileStream = outFileStream;

		password_is_defined_ = !pw.empty();
		Convert(password_, pw);
	}
コード例 #7
0
ファイル: Player.cpp プロジェクト: dgengin/DGEngine
void Player::setProperty(const std::string_view prop, const Variable& val)
{
	if (prop.empty() == true)
	{
		return;
	}
	auto propHash16 = str2int16(prop);
	switch (propHash16)
	{
	case str2int16("name"):
	{
		if (std::holds_alternative<std::string>(val) == true)
		{
			Name(std::get<std::string>(val));
		}
	}
	break;
	default:
	{
		if (std::holds_alternative<int64_t>(val) == true)
		{
			if (setNumberByHash(propHash16, (LevelObjValue)std::get<int64_t>(val), nullptr))
			{
				updateProperties();
			}
		}
	}
	break;
	}
}
コード例 #8
0
ファイル: headers.cpp プロジェクト: kenba/via-httplib
    bool are_headers_split(std::string_view headers) noexcept
    {
      char prev('0');
      char pprev('0');

      if (!headers.empty())
      {
        auto iter(headers.cbegin());
        for(; iter != headers.cend(); ++iter)
        {
          if (*iter == '\n')
          {
            if (prev == '\n')
              return true;
            else if ((prev == '\r') && (pprev == '\n'))
              return true;
          }

          pprev = prev;
          prev = *iter;
        }
      }

      return false;
    }
コード例 #9
0
ファイル: JsonUtils.cpp プロジェクト: dgengin/DGEngine
	bool loadFile(const std::string_view file, Document& doc)
	{
		if (file.empty() == true)
		{
			return false;
		}
		return loadJson(FileUtils::readText(file.data()), doc);
	}
コード例 #10
0
ファイル: JsonUtils.cpp プロジェクト: dgengin/DGEngine
	bool loadJson(const std::string_view json, Document& doc)
	{
		if (json.empty() == true)
		{
			return false;
		}
		// Default template parameter uses UTF8 and MemoryPoolAllocator.
		return (doc.Parse(json.data(), json.size()).HasParseError() == false);
	}
コード例 #11
0
ファイル: easy_lua.cpp プロジェクト: ReactiioN1337/easy_lua
int32_t easy_lua::destroy_userdata(
    const int32_t      stackpos,
    const std::string_view& name ) const
{
    if( is_userdata( stackpos ) && !name.empty() ) {
        const auto data = get_userdata<uintptr_t>( stackpos, name );
        delete data;
    }
    return 0;
}
コード例 #12
0
ファイル: Calculator.cpp プロジェクト: alisa-teplouhova/Calc
double Calculator::parseExpr(std::string_view &ref)
{
	double result = parseExprSum(ref);
	if (!ref.empty())
	{
		return std::numeric_limits<double>::quiet_NaN();
	}

	return result;
}
コード例 #13
0
ファイル: Player.cpp プロジェクト: dgengin/DGEngine
bool Player::getNumberProp(const std::string_view prop, Number32& value) const
{
	if (prop.empty() == true)
	{
		return false;
	}
	auto props = Utils::splitStringIn2(prop, '.');
	auto propHash = str2int16(props.first);
	return getNumberByHash(propHash, props.second, value);
}
コード例 #14
0
ファイル: Calculator.cpp プロジェクト: alisa-teplouhova/Calc
double Calculator::ParseArguments(std::string_view &ref)
{
	double value = 0;
	if (!ref.empty() && ref[0] == '(')
	{
		ref.remove_prefix(1);
		value = parseExprSum(ref);
		skipSpaces(ref);
		if (!ref.empty() && ref[0] == ')')
		{
			ref.remove_prefix(1);
			return value;
		}
		else
		{
			return std::numeric_limits<double>::quiet_NaN();
		}
	}
	else
	{
		return std::numeric_limits<double>::quiet_NaN();
	}
}
コード例 #15
0
bool CSeqConversionDefault::ToValue(std::string_view sv)
{
	m_bReady = false;
	if (sv == "$$") {
		m_bHex = true;
		return true;
	}

	if (auto nextTerm = GetNextTerm(sv)) {
		m_iTargetValue = m_iCurrentValue = *nextTerm;
		m_iRepeat = m_iValueDiv = 1;
		if (!sv.empty() && sv.front() == ':') {
			if (sv.remove_prefix(1), !sv.empty()) {
				if (auto divTerm = GetNextInteger(sv)) {
					m_iValueDiv = *divTerm;
					if (m_iValueDiv <= 0)
						return false;
					if (!sv.empty() && sv.front() == ':') {
						if (sv.remove_prefix(1), sv.empty())
							return false;
						if (auto target = GetNextTerm(sv))
							m_iTargetValue = *target;
						else
							return false;
					}
				}
				else
					return false;
			}
			else
				return false;
		}
		if (!sv.empty() && sv.front() == '\'') {
			if (sv.remove_prefix(1), !sv.empty()) {
				if (auto repTerm = GetNextInteger(sv)) {
					m_iRepeat = *repTerm;
					if (m_iRepeat <= 0)
						return false;
				}
			}
			else
				return false;
		}
		if (sv.empty()) {
			m_iValueInc = m_iTargetValue - m_iCurrentValue;
			m_iRepeatCounter = m_iCounter = m_iValueMod = 0;
			return m_bReady = true;
		}
	}

	return false;
}
コード例 #16
0
ファイル: easy_lua.cpp プロジェクト: ReactiioN1337/easy_lua
bool easy_lua::execute(
    const std::string_view& script,
    const bool              from_memory ) const
{
    if( script.empty() ) {
        return false;
    }
    if( !from_memory ) {
        return !luaL_dofile( EASY_LUA_CAST_LUA( this ), script.data() );
    }
    if( luaL_loadstring( EASY_LUA_CAST_LUA( this ), script.data() ) > 0 ) {
        return false;
    }
    if( lua_pcall( EASY_LUA_CAST_LUA( this ), 0, 0, 0 ) > 0 ) {
        if( pop( 1 ) == this ) {
            return false;
        }
        return false;
    }
    return true;
}
コード例 #17
0
ファイル: FileUtils.cpp プロジェクト: dgengin/DGEngine
	std::vector<std::string> geDirList(const std::string_view path,
		const std::string_view rootPath)
	{
		std::vector<std::string> vecDirs;
		auto dirs = PHYSFS_enumerateFiles(path.data());
		if (dirs != nullptr)
		{
			PHYSFS_Stat fileStat;
			for (char** dir = dirs; *dir != nullptr; dir++)
			{
				if (PHYSFS_stat(*dir, &fileStat) == 0)
				{
					continue;
				}
				if (fileStat.filetype != PHYSFS_FILETYPE_DIRECTORY)
				{
					continue;
				}
				if (**dir == '.')
				{
					continue;
				}
				if (rootPath.empty() == false)
				{
					auto realDir = PHYSFS_getRealDir(*dir);
					if (realDir != nullptr)
					{
						if (rootPath != realDir)
						{
							continue;
						}
					}
				}
				vecDirs.push_back(*dir);
			}
			PHYSFS_freeList(dirs);
		}
		return vecDirs;
	}
コード例 #18
0
// -----------------------------------------------------------------------------
// Detects offset hacks such as that used by the wall torch thing in Heretic.
// If the Y offset is noticeably larger than the sprite height, that means the
// thing is supposed to be rendered above its real position.
// -----------------------------------------------------------------------------
int MapTextureManager::verticalOffset(std::string_view name) const
{
	// Don't bother looking for nameless sprites
	if (name.empty())
		return 0;

	// Get sprite matching name
	auto entry = App::resources().getPatchEntry(name, "sprites", archive_);
	if (!entry)
		entry = App::resources().getPatchEntry(name, "", archive_);
	if (entry)
	{
		SImage image;
		Misc::loadImageFromEntry(&image, entry);
		int h = image.height();
		int o = image.offset().y;
		if (o > h)
			return o - h;
		else
			return 0;
	}

	return 0;
}
コード例 #19
0
ファイル: Player.cpp プロジェクト: dgengin/DGEngine
bool Player::getProperty(const std::string_view prop, Variable& var) const
{
	if (prop.empty() == true)
	{
		return false;
	}
	auto props = Utils::splitStringIn2(prop, '.');
	auto propHash = str2int16(props.first);
	if (getLevelObjProp(propHash, props.second, var) == true)
	{
		return true;
	}
	switch (propHash)
	{
	case str2int16("name"):
		var = Variable(Name());
		break;
	case str2int16("simpleName"):
		var = Variable(SimpleName());
		break;
	case str2int16("d"):
	case str2int16("description"):
	{
		updateNameAndDescriptions();
		size_t idx = Utils::strtou(props.second);
		if (idx >= descriptions.size())
		{
			idx = 0;
		}
		var = Variable(descriptions[idx]);
		break;
	}
	case str2int16("eval"):
		var = Variable((int64_t)Formula::evalString(props.second, *this));
		break;
	case str2int16("evalMin"):
		var = Variable((int64_t)Formula::evalMinString(props.second, *this));
		break;
	case str2int16("evalMax"):
		var = Variable((int64_t)Formula::evalMaxString(props.second, *this));
		break;
	case str2int16("evalf"):
		var = Variable(Formula::evalString(props.second, *this));
		break;
	case str2int16("evalMinf"):
		var = Variable(Formula::evalMinString(props.second, *this));
		break;
	case str2int16("evalMaxf"):
		var = Variable(Formula::evalMaxString(props.second, *this));
		break;
	case str2int16("totalKills"):
		var = Variable((int64_t)Class()->TotalKills());
		break;
	case str2int16("hasMaxStats"):
		var = Variable(hasMaxStats());
		break;
	case str2int16("hasProperty"):
		var = Variable(hasInt(props.second));
		break;
	case str2int16("canUseSelectedItem"):
	{
		if (selectedItem == nullptr)
		{
			return false;
		}
		var = Variable(canUseObject(*selectedItem));
		break;
	}
	case str2int16("canUseSelectedSpell"):
	{
		if (selectedSpell == nullptr)
		{
			return false;
		}
		var = Variable(canUseObject(*selectedSpell->spell));
		break;
	}
	case str2int16("canUseItem"):
	{
		std::string_view props2;
		size_t invIdx;
		size_t itemIdx;
		if (inventories.parseInventoryAndItem(
			props.second, props2, invIdx, itemIdx) == true)
		{
			auto item = inventories[invIdx].get(itemIdx);
			if (item != nullptr)
			{
				var = Variable(canUseObject(*item));
				break;
			}
		}
		return false;
	}
	case str2int16("hasEquipedItemType"):
		var = Variable(hasEquipedItemType(props.second));
		break;
	case str2int16("hasEquipedItemSubType"):
		var = Variable(hasEquipedItemSubType(props.second));
		break;
	case str2int16("hasSelectedItem"):
		var = Variable(selectedItem != nullptr);
		break;
	case str2int16("hasItem"):
	{
		std::string_view props2;
		size_t invIdx;
		size_t itemIdx;
		if (inventories.parseInventoryAndItem(
			props.second, props2, invIdx, itemIdx) == true)
		{
			var = Variable(inventories[invIdx].get(itemIdx) != nullptr);
			break;
		}
		return false;
	}
	case str2int16("hasItemClass"):
		var = Variable(inventories.hasItem(str2int16(props.second)));
		break;
	case str2int16("hasSpell"):
	{
		var = Variable(getSpell(std::string(props.second)) != nullptr);
		break;
	}
	case str2int16("hasSelectedSpell"):
	{
		var = Variable(selectedSpell != nullptr);
		break;
	}
	case str2int16("isItemSlotInUse"):
	{
		std::string_view props2;
		size_t invIdx;
		size_t itemIdx;
		if (inventories.parseInventoryAndItem(
			props.second, props2, invIdx, itemIdx) == true)
		{
			var = Variable(inventories[invIdx].isSlotInUse(itemIdx));
			break;
		}
		return false;
	}
	case str2int16("isStanding"):
		var = Variable(playerStatus == PlayerStatus::Stand);
		break;
	case str2int16("isWalking"):
		var = Variable(playerStatus == PlayerStatus::Walk);
		break;
	case str2int16("isAttacking"):
		var = Variable(playerStatus == PlayerStatus::Attack);
		break;
	case str2int16("isDead"):
		var = Variable(playerStatus == PlayerStatus::Dead);
		break;
	case str2int16("selectedItem"):
	{
		if (selectedItem != nullptr)
		{
			return selectedItem->getProperty(props.second, var);
		}
		return false;
	}
	case str2int16("item"):
	{
		std::string_view props2;
		size_t invIdx;
		size_t itemIdx;
		if (inventories.parseInventoryAndItem(
			props.second, props2, invIdx, itemIdx) == true)
		{
			auto item = inventories[invIdx].get(itemIdx);
			if (item != nullptr)
			{
				return item->getProperty(props2, var);
			}
		}
		return false;
	}
	case str2int16("inventory"):
	{
		auto props2 = Utils::splitStringIn2(props.second, '.');
		auto invIdx = GameUtils::getPlayerInventoryIndex(props2.first);
		if (invIdx < inventories.size())
		{
			return inventories[invIdx].getProperty(props2.second, var);
		}
		return false;
	}
	case str2int16("itemQuantity"):
	{
		auto classIdHash16 = str2int16(props.second);
		uint32_t itemQuantity = 0;
		if (itemQuantityCache.getValue(classIdHash16, itemQuantity) == false)
		{
			if (inventories.getQuantity(classIdHash16, itemQuantity) == true)
			{
				itemQuantityCache.updateValue(classIdHash16, itemQuantity);
			}
		}
		var = Variable((int64_t)itemQuantity);
		break;
	}
	case str2int16("selectedSpell"):
	{
		if (selectedSpell != nullptr)
		{
			return selectedSpell->getProperty(props.second, var);
		}
		return false;
	}
	case str2int16("spell"):
	{
		auto props2 = Utils::splitStringIn2(props.second, '.');
		auto spell = getSpellInstance(std::string(props2.first));
		if (spell != nullptr)
		{
			return spell->getProperty(props2.second, var);
		}
		return false;
	}
	default:
	{
		Number32 value;
		if (getNumberByHash(propHash, props.second, value) == true)
		{
			var = Variable(value.getInt64());
			break;
		}
		return false;
	}
	}
	return true;
}