Ejemplo n.º 1
0
Update_Messages Room::table_contents(const std::string & username) const
{
	if (!has_table()) return Update_Messages("There is no table here.");

	if (table->size() == 0) return Update_Messages("There is nothing on the table.");

	return Update_Messages("On the table there is" + table->contents_to_string(),
		username + " looks at the table.");
}
Ejemplo n.º 2
0
// printing
std::string Room::summary(const std::string & player_ID) const
{
	std::stringstream summary_stream;

	// report on the sides of the room (walls, ceiling, floor)
	if (room_sides.size() > 0)
	{
		summary_stream << " This room consists of";

		// create a pointer pointing to the last side in the room
		std::map<std::string, Room_Side>::const_iterator last_side_it = room_sides.cend(); // one past the actual last item
		--last_side_it; // the last item

		// for each room side
		for (std::map<std::string, Room_Side>::const_iterator it = room_sides.cbegin();
			it != room_sides.cend(); ++it)
		{
			// if there are more than one sides, append " and"
			if (it == last_side_it && room_sides.size() > 1) // "and" precedes last surface
			{
				summary_stream << " and";
			}

			// if the surface is not rubble
			if (!it->second.is_rubble())
			{
				// "a(n) stone ceiling" or "a stone wall to the west"
				summary_stream << " " << U::get_article_for(it->second.get_material_id()) << " " << it->second.get_material_id()
					<< ((it->first == C::CEILING || it->first == C::FLOOR) ? " " : " wall to the ")
					<< it->first; // direction_ID
			}
			else // the surface is rubble
			{
				summary_stream << " a pile of rubble"
					// "on the floor" or " to your north"
					<< ((it->first == C::CEILING || it->first == C::FLOOR) ? " on the " : " to your ")
					<< it->first;
			}

			// add text to the surface's description if it has a door
			if (it->second.has_door())
			{
				// test if the door is rubble
				if (it->second.get_door()->is_rubble())
				{
					// "a stone wall to the west..."
					summary_stream << " with a pile of rubble where a door once was";
				}
				else // the door is at least partially intact
				{
					// "a stone wall to the west" becomes
					// "a stone wall to the west with a wood door"
					summary_stream << " with a " << it->second.get_door()->get_material_ID() << " door";
				}
			}

			// if the current surface is not the last AND there are more than 2 sides, append a comma
			if (it != last_side_it && room_sides.size() > 2)
			{
				summary_stream << ",";
			}
		}

		summary_stream << "."; // end with a period
	}

	// report on the items in the room
	if (contents.size() > 0) // if there are items present
	{
		summary_stream << " Here there is" << this->contents_to_string();
	}

	// if the room contains a table or chest
	if (has_table() && has_chest())
	{
		summary_stream << " There is a table and a chest here.";
	}
	else if (has_table())
	{
		summary_stream << " There is a table here.";
	}
	else if (has_chest())
	{
		summary_stream << " There is a chest here.";
	}

	if (actor_ids.size() > 1) // there will always be at least one, because of the player
	{
		summary_stream << " ";
		for (const std::string & actor_ID : actor_ids)
		{
			if (actor_ID == player_ID) { continue; } // don't report a player's own presence to that player
			summary_stream << actor_ID << " is here.";
		}
	}

	// if there are no items or surfaces
	if (summary_stream.str().length() == 0)
	{
		summary_stream << " There is nothing of interest here.";
	}

	// end with a newline
	summary_stream << "\n";

	return summary_stream.str();
}
Ejemplo n.º 3
0
        template<typename T> void load(ts::TimeSeries<T>& series,
                                       const std::string& table,
                                       bpt::ptime start = bpt::ptime(),
                                       bpt::ptime end = bpt::ptime(),
                                       bool print_meta = false)         // throws
        {
            BOOST_STATIC_ASSERT((boost::is_base_of< dp::DataPoint, T>::value));
            
            if( !isConnected() )
                connect();
            
            if( !has_table(table) )
                throw TSDBInterfaceException(2);
            
            if( !_columns_match_type<T>(table) )
                throw TSDBInterfaceException(5);
            
            if( start > end )
                throw TSDBInterfaceException(4);
            
            try{

                std::string cols = boost::algorithm::join(dp::dp_names<T>(), ", ");
                std::string query = "SELECT date_time, "+cols+" FROM "+table;
                unique_ptr<sql::PreparedStatement> pstmt(_con->prepareStatement(query));
                
                if( !start.is_not_a_date_time() && !end.is_not_a_date_time() )
                {
                    query += " WHERE date_time BETWEEN (?) and (?);";
                    pstmt.reset( _con->prepareStatement(query) );
                    pstmt->setDateTime(1, utilities::bpt_to_str(start));
                    pstmt->setDateTime(2, utilities::bpt_to_str(end));
                }
                else if( !start.is_not_a_date_time() && end.is_not_a_date_time() )
                {
                    query += " WHERE date_time >= (?);";
                    pstmt.reset( _con->prepareStatement(query) );
                    pstmt->setDateTime(1, utilities::bpt_to_str(start));
                }
                else if( start.is_not_a_date_time() && !end.is_not_a_date_time() )
                {
                    query += " WHERE date_time <= (?);";
                    pstmt.reset( _con->prepareStatement(query) );
                	pstmt->setDateTime(1, utilities::bpt_to_str(end));
                }
              
                std::unique_ptr<sql::ResultSet> rset( pstmt->executeQuery() );
                sql::ResultSetMetaData* rset_meta( rset->getMetaData() );
                
                if( print_meta )
                    _print_loading_MetaData( rset_meta );
                
                int num_cols = rset_meta->getColumnCount();
                std::vector<double> row;
                row.reserve( num_cols-1 );
                
                while( rset->next() ){
                    
                    for( int i =  2; i <= num_cols; ++i) // MySQL Conn doesn't allow accessing entire row at once
                        row.push_back(rset->getDouble(i));
                    
                    series.insert( utilities::str_to_time_t(rset->getString(1)), T(row) ); //move insert
                    row.clear();
                }
            }
            catch( sql::SQLException& ex ) {
                _print_SQLException(ex);
                throw TSDBInterfaceException(3);
            }
            
        } //load