
Приветствуем, уважаемое хабрасообщество! Сегодня мы продолжаем начатый в первой части рассказ о создании модификации XVM (eXtended Visualization Mod) для игры World of Tanks. Во второй части вас ждет описание истории развития серверной части мода.
User
class Base { virtual int foo() const = 0; };
class A : public Base { int foo() const { return 1; } };
class B : public Base { int foo() const { return 2; } };
class C : public Base { int foo() const { return 3; } };
class D : public Base { int foo() const { return 4; } };
Base* getconfig(char cfg) // не будем пока отвлекаться на уборку мусора
{
switch(cfg)
{
case 'a': return new A();
case 'b': return new B();
case 'c': return new C();
case 'd': return new D();
default: throw std::invalid_argument("bad type");
}
}
int entry(Base* x, Base* y) { return x->foo()*10 + y->foo(); }
void run(char cx, char cy) { std::cout << cx << cy << " : " << entry(getconfig(cx), getconfig(cy)) << std::endl; }
— Соня, вот ты вроде сначала не послушалась, а затем послушалась, что же получается?..
— Ну… ноль!
#include "Precompiled.h"
#include <QtYandexApi/QtYandexApi.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QtYandexDictionary yandexDictionary(QtYandexApi::getYandexKeyFromFile("dictKey"));
QObject::connect(&yandexDictionary, &QtYandexDictionary::translated,
[](const QtYaWordTranslation& wordTranslation)
{
if (wordTranslation.isError())
qDebug() << wordTranslation.errorString();
else {
QtYaWord wordForTranslation = wordTranslation.wordForTranslation();
QtYaTranslatedWord translatedWord = wordTranslation.translatedWord();
qDebug() << "\n***************";
qDebug() << "Word: " << wordForTranslation.wordName();
qDebug() << "Direction: " << wordForTranslation.fromLanguage() << "-" << wordForTranslation.toLanguage();
qDebug() << "Main translation: " << translatedWord.mainTranslation();
qDebug() << "Synonyms: " << translatedWord.synonyms();
qDebug() << "Examples: ";
for (const auto& example : translatedWord.examples()) {
qDebug() << example.first << "-" << example.second;
}
}
});
QStringList russianWords, englishWords;
russianWords << "дом" << "время" << "легенда" << "ключ" << "клавиатура" << "монитор" << "случай" << "один" << "два" << "три" << "четыре" << "пять" << "шесть";
englishWords << "home" << "time" << "legend" << "key" << "keyboard" << "monitor" << "infection" << "one" << "two" << "three" << "four" << "five" << "success";
for (const QString& word : russianWords) {
yandexDictionary.translate(QtYaWord(word, "ru", "en"));
}
for (const QString& word : englishWords) {
yandexDictionary.translate(QtYaWord(word, "en", "ru"));
}
return a.exec();
}
make_clickable
$string = "This is a long text that contains some links like http://www.wordpress.org and http://www.wordpress.com .";
echo make_clickable( $string );
popuplinks
target='_blank' rel='external'
всем ссылкам в тексте.$string = "This is a long text that contains some links like <a href='http://www.wordpress.org'>http://www.wordpress.org</a> and <a href='http://www.wordpress.com'>http://www.wordpress.com</a> .";
echo popuplinks( $string );
wp_list_pluck
$posts = get_posts();
$ids = wp_list_pluck( $posts, 'ID' ); // [1, 2, 3, ...]
antispambot
$email = 'example@email.com';
echo '<a href="mailto:' . antispambot( $email ) . '">' . antispambot( $email ) . '</a>';
while (n)
{
++count;
n &= (n-1);
}
while (n)
{
if (n&1)
++count;
n >>= 1;
}
popen
и вычислить выражение через него. Целью данной статье является пошаговая разработка достаточно сложной системы с помощью TDD, поэтому будет использоваться только стандартная библиотека C++ и встроенный в IDE тестовый фреймворк.TEST_CLASS(ParserTests) {
public:
TEST_METHOD(Should_return_empty_list_when_put_empty_list) {
Tokens tokens = Parser::Parse({});
Assert::IsTrue(tokens.empty());
}
};
TEST_CLASS(EvaluatorTests) {
public:
TEST_METHOD(Should_return_zero_when_evaluate_empty_list) {
double result = Evaluator::Evaluate({});
Assert::AreEqual(0.0, result);
}
};