//OpenSCADA system file: tconfig.h /*************************************************************************** * Copyright (C) 2003-2017 by Roman Savochenko, * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; version 2 of the License. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef TCONFIG_H #define TCONFIG_H #include #include #include #include "tvariant.h" #include "telem.h" using std::string; using std::vector; using std::map; namespace OSCADA { //************************************************* //* TCfg * //************************************************* class TConfig; //#pragma pack(push,1) class TCfg : public TVariant { public: //Data enum AttrFlg { NoVal = 0x100, //Do not mirrore to value Key = 0x200, //Primary key Hide = 0x400 //Hide attribute }; enum ReqFlg { ForceUse = 0x01, //Force use flag }; //Methods TCfg( TFld &fld, TConfig &owner ); TCfg( const TCfg &cfg ); ~TCfg( ); const string &name( ); bool operator==( TCfg &cfg ); TCfg &operator=( const TCfg &cfg ); bool view( ) const { return mView; } bool keyUse( ) const { return mKeyUse; } bool noTransl( ) const { return mNoTransl; } bool isKey( ) const; //Whether real or request key test void setView( bool vw ) { mView = vw; } void setKeyUse( bool vl ) { if( fld().flg()&Key ) mKeyUse = vl; } void setNoTransl( bool vl ) { mNoTransl = vl; } TFld &fld( ) const { return *mFld; } //> Universal access string getSEL( ); string getS( ) const; operator bool( ) { return getB(); } //> Direct access. Use only for readonly config-fields by no resourced! const char *getSd( ); double &getRd( ); int &getId( ); char &getBd( ); void setSEL( const string &val, uint8_t RqFlg = 0 ); void setS( const string &val ); void setS( const string &val, uint8_t RqFlg ); void setR( double val ); void setR( double val, uint8_t RqFlg ); void setI( int val ); void setI( int val, uint8_t RqFlg ); void setB( char val ); void setB( char val, uint8_t RqFlg ); TCfg &operator=( const string &vl ) { setS(vl); return *this; } TCfg &operator=( const char *vl ) { setS(vl); return *this; } TCfg &operator=( double vl ) { setR(vl); return *this; } TCfg &operator=( int vl ) { setI(vl); return *this; } TCfg &operator=( bool vl ) { setB(vl); return *this; } TConfig &owner( ) const { return mOwner; } private: //Attributes uint8_t mView : 1; uint8_t mKeyUse : 1; uint8_t mNoTransl : 1; uint8_t mInCfgCh : 1; TFld *mFld; TConfig &mOwner; }; //#pragma pack(pop) //************************************************* //* TConfig * //************************************************* typedef map< string, TCfg* > TCfgMap; class TConfig: public TValElem { friend class TCfg; public: //Methods TConfig( TElem *Elements = NULL ); TConfig( const TConfig &src ); virtual ~TConfig( ); TConfig &operator=( const TConfig &cfg ); TConfig &exclCopy( const TConfig &cfg, const string &passCpLs = "", bool cpElsToSingle = false ); void cfgList( vector &list ) const; bool cfgPresent( const string &n_val ) const; TCfg &cfg( const string &n_val ) const; TCfg *at( const string &n_val, bool noExpt = false ) const; void cfgViewAll( bool val = true ); // Show/Hide all no key elements void cfgKeyUseAll( bool val ); TElem &elem( ) { return *mElem; } void setElem( TElem *Elements, bool first = false ); void cntrCmdMake( XMLNode *fld, const string &path, int pos, const string &user = "root", const string &grp = "root", int perm = 0664 ); void cntrCmdProc( XMLNode *fld, const string &elem, const string &user = "root", const string &grp = "root", int perm = 0664 ); TVariant objFunc( const string &id, vector &prms, const string &user ); protected: //Methods virtual bool cfgChange( TCfg &co, const TVariant &pc ) { return true; } void detElem( TElem *el ); void addFld( TElem *el, unsigned id ); void delFld( TElem *el, unsigned id ); //Attributes ResMtx mRes; private: //Attributes TCfgMap value; TElem *mElem; uint8_t single : 1; }; } #endif // TCONFIG_H