1
//////////////////////////////////////////////////////////////////////////
3
// pgScript - PostgreSQL Tools
4
// RCS-ID: $Id: pgsMapm.cpp 7758 2009-03-26 20:49:59Z dpage $
5
// Copyright (C) 2002 - 2009, The pgAdmin Development Team
6
// This software is released under the BSD Licence
8
//////////////////////////////////////////////////////////////////////////
12
#include "pgscript/utilities/pgsMapm.h"
14
#include <wx/sstream.h>
15
#include <wx/txtstrm.h>
17
#include <wx/arrimpl.cpp>
18
WX_DEFINE_OBJARRAY(pgsVectorMapm);
20
wxString pgsMapm::pgs_mapm_str(const MAPM & m, const bool & as_int)
22
if (m.is_integer() || as_int)
24
wxString str = pgs_mapm_str_fixed(m);
25
str = str.substr(0, str.find_last_of('.')); // Remove .0 at the end of an integer
30
return pgs_mapm_str_float(m);
34
MAPM pgsMapm::pgs_mapm_round(const MAPM & m)
36
return MAPM(pgs_mapm_str(m, true).mb_str());
39
wxString pgsMapm::pgs_mapm_str_fixed(const MAPM & m)
41
char * const res = m.toFixPtStringExp(-1, '.', ' ', INT_MAX);
42
wxString str(res, wxConvUTF8);
47
wxString pgsMapm::pgs_mapm_str_float(const MAPM & m)
49
int str_len = m.significant_digits();
52
wxStringOutputStream sos;
53
wxTextOutputStream tos(sos);
54
tos << abs(m.exponent());
55
str_len += sos.GetString().Length();
59
wxStringOutputStream sos;
60
wxTextOutputStream tos(sos);
62
str_len = m.significant_digits() + 10 + sos.GetString().Length();
65
char * res = pnew char[str_len];
67
wxString result(res, wxConvUTF8);
73
MAPM pgsMapm::pgs_str_mapm(const wxString & s)
75
return std::string(s.mb_str()).c_str();