26#include <wx/tokenzr.h>
27#include <wx/textfile.h>
28#include <wx/filename.h>
32#include "s57RegistrarMgr.h"
33#include "S57ClassRegistrar.h"
37static int s57_initialize(
const wxString& csv_dir, FILE* flog) {
41 if (g_poRegistrar == NULL) {
44 if (!g_poRegistrar->LoadInfo(csv_dir.mb_str(), FALSE)) {
45 wxString msg(_T(
" Error: Could not load S57 ClassInfo from "));
57s57RegistrarMgr::s57RegistrarMgr(
const wxString& csv_dir, FILE* flog) {
58 s57_initialize(csv_dir, flog);
61 s57_attr_init(csv_dir);
63 s57_feature_init(csv_dir);
66s57RegistrarMgr::~s57RegistrarMgr() {
71bool s57RegistrarMgr::s57_attr_init(
const wxString& csv_dir) {
73 wxString csv_t = csv_dir;
74 wxChar sep = wxFileName::GetPathSeparator();
75 if (csv_t.Last() != sep) csv_t.Append(sep);
78 wxString targetFile = csv_t + _T(
"s57attributes.csv");
80 if (!tFile.Open(targetFile)) {
81 wxString msg(_T(
" Error: Could not load S57 Attribute Info from "));
94 for (str = tFile.GetFirstLine(); !tFile.Eof(); str = tFile.GetNextLine()) {
95 wxStringTokenizer tk(str, _T(
","));
97 wxString ident = tk.GetNextToken();
99 if (ident.ToLong(&nID)) {
100 wxString description = tk.GetNextToken();
101 wxString acronym = tk.GetNextToken();
103 m_attrHash1[acronym] = nID;
104 m_attrHash2[nID] = acronym.c_str();
111bool s57RegistrarMgr::s57_feature_init(
const wxString& csv_dir) {
113 wxString csv_t = csv_dir;
114 wxChar sep = wxFileName::GetPathSeparator();
115 if (csv_t.Last() != sep) csv_t.Append(sep);
118 wxString targetFile = csv_t + _T(
"s57objectclasses.csv");
120 if (!tFile.Open(targetFile)) {
121 wxString msg(_T(
" Error: Could not load S57 Feature Info from "));
134 for (str = tFile.GetFirstLine(); !tFile.Eof(); str = tFile.GetNextLine()) {
135 wxStringTokenizer tk(str, _T(
","));
137 wxString ident = tk.GetNextToken();
147 if (ident.ToLong(&nID)) {
148 wxString description = tk.GetNextToken();
150 while (!description.EndsWith(
"\"")) description += tk.GetNextToken();
152 wxString acronym = tk.GetNextToken();
154 m_featureHash1[acronym] = nID;
155 m_featureHash2[nID] = acronym.c_str();
162int s57RegistrarMgr::getAttributeID(
const char* pAttrName) {
163 wxString key(pAttrName);
165 if (m_attrHash1.find(key) == m_attrHash1.end())
168 return m_attrHash1[key];
171std::string s57RegistrarMgr::getAttributeAcronym(
int nID) {
172 if (m_attrHash2.find(nID) == m_attrHash2.end())
175 return m_attrHash2[nID];
178std::string s57RegistrarMgr::getFeatureAcronym(
int nID) {
179 if (m_featureHash2.find(nID) == m_featureHash2.end())
182 return m_featureHash2[nID];