~ubuntu-branches/debian/sid/pgadmin3/sid

« back to all changes in this revision

Viewing changes to pgadmin/pgscript/utilities/pgsMapm.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gerfried Fuchs
  • Date: 2009-07-30 12:27:16 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730122716-fddbh42on721bbs2
Tags: 1.10.0-1
* New upstream release.
* Adjusted watch file to match release candidates.
* Updated to Standards-Version 3.8.2:
  - Moved to Section: database.
  - Add DEB_BUILD_OPTIONS support for parallel building.
  - Move from findstring to filter suggestion for DEB_BUILD_OPTIONS parsing.
* pgagent got split into its own separate source package by upstream.
* Exclude Docs.vcproj from installation.
* Move doc-base.enus from pgadmin3 to pgadmin3-data package, the files are
  in there too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//////////////////////////////////////////////////////////////////////////
 
2
//
 
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
 
7
//
 
8
//////////////////////////////////////////////////////////////////////////
 
9
 
 
10
 
 
11
#include "pgAdmin3.h"
 
12
#include "pgscript/utilities/pgsMapm.h"
 
13
#include <string>
 
14
#include <wx/sstream.h>
 
15
#include <wx/txtstrm.h>
 
16
 
 
17
#include <wx/arrimpl.cpp>
 
18
WX_DEFINE_OBJARRAY(pgsVectorMapm);
 
19
 
 
20
wxString pgsMapm::pgs_mapm_str(const MAPM & m, const bool & as_int)
 
21
{
 
22
        if (m.is_integer() || as_int)
 
23
        {
 
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
 
26
                return str;
 
27
        }
 
28
        else
 
29
        {
 
30
                return pgs_mapm_str_float(m);
 
31
        }
 
32
}
 
33
 
 
34
MAPM pgsMapm::pgs_mapm_round(const MAPM & m)
 
35
{
 
36
        return MAPM(pgs_mapm_str(m, true).mb_str());
 
37
}
 
38
 
 
39
wxString pgsMapm::pgs_mapm_str_fixed(const MAPM & m)
 
40
{
 
41
        char * const res = m.toFixPtStringExp(-1, '.', ' ', INT_MAX);
 
42
        wxString str(res, wxConvUTF8);
 
43
        free(res);
 
44
        return str;
 
45
}
 
46
 
 
47
wxString pgsMapm::pgs_mapm_str_float(const MAPM & m)
 
48
{
 
49
        int str_len = m.significant_digits();
 
50
        
 
51
        {
 
52
                wxStringOutputStream sos;
 
53
                wxTextOutputStream tos(sos);
 
54
                tos << abs(m.exponent());
 
55
                str_len += sos.GetString().Length();
 
56
        }
 
57
        
 
58
        {
 
59
                wxStringOutputStream sos;
 
60
                wxTextOutputStream tos(sos);
 
61
                tos << str_len;
 
62
                str_len = m.significant_digits() + 10 + sos.GetString().Length();
 
63
        }
 
64
        
 
65
        char * res = pnew char[str_len];
 
66
        m.toString(res, -1);
 
67
        wxString result(res, wxConvUTF8);
 
68
        pdeletea(res);
 
69
        
 
70
        return result;
 
71
}
 
72
 
 
73
MAPM pgsMapm::pgs_str_mapm(const wxString & s)
 
74
{
 
75
        return std::string(s.mb_str()).c_str();
 
76
}