WvStreams
uniinigen.h
1 /* -*- Mode: C++ -*-
2  * Worldvisions Weaver Software:
3  * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4  *
5  * A generator for .ini files.
6  */
7 #ifndef __UNICONFINI_H
8 #define __UNICONFINI_H
9 
10 #include "unitempgen.h"
11 #include "wvlog.h"
12 #include <sys/stat.h>
13 
14 class WvFile;
15 
25 class UniIniGen : public UniTempGen
26 {
27 public:
28  typedef wv::function<void()> SaveCallback;
29 
30 private:
31  WvString filename;
32  int create_mode;
33  WvLog log;
34  struct stat old_st;
35  SaveCallback save_cb;
36 
37 public:
42  UniIniGen(WvStringParm filename, int _create_mode = 0666,
43  SaveCallback _save_cb = SaveCallback());
44 
45  virtual ~UniIniGen();
46 
47  /***** Overridden members *****/
48 
49  virtual void commit();
50  virtual bool refresh();
51  virtual void set(const UniConfKey &key, WvStringParm value);
52 
53 private:
54 #ifndef _WIN32
55  // helper methods for commit
56  bool commit_atomic(WvStringParm real_filename);
57 #endif
58 
59  void save(WvStream &file, UniConfValueTree &parent);
60  bool refreshcomparator(const UniConfValueTree *a,
61  const UniConfValueTree *b);
62 };
63 
64 
65 #endif // __UNICONFINI_H