Source

zorkish / Item.hpp

Full commit
/*
 * Item.hpp
 *
 *  Created on: 24/08/2012
 *      Author: rhys
 */

#ifndef ITEM_HPP_
#define ITEM_HPP_

#include <algorithm>
#include <vector>
#include <boost/algorithm/string/predicate.hpp>

class Item {
public:
    typedef std::vector<std::string> Ids;

private:
    std::string _short_name;
    Ids ids;

public:
    // Use std::move for names
    Item(std::string short_name, Ids ids) :
        _short_name(short_name), ids(ids) {};

    Item(std::string short_name, std::initializer_list<std::string> ids) :
        _short_name(short_name), ids(Ids(ids)) {};

    bool identifies_as(const std::string& id) {
        return boost::iequals(this->_short_name, id) ||
            std::find_if(begin(ids), end(ids),
                    [&](const std::string& td){return boost::iequals(td, id);})
                != end(ids);
    }

    const std::string& short_name() {
        return this->_short_name;
    }
};

#endif /* ITEM_HPP_ */