WvStreams
uniinigen.h
00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  * 
00005  * A generator for .ini files.
00006  */
00007 #ifndef __UNICONFINI_H
00008 #define __UNICONFINI_H
00009 
00010 #include "unitempgen.h"
00011 #include "wvlog.h"
00012 #include <sys/stat.h>
00013 
00014 class WvFile;
00015 
00025 class UniIniGen : public UniTempGen
00026 {
00027 public:
00028     typedef wv::function<void()> SaveCallback;
00029 
00030 private:
00031     WvString filename;
00032     int create_mode;
00033     WvLog log;
00034     struct stat old_st;
00035     SaveCallback save_cb;
00036     
00037 public:
00042     UniIniGen(WvStringParm filename, int _create_mode = 0666,
00043             SaveCallback _save_cb = SaveCallback());
00044 
00045     virtual ~UniIniGen();
00046     
00047     /***** Overridden members *****/
00048 
00049     virtual void commit();
00050     virtual bool refresh();
00051     virtual void set(const UniConfKey &key, WvStringParm value);
00052 
00053 private:
00054 #ifndef _WIN32
00055     // helper methods for commit
00056     bool commit_atomic(WvStringParm real_filename);
00057 #endif
00058     
00059     void save(WvStream &file, UniConfValueTree &parent);
00060     bool refreshcomparator(const UniConfValueTree *a,
00061                            const UniConfValueTree *b);
00062 };
00063 
00064 
00065 #endif // __UNICONFINI_H