Libmacro  0.2
Libmacro is an extensible macro and hotkey library.
string_key.h
Go to the documentation of this file.
1 /* Libmacro - A multi-platform, extendable macro and hotkey C library
2  Copyright (C) 2013 Jonathan Pelletier, New Paradigm Software
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
24 #ifndef MCR_EXTRAS_SIGNALS_STRING_KEY_H_
25 #define MCR_EXTRAS_SIGNALS_STRING_KEY_H_
26 
28 #include "mcr/extras/safe_string.h"
29 
30 namespace mcr
31 {
32 class MCR_API IStringKey
33 {
34 public:
36 
37  virtual bool cryptic() const = 0;
38  virtual void setCryptic(bool val) = 0;
39  virtual int seconds() const = 0;
40  virtual void setSeconds(int val) = 0;
41  virtual int milliseconds() const = 0;
42  virtual void setMilliseconds(int val) = 0;
43  virtual String text() const = 0;
44  virtual void setText(const String &val) = 0;
45 };
46 
48 class MCR_API StringKey: public ISignalMember, public IStringKey
49 {
50 public:
55 
56  StringKey(bool cryptic = false)
57  : string(_keyProvider, "", cryptic)
58  {
59  interval.seconds = 0;
60  interval.milliseconds = 40;
61  }
62  StringKey(const StringKey &copytron)
63  : ISignalMember(), interval(copytron.interval), string(copytron.string)
64  {
65  }
66  virtual ~StringKey() override = default;
67  StringKey &operator =(const StringKey &copytron)
68  {
69  if (&copytron != this) {
70  interval = copytron.interval;
71  string = copytron.string;
72  }
73  return *this;
74  }
75 
76  static void setKeyProvider(IKeyProvider *provider)
77  {
78  _keyProvider = provider;
79  }
80 
81  virtual bool cryptic() const override
82  {
83  return string.cryptic();
84  }
85  virtual void setCryptic(bool val) override
86  {
87  if (val != cryptic())
88  string.setCryptic(val);
89  }
90 
91  virtual int seconds() const override
92  {
93  return interval.seconds;
94  }
95  virtual void setSeconds(int val) override
96  {
97  interval.seconds = val;
98  }
99  virtual int milliseconds() const override
100  {
101  return interval.milliseconds;
102  }
103  virtual void setMilliseconds(int val) override
104  {
105  interval.milliseconds = val;
106  }
107 
109  virtual String text() const override
110  {
111  return string.text();
112  }
114  virtual void setText(const String &val) override
115  {
116  string.setText(val);
117  }
118 
120  virtual int compare(const IDataMember &rhs) const override
121  {
122  return compare(dynamic_cast<const StringKey &>(rhs));
123  }
125  virtual int compare(const StringKey &rhs) const;
129  virtual void copy(const IDataMember *copytron) override;
131  virtual const char *name() const override
132  {
133  return "StringKey";
134  }
135  virtual size_t addNameCount() const override
136  {
137  return 2;
138  }
139  virtual void addNames(const char **bufferOut,
140  size_t bufferLength) const override
141  {
142  const char *names[] = {"String Key", "string_key"};
143  size_t i, count = arrlen(names);
144  if (!bufferOut)
145  return;
146  for (i = 0; i < count && i < bufferLength; i++) {
147  bufferOut[i] = names[i];
148  }
149  }
151  virtual void send(mcr_Signal *signalPt) override;
152 private:
153  static IKeyProvider *_keyProvider;
154 };
155 }
156 
157 #endif
ISignalData - Data type for signal instances C++.
virtual void addNames(const char **bufferOut, size_t bufferLength) const override
Definition: string_key.h:139
virtual String text() const override
Definition: string_key.h:109
int milliseconds
Definition: noop.h:37
#define MCR_DECL_INTERFACE(className)
Definition: defines.h:434
virtual size_t addNameCount() const override
Definition: string_key.h:135
virtual const char * name() const override
Definition: string_key.h:131
Definition: noop.h:33
Libmacro, by Jonathan Pelletier, New Paradigm Software. Alpha version.
Definition: classes.h:31
virtual int compare(const IDataMember &rhs) const override
Definition: string_key.h:120
SafeString string
Definition: string_key.h:54
#define arrlen(arr)
Definition: defines.h:367
SafeString - A string that can be encrypted in memory IKeyProvider - Application-defined objects that...
virtual void setText(const String &val) override
Definition: string_key.h:114
int seconds
Definition: noop.h:35
mcr_NoOp interval
Definition: string_key.h:52