26#include <wx/tokenzr.h>
27#include <wx/textfile.h>
28#include <wx/filename.h>
35static int s57_initialize(
const wxString& csv_dir, FILE* flog) {
43 wxString msg(_T(
" Error: Could not load S57 ClassInfo from "));
55s57RegistrarMgr::s57RegistrarMgr(
const wxString& csv_dir, FILE* flog) {
56 s57_initialize(csv_dir, flog);
59 s57_attr_init(csv_dir);
61 s57_feature_init(csv_dir);
64s57RegistrarMgr::~s57RegistrarMgr() {
69bool s57RegistrarMgr::s57_attr_init(
const wxString& csv_dir) {
71 wxString csv_t = csv_dir;
72 wxChar sep = wxFileName::GetPathSeparator();
73 if (csv_t.Last() != sep) csv_t.Append(sep);
76 wxString targetFile = csv_t + _T(
"s57attributes.csv");
78 if (!tFile.Open(targetFile)) {
79 wxString msg(_T(
" Error: Could not load S57 Attribute Info from "));
92 for (str = tFile.GetFirstLine(); !tFile.Eof(); str = tFile.GetNextLine()) {
93 wxStringTokenizer tk(str, _T(
","));
95 wxString ident = tk.GetNextToken();
97 if (ident.ToLong(&nID)) {
98 wxString description = tk.GetNextToken();
99 wxString acronym = tk.GetNextToken();
101 m_attrHash1[acronym] = nID;
102 m_attrHash2[nID] = acronym.c_str();
109bool s57RegistrarMgr::s57_feature_init(
const wxString& csv_dir) {
111 wxString csv_t = csv_dir;
112 wxChar sep = wxFileName::GetPathSeparator();
113 if (csv_t.Last() != sep) csv_t.Append(sep);
116 wxString targetFile = csv_t + _T(
"s57objectclasses.csv");
118 if (!tFile.Open(targetFile)) {
119 wxString msg(_T(
" Error: Could not load S57 Feature Info from "));
132 for (str = tFile.GetFirstLine(); !tFile.Eof(); str = tFile.GetNextLine()) {
133 wxStringTokenizer tk(str, _T(
","));
135 wxString ident = tk.GetNextToken();
145 if (ident.ToLong(&nID)) {
146 wxString description = tk.GetNextToken();
148 while (!description.EndsWith(
"\"")) description += tk.GetNextToken();
150 wxString acronym = tk.GetNextToken();
152 m_featureHash1[acronym] = nID;
153 m_featureHash2[nID] = acronym.c_str();
160int s57RegistrarMgr::getAttributeID(
const char* pAttrName) {
161 wxString key(pAttrName);
163 if (m_attrHash1.find(key) == m_attrHash1.end())
166 return m_attrHash1[key];
169std::string s57RegistrarMgr::getAttributeAcronym(
int nID) {
170 if (m_attrHash2.find(nID) == m_attrHash2.end())
173 return m_attrHash2[nID];
176std::string s57RegistrarMgr::getFeatureAcronym(
int nID) {
177 if (m_featureHash2.find(nID) == m_featureHash2.end())
180 return m_featureHash2[nID];
An s57 class registry container.
S57ClassRegistrar * g_poRegistrar
Global instance.
S57ClassRegistrar * g_poRegistrar
Global instance.