File: preferences.h

package info (click to toggle)
curves 0.8.7
  • links: PTS
  • area: main
  • in suites: slink
  • size: 704 kB
  • ctags: 1,001
  • sloc: cpp: 6,197; ansic: 519; makefile: 270; sh: 192; fortran: 149
file content (96 lines) | stat: -rw-r--r-- 2,841 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* preferences.h			-*- C++ -*-
   $Id: preferences.h,v 1.6 1998/09/10 20:51:00 elf Exp $
   
   written by Marc Singer
   27 Oct 1996

   This file is part of the project CurVeS.  See the file README for
   more information.

   Copyright (C) 1996 Marc Singer

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   in a file called COPYING along with this program; if not, write to
   the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
   02139, USA.

   -----------
   DESCRIPTION
   -----------

   Preference options management class.

*/

#if !defined (__PREFERENCES_H__)
#    define   __PREFERENCES_H__

/* ----- Includes */

#include <memory.h>

/* ----- Globals */

typedef struct _LPreferenceElement {
  struct _LPreferenceElement* pNext;
  char* szKeyword;
  char* szValue;
  char* szValueDefault;		// Default values for re-reads
} LPreferenceElement;

	// === This is a very important constant.  It is the maximum
	//     length allowed for any preference string.  It is
	//     important because the command strings that we compose
	//     will use it when allocating space to include commands
	//     specified by the user.  Internally, we will discard any
	//     preferences longer than this maximum.
#define CB_PREFERENCE_MAX	100
#define CB_COMMAND		(CB_PREFERENCE_MAX + 40)

class LPreferences {
protected:
  LPreferenceElement* m_pElements; 	// List of preference key/value pairs

  LPreferenceElement* _find (const char* szKeyword);
  void _associate (char* szKeyword, char* szValue);

public:  
  LPreferences () {
    zero (); }
  LPreferences (const char* szPath) {
    zero (); init (szPath); }
  ~LPreferences () {
    release_this (); }
  void zero (void) {
    memset (this, 0, sizeof (*this)); }
  void init (const char* szPath) {
    read (szPath); }
  void release_this (void);
  void release_entries (void);
  void release_settings (void);

  void associate (const char* szKeyword, const char* szValue);
  void associate (const char* szKeyword, int value);
  const char* fetch (const char* szKeyword);
  char* grab (char* pb, int cch);
  void read (const char* szPath);
  void transfer_defaults (void);

  bool as_bool (const char* szKeyword);
  int as_int (const char* szKeyword);

};

extern LPreferences g_preferences;		 // Everybody's favorite

#endif  /* __PREFERENCES_H__ */