1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
/*
* Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; version 2 of the
* License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef _WIN32
#include <algorithm>
#endif
#include "charset_list.h"
#include "grts/structs.db.mgmt.h"
using namespace bec;
CharsetList::CharsetList(grt::GRT *grt, const std::string &path)
: _grt(grt)
{
_charset_list_path= path;
}
void CharsetList::picked_charset(const NodeId &node)
{
if (std::find(_recently_used.begin(), _recently_used.end(), node[0]) != _recently_used.end())
_recently_used.erase(std::find(_recently_used.begin(), _recently_used.end(), node[0]));
_recently_used.push_front(node[0]);
if (_recently_used.size() > 5)
_recently_used.pop_back();
}
size_t CharsetList::count_children(const NodeId &parent)
{
grt::ListRef<db_CharacterSet> charsets= grt::ListRef<db_CharacterSet>::cast_from(_grt->get(_charset_list_path));
if (parent.depth() == 0)
return (charsets.count() + _recently_used.size() + 1);
else
return charsets[parent[0]]->collations().count();
}
bool CharsetList::get_field(const NodeId &node, ColumnId column, std::string &value)
{
grt::ListRef<db_CharacterSet> charsets= grt::ListRef<db_CharacterSet>::cast_from(_grt->get(_charset_list_path));
switch ((CharsetListColumns)column)
{
case Name:
if (node.depth() == 1)
{
if (node[0] < _recently_used.size())
{
std::list<size_t>::const_iterator it = _recently_used.begin();
size_t i = node[0];
while (i > 0)
{
--it;
--i;
}
value = charsets[*it]->name();
}
else if (node[0] == _recently_used.size())
value = "";
else
value = charsets[node[0] - _recently_used.size() - 1]->name();
}
else
{
if (node[0] < _recently_used.size())
{
std::list<size_t>::const_iterator it = _recently_used.begin();
size_t i= node[0];
while (i > 0) { --it; --i; }
value= charsets[*it]->collations()[node[1]];
}
else
value= charsets[node[0] - static_cast<unsigned int>(_recently_used.size()) - 1]->collations()[node[1]];
}
return true;
default:
return false;
}
}
std::string CharsetList::get_field_description(const NodeId &node, ColumnId column)
{
grt::ListRef<db_CharacterSet> charsets= grt::ListRef<db_CharacterSet>::cast_from(_grt->get(_charset_list_path));
switch ((CharsetListColumns)column)
{
case Name:
if (node.depth() == 1)
{
if (node[0] < _recently_used.size())
{
std::list<size_t>::const_iterator it = _recently_used.begin();
size_t i= node[0];
while (i > 0) { --it; --i; }
return charsets[*it]->description();
}
else
return charsets[node[0] - _recently_used.size() - 1]->description();
}
}
return "";
}
|