tagging release
[dasher.git] / Src / DasherCore / Alphabet / AlphIO.h
blob9192a390c80bc7ac6196a85c83fbc882b81f584f
1 // AlphIO.h
2 //
3 /////////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (c) 2002 Iain Murray
6 //
7 /////////////////////////////////////////////////////////////////////////////
9 #ifndef __AlphIO_h__
10 #define __AlphIO_h__
12 #include "../DasherTypes.h"
13 //#include "Alphabet.h"
14 #include "GroupInfo.h"
16 #include <string>
17 #include <map>
18 #include <vector>
19 #include <utility> // for std::pair
20 #include <stdio.h> // for C style file IO
22 /* namespace Dasher { */
23 /* class CAlphabet { */
24 /* public: */
25 /* struct SGroupInfo; */
26 /* }; */
27 /* } */
29 /// \cond expat
31 namespace expat {
32 #include "../../Common/Expat/lib/expat.h"
35 /// \endcond
37 namespace Dasher {
38 class CAlphIO;
42 /// \ingroup Alphabet
43 /// @{
45 class Dasher::CAlphIO {
46 public:
47 // This structure completely describes the characters used in alphabet
49 struct AlphInfo {
50 // Basic information
51 std::string AlphID;
52 bool Mutable; // If from user we may play. If from system defaults this is immutable. User should take a copy.
54 // Complete description of the alphabet:
55 std::string TrainingFile;
56 std::string GameModeFile;
57 std::string PreferredColours;
58 Opts::AlphabetTypes Encoding;
59 Opts::AlphabetTypes Type;
60 Opts::ScreenOrientations Orientation;
62 struct character {
63 std::string Display;
64 std::string Text;
65 int Colour;
66 std::string Foreground;
69 /* // Obsolete groups stuff */
70 /* struct group { */
71 /* std::string Description; */
72 /* std::vector < character > Characters; */
73 /* int Colour; */
74 /* std::string Label; */
75 /* }; */
76 /* std::vector < group > Groups; */
77 /* // --- */
79 int m_iCharacters;
80 std::vector<SGroupInfo *> m_vGroups;
81 SGroupInfo *m_pBaseGroup;
83 std::vector<character> m_vCharacters;
85 character ParagraphCharacter; // display and edit text of paragraph character. Use ("", "") if no paragraph character.
86 character SpaceCharacter; // display and edit text of Space character. Typically (" ", "_"). Use ("", "") if no space character.
87 character ControlCharacter; // display and edit text of Control character. Typically ("", "Control"). Use ("", "") if no control character.
88 character StartConvertCharacter;
89 character EndConvertCharacter;
90 int m_iConversionID;
91 std::string m_strDefaultContext;
94 CAlphIO(std::string SystemLocation, std::string UserLocation, std::vector < std::string > Filenames);
95 void GetAlphabets(std::vector < std::string > *AlphabetList) const;
96 std::string GetDefault();
97 const AlphInfo & GetInfo(const std::string & AlphID);
98 void SetInfo(const AlphInfo & NewInfo);
99 void Delete(const std::string & AlphID);
100 private:
101 AlphInfo BlankInfo;
102 std::string SystemLocation;
103 std::string UserLocation;
104 std::map < std::string, AlphInfo > Alphabets; // map short names (file names) to descriptions
105 std::vector < std::string > Filenames;
107 void Save(const std::string & AlphID);
108 void CreateDefault(); // Give the user an English alphabet rather than nothing if anything goes horribly wrong.
110 // XML handling:
111 /////////////////////////
113 bool LoadMutable;
114 void ParseFile(std::string Filename);
116 // Alphabet types:
117 std::map < std::string, Opts::AlphabetTypes > StoT;
118 std::map < Opts::AlphabetTypes, std::string > TtoS;
120 // & to &amp; < to &lt; and > to &gt; and if (Attribute) ' to &apos; and " to &quot;
121 void XML_Escape(std::string * Text, bool Attribute);
123 // Data gathered
124 std::string CData; // Text gathered from when an elemnt starts to when it ends
125 AlphInfo InputInfo;
126 bool bFirstGroup;
127 int iGroupIdx;
129 // Callback functions. These involve the normal dodgy casting to a pointer
130 // to an instance to get a C++ class to work with a plain C library.
131 static void XML_StartElement(void *userData, const expat::XML_Char * name, const expat::XML_Char ** atts);
132 static void XML_EndElement(void *userData, const expat::XML_Char * name);
133 static void XML_CharacterData(void *userData, const expat::XML_Char * s, int len);
136 /// @}
138 #endif /* #ifndef __AlphIO_h__ */