Example #1
0
// Stream output operator; prints in the following format:
// "(Priority tag) [Duedate Text] {Tag_1 / Tag_2 / Tag_3}
// ex: "(A) [4/17] write essay #3 {history, computer}
std::ostream& operator << (std::ostream& out, const Todo& aTodo)
{
	char			myPriority = aTodo.GetPriority();
	Date			myDueDate = aTodo.GetDate();
	string			todoText = aTodo.GetText();
	vector<Tag>		tagList = aTodo.GetTags();
	
	// If the todo has a priority print it
	if (myPriority != NULL)
	{
		// If priority is A, B, C, or D print colors for added emphasis
		switch (myPriority)
		{
		case 'A':
			aTodo.SetColor(Todo::YELLOW);
			out << "(" << myPriority << ") ";
			break;
		case 'B':
			aTodo.SetColor(Todo::GREEN);
			out << "(" << myPriority << ") ";
			break;
		case 'C':
			aTodo.SetColor(Todo::RED);
			out << "(" << myPriority << ") ";
			break;
		case 'D':
			aTodo.SetColor(Todo::TEAL);
			out << "(" << myPriority << ") ";
			break;
		}
	}

	// If the todo has a due date print it
	if ( !myDueDate.IsEmpty() )
		out << myDueDate << " ";

	out << todoText << " ";

	// Print tags by traversing vector of tags, as long as there are tags available to print
	if ( !tagList.empty() )
	{
		int pos = 0;
		out << "{";
		for (; pos < int(tagList.size()-1); pos++ )
			out << tagList[pos] << ", ";
		out << tagList[pos] << "}";
	}
	aTodo.SetColor(Todo::GRAY);			// reset output color
	return out;
}