amath  1.8.5
Simple command line calculator
StandardPreferences Class Reference

#include <preferences_stdc.h>

Inheritance diagram for StandardPreferences:
Collaboration diagram for StandardPreferences:

Public Member Functions

virtual bool Load ()
 
virtual bool Keep ()
 
virtual bool Save ()
 
- Public Member Functions inherited from PreferencesBase
 PreferencesBase ()
 
virtual ~PreferencesBase ()
 
char * GetDescription () const
 
char * GetPrompt () const
 
void SetPrompt (const char *prompt)
 
int GetDigits () const
 
void SetDigits (int digits)
 
bool GetRefactorNames ()
 
void SetRefactorNames (bool yes)
 
void SetDefaults ()
 

Private Member Functions

bool SavePrefs (const char *file)
 

Additional Inherited Members

- Static Protected Member Functions inherited from PreferencesBase
static void SetPrefs (char *prefs)
 

Detailed Description

Definition at line 39 of file preferences_stdc.h.

Member Function Documentation

◆ Keep()

bool StandardPreferences::Keep ( )
virtual

Implements PreferencesBase.

Definition at line 83 of file preferences_stdc.cpp.

References SavePrefs(), and tempname.

84 {
85  return SavePrefs(tempname);
86 }
static const char * tempname
bool SavePrefs(const char *file)
Here is the call graph for this function:

◆ Load()

bool StandardPreferences::Load ( )
virtual

Implements PreferencesBase.

Definition at line 51 of file preferences_stdc.cpp.

52 {
53 #if defined(UNIX) && defined(HAIKU)
54  FILE *file = fopen(tempname, "r");
55  if (!file) {
56  return false;
57  }
58 
59  CharBuffer *text = new CharBuffer();
60  text->Empty();
61 
62  const int bufsize = 64;
63  char* buf = new char[bufsize];
64  char* c;
65  int s = 1;
66 
67  do {
68  c = fgets(buf, bufsize, file);
69  if (c != nullptr) {
70  text->EnsureSize(s++);
71  text->Append(c);
72  }
73  } while (c != nullptr);
74 
75  delete [] buf;
76  fclose(file);
77  SetPrefs(text->GetString());
78  delete text;
79 #endif
80  return true;
81 }
static const char * tempname
void Empty()
Definition: charbuf.cpp:218
char * GetString() const
Definition: charbuf.cpp:306
void Append(const char *source)
Definition: charbuf.cpp:262
CharBuffer * buf
Definition: preferences.h:56
static void SetPrefs(char *prefs)
Definition: preferences.cpp:93
Encapsulate an character array which can be used as a string.
Definition: charbuf.h:44
void EnsureSize(unsigned int size)
Ensure a memory block of specified size is allocated.
Definition: charbuf.cpp:114

◆ Save()

bool StandardPreferences::Save ( )
virtual

Implements PreferencesBase.

Definition at line 88 of file preferences_stdc.cpp.

References permname, and SavePrefs().

89 {
90  return SavePrefs(permname);
91 }
static const char * permname
bool SavePrefs(const char *file)
Here is the call graph for this function:

◆ SavePrefs()

bool StandardPreferences::SavePrefs ( const char *  file)
private

Definition at line 93 of file preferences_stdc.cpp.

Referenced by Keep(), and Save().

94 {
95 #if defined(UNIX) && defined(HAIKU)
96  FILE *file = fopen(name, "w");
97  if (!file) {
98  return false;
99  }
100 
101  char *out = GetDescription();
102  fputs(out, file);
103  fclose(file);
104 #endif
105  return true;
106 }
char * GetDescription() const
Definition: preferences.cpp:60
Here is the caller graph for this function:

The documentation for this class was generated from the following files: