implemented infinite backoff (fixes #311767)
[dasher.git] / Src / DasherCore / ColourIO.h
blobf716031f993eb635d5520d11f43dc7d290d2e861
1 // ColourIO.h
2 //
3 /////////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (c) 2002 Iain Murray
6 //
7 /////////////////////////////////////////////////////////////////////////////
9 #ifndef __ColourIO_h__
10 #define __ColourIO_h__
12 #include "DasherTypes.h"
14 #include <string>
15 #include <map>
16 #include <vector>
17 #include <utility> // for std::pair
18 #include <stdio.h> // for C style file IO
20 namespace expat {
21 #include "../Common/Expat/lib/expat.h"
23 namespace Dasher {
24 class CColourIO;
26 class Dasher::CColourIO {
27 public:
28 // This structure completely describes the characters used in alphabet
29 struct ColourInfo {
30 // Basic information
31 std::string ColourID;
32 bool Mutable; // If from user we may play. If from system defaults this is immutable. User should take a copy.
34 // Complete description of the alphabet:
35 std::vector < int >Reds;
36 std::vector < int >Greens;
37 std::vector < int >Blues;
40 CColourIO(std::string SystemLocation, std::string UserLocation, std::vector < std::string > Filenames);
41 void GetColours(std::vector < std::string > *ColourList) const;
42 const ColourInfo & GetInfo(const std::string & ColourID);
43 void SetInfo(const ColourInfo & NewInfo);
44 void Delete(const std::string & ColourID);
45 private:
46 ColourInfo BlankInfo;
47 std::string SystemLocation;
48 std::string UserLocation;
49 std::map < std::string, ColourInfo > Colours; // map short names (file names) to descriptions
50 std::vector < std::string > Filenames;
52 void Save(const std::string & ColourID);
53 void CreateDefault(); // Give the user a default colour scheme rather than nothing if anything goes horribly wrong.
55 // XML handling:
56 /////////////////////////
58 bool LoadMutable;
59 void ParseFile(std::string Filename);
61 // & to &amp; < to &lt; and > to &gt; and if (Attribute) ' to &apos; and " to &quot;
62 void XML_Escape(std::string * Text, bool Attribute);
64 // Data gathered
65 std::string CData; // Text gathered from when an elemnt starts to when it ends
66 ColourInfo InputInfo;
68 // Callback functions. These involve the normal dodgy casting to a pointer
69 // to an instance to get a C++ class to work with a plain C library.
70 static void XML_StartElement(void *userData, const expat::XML_Char * name, const expat::XML_Char ** atts);
71 static void XML_EndElement(void *userData, const expat::XML_Char * name);
72 static void XML_CharacterData(void *userData, const expat::XML_Char * s, int len);
75 #endif /* #ifndef __ColourIO_h__ */