Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tao / Storable_File_Guard.h
blob89e120591237b6b0cd9e21e16edb956333967782
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Storable_File_Guard.h
7 * @author Rich Seibel (seibelr@ociweb.com)
8 * @author Byron Harris (harrisb@ociweb.com)
9 */
10 //=============================================================================
12 #ifndef TAO_STORABLE_FILE_GUARD_H
13 #define TAO_STORABLE_FILE_GUARD_H
15 #include "tao/Storable_Base.h"
17 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
19 namespace TAO
21 /**
22 * @class Storable_File_Guard
23 * @brief Base class to use with TAO_Storable_Base to synch object state
24 * with a storable base.
26 * A guard for Storable_Base that opens a file
27 * for read/write and sets a lock on it. It then checks if the file has
28 * changed and re-reads it if it has.
31 class TAO_Export Storable_File_Guard
33 public:
34 Storable_File_Guard (bool redundant,
35 bool use_backup = Storable_Base::use_backup_default);
37 virtual ~Storable_File_Guard () noexcept(false);
39 /// Releases the lock, closes the file, and deletes the I/O stream.
40 /// Destructors of derived classes should call this this will
41 /// virtual functions are available.
42 void release ();
44 /// Return when the object in memory has last changed
45 virtual time_t get_object_last_changed () = 0;
47 /// Get the underlying stream being used.
48 TAO::Storable_Base & peer ();
50 /// Indicate how the state of the object is being used.
51 /// This is used for determine the mode for accessing
52 /// the persistent store.
53 enum Method_Type
55 /// Construction with persistent file already existing
56 CREATE_WITH_FILE,
58 /// Construction with persistent file not existing
59 CREATE_WITHOUT_FILE,
61 /// Getting object state
62 ACCESSOR,
64 /// Setting object state
65 MUTATOR
68 protected:
69 /// Should be called by constructors of derived classes
70 /// since can't call the virtual functions below in constructor
71 /// of this class.
72 void init (Method_Type method_type);
74 /// Initializes the backing store file object but does not
75 /// actually load the data. This can be called without locks,
76 /// allowing the caller to decide whether or not to then lock
77 /// and complete the load.
78 void init_no_load (Method_Type method_type);
80 /// Complete the initialization of the containing object, should
81 /// be called with lock held after calling init_no_load
82 void reload ();
84 /// Check if the object is current with the last update.
85 virtual bool object_obsolete ();
87 /// Mark the object as up to date
88 virtual void mark_object_current ();
90 /// Indicate when the object in memory has last changed
91 virtual void set_object_last_changed (const time_t & time) = 0;
93 /// Load object from file to memory. Return 0 on success.
94 virtual int load_from_stream () = 0;
96 /// Answer if object has been loaded from file
97 virtual bool is_loaded_from_stream () = 0;
99 virtual Storable_Base * create_stream (const char * mode) = 0;
101 /// The pointer to the actual file I/O (bridge pattern)
102 Storable_Base *fl_;
104 private:
105 // Return 0 if successful.
106 int load ();
108 bool redundant_;
110 /// A flag to keep us from trying to close things more than once.
111 int closed_;
113 /// The flags that we were opened with
114 int rwflags_;
116 /// A flag indicating if backup/restore should be performed
117 bool use_backup_;
119 /// Symbolic values for the flags in the above
120 enum { mode_write = 1, mode_read = 2, mode_create = 4 };
124 TAO_END_VERSIONED_NAMESPACE_DECL
126 #endif