Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Eigen and UPP? (STL question?)
Re: Eigen and UPP? (STL question?) [message #32362 is a reply to message #32360] Fri, 13 May 2011 08:43 Go to previous messageGo to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1791
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi GaroRobe!

Welcome to U++ Forum! Smile

First, regarding your remark: Not using STL in past will actually make it simpler for you to get familiar with U++, since you won't have to get rid of the old habbits Wink

Now to the code: Simply put, the operator<< in U++ uses by default function AsString(), which transform the given object to Upp::String. This is in most cases done by just calling the objects ToString() method, but in cases of foreign types, like those from Eigen, you have to make a specialization of AsString, which would understand it. The simplest posible code to make this work (altough not the best, but I didn't have much time to study Eigen internals Smile ) can be this:
#include <Core/Core.h>
#include <Eigen/Dense>

using namespace Upp;
using Eigen::MatrixXd;

NAMESPACE_UPP
template<>
String AsString(const MatrixXd& m) {
	std::stringstream tmp;
	tmp << m; // we just use eigen classes capability to write to std::ostream
	return tmp.str(); // here the std::string is 'magicaly' converted to Upp::String
}
END_UPP_NAMESPACE

CONSOLE_APP_MAIN
{
	MatrixXd m ( 2, 2 );
	m ( 0, 0 ) = 3;
	m ( 1, 0 ) = 2.5;
	m ( 0, 1 ) = -1;
	m ( 1, 1 ) = m ( 1, 0 ) + m ( 0, 1 );
	Cout() << m << '\n';
}

Hopefully this will give you an idea Wink

Best regards,
Honza
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Appearance errors in HelloWorld app build with MSVC++ 10
Next Topic: How to print staticlabel text at an angle?
Goto Forum:
  


Current Time: Sun Aug 24 14:32:29 CEST 2025

Total time taken to generate the page: 0.04972 seconds