Back
1 //------------------------------------------------------------------------------
2 // Module StyleFile.cpp //
3 // //
4 // Class TStyleFile which encapsulates several TItemStyle objects which //
5 // are loaded from style file //
6 // //
7 // Copyright (c) 2000-2004 by Lars Haendel //
8 // Home: http://www.newty.de //
9 // //
10 // This program is free software; you can redistribute it and/or modify //
11 // it under the terms of the GNU General Public License as published by //
12 // the Free Software Foundation as version 2 of the License. //
13 // //
14 // This program is distributed in the hope that it will be useful, //
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
17 // GNU General Public License for more details. //
18 // //
19 // You should have received a copy of the GNU General Public License //
20 // along with this program; if not, write to the Free Software //
21 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //
22 // //
23 //------------------------------------------------------------------------------
24
25
26 #ifndef StyleFileH
27 #define StyleFileH
28
29
30 #include <stdio> // due to: sprintf()
31 #include <fstream>
32
33 #include "stdList.h" // standard list template
34 #include "ItemStyle.h" // TItemStyle
35 #include "defines.h" // general defines
36
37
38
39 //----------------------------------------------------------------------------------------------------------------------
40 // class which encapsulates several TItemStyle objects which are loaded from style file
41 class TStyleFile
42 {
43 public:
44
45 // save styles to file, the style with number 'moveToFirst' is saved first if number is within legal range
46 void Save(const char*const& szFileName, const int& moveToFirst);
47
48 // load styles from file
49 void Load(const char*const& szFileName);
50
51
52 // functions to get, delete and insert a style
53 int nStyles() { return styles.Size(); } // return number of styles
54 TItemStyle* GetStyle(const int& id) { return &styles.Get(id); }; // gets style by id
55 TItemStyle* GetStyle(const char*const& szName); // get style by name
56 int GetStyleId(const char*const& szName); // get style id by name
57 void DeleteStyle(const int& id) { styles.Pos(id); styles.Del(); }; // delete style by id
58
59 // Insert new style into list and return reference
60 TItemStyle& InsertStyle(const TItemStyle*const& style) { styles.Reset(); styles.Ins(*style); return styles.Get(); };
61 TItemStyle& InsertStyle() { styles.Reset(); return styles.Ins(); };
62
63
64 private:
65
66 TStdList<TItemStyle> styles; // list with the styles
67
68 void WriteStyle2File(const TItemStyle& style, ofstream& file); // utility: write given style to given file
69 };
70 #endif
Top |