// // $Id: Exchange.hpp,v 1.33 2008/11/25 22:06:28 philw Exp $ // #ifndef ExchangeINCLUDED #define ExchangeINCLUDED #ifndef RootINCLUDED # include "Root.hpp" #endif #ifndef EditObjINCLUDED # include "EditObj.hpp" #endif #ifndef EditObjListINCLUDED # include "EditObjList.hpp" #endif #ifndef ScalarSlotINCLUDED # include "ScalarSlot.hpp" #endif #ifndef SeriesSlotINCLUDED # include "SeriesSlot.hpp" #endif #ifndef TclINCLUDED # include "Tcl.hpp" #endif #include // class forward declarations class Payback; class Supply; template class ObjList; template class EditList; // type forward definitions typedef ObjList PaybackList; typedef EditList PaybackEditList; // // note: the Exchange class is intended to be held in an EditObjList, // but the GUI design doesn't allow it. if this mistake is // corrected: // // 1. the Exchange class should publicly inherit from the // EditObj class // // 2. the friend declaration for the AccountMgr class should be // removed. // // 3. the Exchange list type declarations should be reverted. // extern "C" { int exchangeCmd(ClientData, Tcl_Interp*, int, char**); } class Exchange : public Root, public EditObj { friend class AccountMgr; friend int exchangeCmd(ClientData, Tcl_Interp*, int, char**); public: // slot names static const RWCString SourceBalance; // source balance static const RWCString DestBalance; // destination balance static const RWCString Borrow; // borrow (pseudo-slot) private: RWCString _name; // name Supply *_borrowSupply; // borrow supply Supply *_inputBorrow; // input borrow supply (OWNERSHIP) Supply *_destSupply; // destination supply EditObjList _paybacks; // payback list PaybackEditList *_editList; // payback edit list Callback* _borrowCb; // borrow supply callback Callback* _destCb; // destincation supply callback Callback* _acctMgrCb; // account manager callback // slots SeriesSlot _sourceBalance; // source balance SeriesSlot _destBalance; // destination balance cwSlist _slotList; private: // EditObj: init, apply, cancel, and revert the edit using EditObj::init_edit; using EditObj::apply_edit; using EditObj::cancel_edit; using EditObj::revert_edit; virtual Exchange *init_edit() throw (cwException); virtual void apply_edit(Exchange *copy) throw (cwException); virtual void cancel_edit(Exchange *copy) throw (cwException); virtual void revert_edit(Exchange *orig) throw (cwException); // EditObj: is-modified virtual bool is_modified(const Exchange *orig) const; // EditObj: return the edit id virtual RWCString editobj_id() const; // load commands int borrow_cmd (Tcl_Interp *interp, int argc, char **argv); int dest_cmd (Tcl_Interp *interp, int argc, char **argv); int payback_cmd (Tcl_Interp *interp, int argc, char **argv); int input_cmd (Tcl_Interp *interp, int argc, char **argv); int slot_cmd (Tcl_Interp *interp, int argc, char **argv); // callbacks void addBorrowSupplyCallback(); // callback on _borrowSupply void deleteBorrowSupplyCallback(); // void addDestSupplyCallback(); // callback on _destSupply void deleteDestSupplyCallback(); // void addAccountMgrCallback(); // callback on AccountMgr void deleteAccountMgrCallback(); // public: // Supply deletion handler, used also by the Payback class. int supplyCbHandler (CallbackType, CallbackData*, void*); private: int accountMgrCbHandler (CallbackType, CallbackData*, void*); // set the borrow supply by name (when loading a model file) void setBorrowSupply(const RWCString &name) throw (cwException); // set the destination supply by name (when loading a model file) void setDestSupply(const RWCString &name) throw (cwException); // add a payback by payback supply name (when loading a model // file) Payback *addPayback(const RWCString &name) throw (cwException); // update the slot dates bool updateSlotDates(); // apply the slot configuration bool applySlotConfig(const SeriesSlot *slot); // given borrow or payback at T, solve for source balance at T bool solve_source_balance(const Date_Time *when, const Slot *slot); // given source balance at T, solve for source balance at T+1 bool solve_next_source_balance(const Date_Time *when, const Slot *slot); // given borrow or destination at T, solve for destination balance // at T bool solve_dest_balance(const Date_Time *when, const Slot *slot); // given destination balance at T, solve for destination balance // at T+1 bool solve_next_dest_balance(const Date_Time *when, const Slot *slot); // solve paybacks at T bool solve_paybacks(const Date_Time *when) const; public: // constructors and destructor Exchange(const RWCString &name = "Unnamed"); virtual ~Exchange(); // Virtual functions from Root class: virtual bool isExchange() const { return (TRUE); } virtual Root::SubclassType rootSubclassType() const { return (Root::SUBCLASS_EXCHANGE); } virtual const RWCString rootInstanceName() const { return _name; } // save and load bool save(cwostream &os) const; // tcl commands bool createTclCmd(Tcl_Interp *inter, const RWCString &cmd) const; // set and return the name void setName(const RWCString &name) throw (cwException); const RWCString getName() const; // set and return the borrow supply bool hasBorrowSupply() const; void setBorrowSupply(Supply *supply, bool origDeleted = false) throw (cwException); Supply *getBorrowSupply() const; // return the input borrow supply Supply *getInputBorrow() const; // return the borrow value at the specified timestep and offset bool getBorrowValue(double &value, const Date_Time *when, int offset = 0) const; // set and return the destination supply flag bool hasDestSupply() const; // set and return the destination supply void setDestSupply(Supply *supply, bool origDeleted = false) throw (cwException); Supply *getDestSupply() const; // return the destination value at the specified timestep and // offset bool getDestValue(double &value, const Date_Time *when, int offset = 0) const; // return the payback list int getPaybacks(PaybackList &paybacks) const; // edit the payback list PaybackEditList *getPaybackEditList() throw (cwException); // return the payback with the specified supply const Payback *getPayback(const Supply *supply) const; // sum the payback values at the specified timestep and offset // (with or without the losses applied) bool sumPaybackValues(double &sum, const Date_Time *when, int offset = 0) const; bool sumPaybackMinusLossValues(double &sum, const Date_Time *when, int offset = 0) const; // all supplies includes those on paybacks void retrieveAllSupplies (cwSlist& retList, bool enforceUnique = false) const; // return the unit type and standard scale and units unit_type getUnitType() const; double getStdScale() const; const RWCString getStdUnits() const; // set and return the user scale and units bool setUsrScale(double scale); bool setUsrUnits(const RWCString &units); double getUsrScale() const; const RWCString getUsrUnits() const; // set and return the format and precision bool setUsrFormat(const RWCString &format); bool setUsrPrecision(int precision); const RWCString getUsrFormat() const; int getUsrPrecision() const; // return the slot Slot *getSlot(const RWCString &name); const cwSlist& slotList() const { return (_slotList); } Slot *getPaybackSlot(const RWCString &name); SeriesSlot* getSourceBalanceSlot() const; SeriesSlot* getDestBalanceSlot() const; SeriesSlot* getBorrowSupplySlot() const; SeriesSlot* getInputBorrowSlot() const; SeriesSlot* getBorrowSlot() const; // return various names const RWCString getRiverWareName() const; const RWCString getCompleteName() const; // set the accounting period void setAccountingPeriod(const Date_Time *beginDate, const Date_Time *endDate, const DeltaTime *timestep = NULL) throw (cwException); // slot changed notification bool slotChanged(const Date_Time *when, const Slot *slot, CallbackType callback); // controller methods void clearState(); void clearOutputs(const class TimeInterval &interval); void clearOutputFlags(const class TimeInterval &interval); void clearIterations(); void setUserInput(RunInfo *ri); private: // note: the following methods should not be called (no bodies // provided) // constructors and destructor Exchange(const Exchange &exchange); // assignment operator Exchange &operator= (const Exchange &); }; // // inline methods // // rtti // set and return the name inline const RWCString Exchange::getName() const { return _name; } // set and return the borrow supply flag inline bool Exchange::hasBorrowSupply() const { return (_borrowSupply != NULL); } // set and return the borrow supply inline Supply *Exchange::getBorrowSupply() const { return _borrowSupply; } // return the input borrow supply inline Supply *Exchange::getInputBorrow() const { return _inputBorrow; } // set and return the destination supply flag inline bool Exchange::hasDestSupply() const { return (_destSupply == NULL); } // set and return the destination supply inline Supply *Exchange::getDestSupply() const { return _destSupply; } // // comparison functions for sorting exchanges // int compareExchangesByName(const Exchange * const &, const Exchange * const &); int compareExchangesByName(Exchange * const &, Exchange * const &); int compareExchangesByBorrowSupply(const Exchange * const &, const Exchange * const &); int compareExchangesByBorrowSupply(Exchange * const &, Exchange * const &); // // type definitions // //typedef ObjList ExchangeList; //typedef EditList ExchangeEditList; typedef cwDlist ExchangeList; #endif // ExchangeINCLUDED //--- (end Exchange.hpp) ---