// -*- C++ -*- // $RCSfile: menuDef.C,v $ // $Revision: 1.6 $ // $Author: langer $ // $Date: 2000/11/01 17:07:45 $ /* This software was produced by NIST, an agency of the U.S. government, * and by statute is not subject to copyright in the United States. * Recipients of this software assume all responsibilities associated * with its operation, modification and maintenance. However, to * facilitate maintenance we ask that before distributing modifed * versions of this software, you first contact the authors at * oof_manager@ctcms.nist.gov. */ #ifndef MENUDEF_C #define MENUDEF_C #include "menuDef.h" /* name and helpstring types are parametrized so they can be either * const char* or const CharString&. */ template void AddVariable(Menu *m, NTYPE nm, HTYPE help, TYPE &x, void (*f)(const CharString&)) { Var *newvar = new Var(nm, help, x, f); m->AddOption(newvar); } template void AddVariable(Menu *m, NTYPE nm, HTYPE help, TYPE &x) { Var *newvar = new Var(nm, help, x); m->AddOption(newvar); } template void AddVariable(Menu *m, NTYPE nm, HTYPE help, TYPE &x, void (*f)(const CharString&), const MenuAttribute &att) { Var *newvar = new Var(nm, help, x, f, att); m->AddOption(newvar); } template void AddVariable(Menu *m, NTYPE nm, HTYPE help, TYPE &x, const MenuAttribute &att) { Var *newvar = new Var(nm, help, x, att); m->AddOption(newvar); } // --- template void AddArgument(CommandM *cmd, NTYPE nm, TYPE &x) { Var *arg = new Var(nm, x); cmd->arg.grow(1, arg); } template void AddArgument(CommandM *cmd, NTYPE nm, TYPE &x, const MenuAttribute &att) { Var *arg = new Var(nm, x, att); cmd->arg.grow(1, arg); } // ---------------------------------------------------------- // template Var::Var(const CharString &nm, const CharString &hs, TYPE &x, void (*f)(const CharString&)) : Variable(nm, hs, (void*)&x, f) {} template Var::Var(const CharString &nm, const CharString &hs, TYPE &x, void (*f)(const CharString&), const MenuAttribute &att) : Variable(nm, hs, (void*)&x, f, att) {} template Var::Var(const CharString &nm, const CharString &hs, TYPE &x) : Variable(nm, hs, (void*)&x) {} template Var::Var(const CharString &nm, const CharString &hs, TYPE &x, const MenuAttribute &att) : Variable(nm, hs, (void*)&x, 0, att) {} template Var::Var(const CharString &nm, TYPE &x) : Variable(nm, CharString(""), (void*)&x) {} template Var::Var(const CharString &nm, TYPE &x, const MenuAttribute &att) : Variable(nm, CharString(""), (void*)&x, 0, att) {} template Var::~Var() { if(oldvalue) delete (TYPE*) oldvalue; } template int Var::fromstring(const CharString &str, Waiter&) const { istrstream iss(str); iss >> *(TYPE*) address; if(iss) return 1; return 0; } // read from TextWaiter's input buffer template void Var::fromstring(TextWaiter &w) const { *w.inbuf >> *(TYPE*) address; } template CharString Var::tostring() const { return to_charstring(*(TYPE*) address); } template void Var::copyvalue(const Variable *v) { *(TYPE*) address = *((TYPE*)(v->address)); } template void Var::savevalue() { if(oldvalue) delete (TYPE*)oldvalue; oldvalue = new TYPE; *(TYPE*)oldvalue = *(TYPE*)address; } template void Var::restorevalue() { *(TYPE*) address = *(TYPE*) oldvalue; } // -------------------------------------------------------- // #include "varobjects.h" template VarObject *Var::create_varobject(Variable *var, Form *form, VarObjectType type, int x, int y, int w, int h) { return new DfltVarObject(var, form, type, x, y, w, h); } #include "tocharstring.C" #endif