Fixed UTF-8 file save bug Update to circle start handler Started two
[dasher.git] / Src / DasherCore / Alphabet / AlphIO.h
blob750ed9b739388f84fd81b5e7feac63a19401af32
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 namespace expat {
30 #include "../../Common/Expat/lib/expat.h"
33 namespace Dasher {
34 class CAlphIO;
37 class Dasher::CAlphIO {
38 public:
39 // This structure completely describes the characters used in alphabet
41 struct AlphInfo {
42 // Basic information
43 std::string AlphID;
44 bool Mutable; // If from user we may play. If from system defaults this is immutable. User should take a copy.
46 // Complete description of the alphabet:
47 std::string TrainingFile;
48 std::string GameModeFile;
49 std::string PreferredColours;
50 Opts::AlphabetTypes Encoding;
51 Opts::AlphabetTypes Type;
52 Opts::ScreenOrientations Orientation;
54 struct character {
55 std::string Display;
56 std::string Text;
57 int Colour;
58 std::string Foreground;
61 /* // Obsolete groups stuff */
62 /* struct group { */
63 /* std::string Description; */
64 /* std::vector < character > Characters; */
65 /* int Colour; */
66 /* std::string Label; */
67 /* }; */
68 /* std::vector < group > Groups; */
69 /* // --- */
71 int m_iCharacters;
72 std::vector<SGroupInfo *> m_vGroups;
73 SGroupInfo *m_pBaseGroup;
75 std::vector<character> m_vCharacters;
77 character ParagraphCharacter; // display and edit text of paragraph character. Use ("", "") if no paragraph character.
78 character SpaceCharacter; // display and edit text of Space character. Typically (" ", "_"). Use ("", "") if no space character.
79 character ControlCharacter; // display and edit text of Control character. Typically ("", "Control"). Use ("", "") if no control character.
81 // Added for Kanji Conversion by T.Kaburagi 15 July 2005
82 character StartConvertCharacter;
83 character EndConvertCharacter;
89 CAlphIO(std::string SystemLocation, std::string UserLocation, std::vector < std::string > Filenames);
90 void GetAlphabets(std::vector < std::string > *AlphabetList) const;
91 std::string GetDefault();
92 const AlphInfo & GetInfo(const std::string & AlphID);
93 void SetInfo(const AlphInfo & NewInfo);
94 void Delete(const std::string & AlphID);
95 private:
96 AlphInfo BlankInfo;
97 std::string SystemLocation;
98 std::string UserLocation;
99 std::map < std::string, AlphInfo > Alphabets; // map short names (file names) to descriptions
100 std::vector < std::string > Filenames;
102 void Save(const std::string & AlphID);
103 void CreateDefault(); // Give the user an English alphabet rather than nothing if anything goes horribly wrong.
105 // XML handling:
106 /////////////////////////
108 bool LoadMutable;
109 void ParseFile(std::string Filename);
111 // Alphabet types:
112 std::map < std::string, Opts::AlphabetTypes > StoT;
113 std::map < Opts::AlphabetTypes, std::string > TtoS;
115 // & to &amp; < to &lt; and > to &gt; and if (Attribute) ' to &apos; and " to &quot;
116 void XML_Escape(std::string * Text, bool Attribute);
118 // Data gathered
119 std::string CData; // Text gathered from when an elemnt starts to when it ends
120 AlphInfo InputInfo;
121 bool bFirstGroup;
122 int iGroupIdx;
124 // Callback functions. These involve the normal dodgy casting to a pointer
125 // to an instance to get a C++ class to work with a plain C library.
126 static void XML_StartElement(void *userData, const expat::XML_Char * name, const expat::XML_Char ** atts);
127 static void XML_EndElement(void *userData, const expat::XML_Char * name);
128 static void XML_CharacterData(void *userData, const expat::XML_Char * s, int len);
131 #endif /* #ifndef __AlphIO_h__ */