• Main Page
  • Classes
  • Files
  • File List

CConfig.h

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2012 Bolton Software Ltd.
00004  * Copyright (C) 2002 Chris Schoeneman
00005  * 
00006  * This package is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * found in the file COPYING that should have accompanied this file.
00009  * 
00010  * This package is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 #ifndef CCONFIG_H
00020 #define CCONFIG_H
00021 
00022 #include "OptionTypes.h"
00023 #include "ProtocolTypes.h"
00024 #include "CNetworkAddress.h"
00025 #include "CStringUtil.h"
00026 #include "CInputFilter.h"
00027 #include "XBase.h"
00028 #include "stdmap.h"
00029 #include "stdset.h"
00030 #include "IPlatformScreen.h"
00031 #include <iosfwd>
00032 
00033 class CConfig;
00034 class CConfigReadContext;
00035 
00036 namespace std {
00037 template <>
00038 struct iterator_traits<CConfig> {
00039     typedef CString                     value_type;
00040     typedef ptrdiff_t                   difference_type;
00041     typedef bidirectional_iterator_tag  iterator_category;
00042     typedef CString*                    pointer;
00043     typedef CString&                    reference;
00044 };
00045 };
00046 
00048 
00057 class CConfig {
00058 public:
00059     typedef std::map<OptionID, OptionValue> CScreenOptions;
00060     typedef std::pair<float, float> CInterval;
00061 
00062     class CCellEdge {
00063     public:
00064         CCellEdge(EDirection side, float position);
00065         CCellEdge(EDirection side, const CInterval&);
00066         CCellEdge(const CString& name, EDirection side, const CInterval&);
00067         ~CCellEdge();
00068 
00069         CInterval       getInterval() const;
00070         void            setName(const CString& newName);
00071         CString         getName() const;
00072         EDirection      getSide() const;
00073         bool            overlaps(const CCellEdge&) const;
00074         bool            isInside(float x) const;
00075 
00076         // transform position to [0,1]
00077         float           transform(float x) const;
00078 
00079         // transform [0,1] to position
00080         float           inverseTransform(float x) const;
00081 
00082         // compares side and start of interval
00083         bool            operator<(const CCellEdge&) const;
00084 
00085         // compares side and interval
00086         bool            operator==(const CCellEdge&) const;
00087         bool            operator!=(const CCellEdge&) const;
00088 
00089     private:
00090         void            init(const CString& name, EDirection side,
00091                             const CInterval&);
00092 
00093     private:
00094         CString         m_name;
00095         EDirection      m_side;
00096         CInterval       m_interval;
00097     };
00098 
00099 private:
00100     class CName {
00101     public:
00102         CName(CConfig*, const CString& name);
00103 
00104         bool            operator==(const CString& name) const;
00105 
00106     private:
00107         CConfig*        m_config;
00108         CString         m_name;
00109     };
00110 
00111     class CCell {
00112     private:
00113         typedef std::map<CCellEdge, CCellEdge> CEdgeLinks;
00114 
00115     public:
00116         typedef CEdgeLinks::const_iterator const_iterator;
00117 
00118         bool            add(const CCellEdge& src, const CCellEdge& dst);
00119         void            remove(EDirection side);
00120         void            remove(EDirection side, float position);
00121         void            remove(const CName& destinationName);
00122         void            rename(const CName& oldName, const CString& newName);
00123 
00124         bool            hasEdge(const CCellEdge&) const;
00125         bool            overlaps(const CCellEdge&) const;
00126 
00127         bool            getLink(EDirection side, float position,
00128                             const CCellEdge*& src, const CCellEdge*& dst) const;
00129 
00130         bool            operator==(const CCell&) const;
00131         bool            operator!=(const CCell&) const;
00132 
00133         const_iterator  begin() const;
00134         const_iterator  end() const;
00135 
00136     private:
00137         CEdgeLinks      m_neighbors;
00138 
00139     public:
00140         CScreenOptions  m_options;
00141     };
00142     typedef std::map<CString, CCell, CStringUtil::CaselessCmp> CCellMap;
00143     typedef std::map<CString, CString, CStringUtil::CaselessCmp> CNameMap;
00144 
00145 public:
00146     typedef CCell::const_iterator link_const_iterator;
00147     typedef CCellMap::const_iterator internal_const_iterator;
00148     typedef CNameMap::const_iterator all_const_iterator;
00149     class const_iterator : std::iterator_traits<CConfig> {
00150     public:
00151         explicit const_iterator() : m_i() { }
00152         explicit const_iterator(const internal_const_iterator& i) : m_i(i) { }
00153 
00154         const_iterator& operator=(const const_iterator& i) {
00155             m_i = i.m_i;
00156             return *this;
00157         }
00158         CString         operator*() { return m_i->first; }
00159         const CString*  operator->() { return &(m_i->first); }
00160         const_iterator& operator++() { ++m_i;  return *this; }
00161         const_iterator  operator++(int) { return const_iterator(m_i++); }
00162         const_iterator& operator--() { --m_i;  return *this; }
00163         const_iterator  operator--(int) { return const_iterator(m_i--); }
00164         bool            operator==(const const_iterator& i) const {
00165             return (m_i == i.m_i);
00166         }
00167         bool            operator!=(const const_iterator& i) const {
00168             return (m_i != i.m_i);
00169         }
00170 
00171     private:
00172         internal_const_iterator m_i;
00173     };
00174 
00175     CConfig();
00176     virtual ~CConfig();
00177 
00179 
00180 
00182 
00186     bool                addScreen(const CString& name);
00187 
00189 
00193     bool                renameScreen(const CString& oldName,
00194                             const CString& newName);
00195 
00197 
00202     void                removeScreen(const CString& name);
00203 
00205 
00208     void                removeAllScreens();
00209 
00211 
00217     bool                addAlias(const CString& canonical,
00218                             const CString& alias);
00219 
00221 
00225     bool                removeAlias(const CString& alias);
00226 
00228 
00232     bool                removeAliases(const CString& canonical);
00233 
00235 
00238     void                removeAllAliases();
00239 
00241 
00256     bool                connect(const CString& srcName,
00257                             EDirection srcSide,
00258                             float srcStart, float srcEnd,
00259                             const CString& dstName,
00260                             float dstStart, float dstEnd);
00261 
00263 
00267     bool                disconnect(const CString& srcName,
00268                             EDirection srcSide);
00269 
00271 
00276     bool                disconnect(const CString& srcName,
00277                             EDirection srcSide, float position);
00278 
00280 
00284     void                setSynergyAddress(const CNetworkAddress&);
00285 
00287 
00292     bool                addOption(const CString& name,
00293                             OptionID option, OptionValue value);
00294 
00296 
00301     bool                removeOption(const CString& name, OptionID option);
00302 
00304 
00308     bool                removeOptions(const CString& name);
00309 
00311 
00315     CInputFilter*       getInputFilter();
00316 
00318 
00319 
00320 
00322 
00325     bool                isValidScreenName(const CString& name) const;
00326 
00328     const_iterator      begin() const;
00330     const_iterator      end() const;
00331 
00333     all_const_iterator  beginAll() const;
00335     all_const_iterator  endAll() const;
00336 
00338 
00341     bool                isScreen(const CString& name) const;
00342 
00344 
00347     bool                isCanonicalName(const CString& name) const;
00348 
00350 
00354     CString             getCanonicalName(const CString& name) const;
00355 
00357 
00364     CString             getNeighbor(const CString&, EDirection,
00365                             float position, float* positionOut) const;
00366 
00368 
00372     bool                hasNeighbor(const CString&, EDirection) const;
00373 
00375 
00379     bool                hasNeighbor(const CString&, EDirection,
00380                             float start, float end) const;
00381 
00383     link_const_iterator beginNeighbor(const CString&) const;
00385     link_const_iterator endNeighbor(const CString&) const;
00386 
00388     const CNetworkAddress&  getSynergyAddress() const;
00389 
00391 
00396     const CScreenOptions* getOptions(const CString& name) const;
00397 
00399 
00403     bool                    hasLockToScreenAction() const;
00404 
00406     bool                operator==(const CConfig&) const;
00408     bool                operator!=(const CConfig&) const;
00409 
00411 
00415     void                    read(CConfigReadContext& context);
00416 
00418 
00421     friend std::istream&    operator>>(std::istream&, CConfig&);
00422 
00424 
00427     friend std::ostream&    operator<<(std::ostream&, const CConfig&);
00428 
00430 
00433     static const char*  dirName(EDirection);
00434 
00436 
00439     static CString      formatInterval(const CInterval&);
00440 
00442 
00443 private:
00444     void                readSection(CConfigReadContext&);
00445     void                readSectionOptions(CConfigReadContext&);
00446     void                readSectionScreens(CConfigReadContext&);
00447     void                readSectionLinks(CConfigReadContext&);
00448     void                readSectionAliases(CConfigReadContext&);
00449 
00450     CInputFilter::CCondition*
00451                         parseCondition(CConfigReadContext&,
00452                             const CString& condition,
00453                             const std::vector<CString>& args);
00454     void                parseAction(CConfigReadContext&,
00455                             const CString& action,
00456                             const std::vector<CString>& args,
00457                             CInputFilter::CRule&, bool activate);
00458 
00459     void                parseScreens(CConfigReadContext&, const CString&,
00460                             std::set<CString>& screens) const;
00461     static const char*  getOptionName(OptionID);
00462     static CString      getOptionValue(OptionID, OptionValue);
00463 
00464 private:
00465     CCellMap            m_map;
00466     CNameMap            m_nameToCanonicalName;
00467     CNetworkAddress     m_synergyAddress;
00468     CScreenOptions      m_globalOptions;
00469     CInputFilter        m_inputFilter;
00470     bool                m_hasLockToScreenAction;
00471 };
00472 
00474 
00477 class CConfigReadContext {
00478 public:
00479     typedef std::vector<CString> ArgList;
00480 
00481     CConfigReadContext(std::istream&, SInt32 firstLine = 1);
00482     ~CConfigReadContext();
00483 
00484     bool            readLine(CString&);
00485     UInt32          getLineNumber() const;
00486 
00487     operator void*() const;
00488     bool            operator!() const;
00489 
00490     OptionValue     parseBoolean(const CString&) const;
00491     OptionValue     parseInt(const CString&) const;
00492     OptionValue     parseModifierKey(const CString&) const;
00493     OptionValue     parseCorner(const CString&) const;
00494     OptionValue     parseCorners(const CString&) const;
00495     CConfig::CInterval
00496                     parseInterval(const ArgList& args) const;
00497     void            parseNameWithArgs(
00498                         const CString& type, const CString& line,
00499                         const CString& delim, CString::size_type& index,
00500                         CString& name, ArgList& args) const;
00501     IPlatformScreen::CKeyInfo*
00502                     parseKeystroke(const CString& keystroke) const;
00503     IPlatformScreen::CKeyInfo*
00504                     parseKeystroke(const CString& keystroke,
00505                         const std::set<CString>& screens) const;
00506     IPlatformScreen::CButtonInfo*
00507                     parseMouse(const CString& mouse) const;
00508     KeyModifierMask parseModifier(const CString& modifiers) const;
00509 
00510 private:
00511     // not implemented
00512     CConfigReadContext& operator=(const CConfigReadContext&);
00513 
00514     static CString  concatArgs(const ArgList& args);
00515 
00516 private:
00517     std::istream&   m_stream;
00518     SInt32          m_line;
00519 };
00520 
00522 
00525 class XConfigRead : public XBase {
00526 public:
00527     XConfigRead(const CConfigReadContext& context, const CString&);
00528     XConfigRead(const CConfigReadContext& context,
00529                             const char* errorFmt, const CString& arg);
00530     ~XConfigRead();
00531 
00532 protected:
00533     // XBase overrides
00534     virtual CString     getWhat() const throw();
00535 
00536 private:
00537     CString             m_error;
00538 };
00539 
00540 #endif

Generated on Fri May 24 2013 00:00:03 for Synergy by  doxygen 1.7.1