~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.h

  • Committer: Jay Pipes
  • Date: 2009-06-11 18:38:33 UTC
  • mto: This revision was merged to the branch mainline in revision 1061.
  • Revision ID: jpipes@serialcoder-20090611183833-e9m2tmlfkdwluue1
Refactors sys_var class -- doxygenates and documents the class members and functions. Protects all member variables and adds public getters/setters.

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
  sys_var *last;
60
60
};
61
61
 
 
62
/**
 
63
 * A class which represents a variable, either global or 
 
64
 * session-local.
 
65
 */
62
66
class sys_var
63
67
{
64
 
public:
 
68
protected:
 
69
  const std::string name; /**< The name of the variable */
 
70
  sys_after_update_func after_update; /**< Function pointer triggered after the variable's value is updated */
 
71
  struct my_option *option_limits; /**< Updated by by set_var_init() */
 
72
  bool m_allow_empty_value; /**< Does variable allow an empty value? */
65
73
  sys_var *next;
66
 
  struct my_option *option_limits;      /* Updated by by set_var_init() */
67
 
  uint32_t name_length;                 /* Updated by by set_var_init() */
68
 
  const std::string name;
69
 
 
70
 
  sys_after_update_func after_update;
 
74
public:
71
75
  sys_var(const char *name_arg, sys_after_update_func func= NULL)
72
 
    :name(name_arg), after_update(func),
 
76
    :
 
77
    name(name_arg),
 
78
    after_update(func),
73
79
    m_allow_empty_value(true)
74
80
  {}
75
81
  virtual ~sys_var() {}
82
88
    chain_arg->last= this;
83
89
  }
84
90
 
85
 
/* So that we can exist in a Registry. We really need to formalize that */
86
 
  std::string getName() const { return name; }
87
 
  const std::vector<std::string>& getAliases() const { return empty_aliases; }
88
 
 
 
91
  /** 
 
92
   * Returns the name of the variable.
 
93
   *
 
94
   * @note 
 
95
   *
 
96
   * So that we can exist in a Registry. We really need to formalize that 
 
97
   */
 
98
  inline const std::string &getName() const
 
99
  {
 
100
    return name;
 
101
  }
 
102
  /**
 
103
   * Returns a vector of strings representing aliases
 
104
   * for this variable's name.
 
105
   */
 
106
  const std::vector<std::string>& getAliases() const
 
107
  {
 
108
    return empty_aliases;
 
109
  }
 
110
  /**
 
111
   * Returns a pointer to the next sys_var, or NULL if none.
 
112
   */
 
113
  inline sys_var *getNext() const
 
114
  {
 
115
    return next;
 
116
  }
 
117
  /**
 
118
   * Sets the pointer to the next sys_var.
 
119
   *
 
120
   * @param Pointer to the next sys_var, or NULL if you set the tail...
 
121
   */
 
122
  inline void setNext(sys_var *in_next)
 
123
  {
 
124
    next= in_next;
 
125
  }
 
126
  /**
 
127
   * Returns a pointer to the variable's option limits
 
128
   */
 
129
  inline struct my_option *getOptionLimits() const
 
130
  {
 
131
    return option_limits;
 
132
  }
 
133
  /**
 
134
   * Sets the pointer to the variable's option limits
 
135
   *
 
136
   * @param Pointer to the option limits my_option variable
 
137
   */
 
138
  inline void setOptionLimits(struct my_option *in_option_limits)
 
139
  {
 
140
    option_limits= in_option_limits;
 
141
  }
 
142
  /** 
 
143
   * Returns the function pointer for after update trigger, or NULL if none.
 
144
   */
 
145
  inline sys_after_update_func getAfterUpdateTrigger() const
 
146
  {
 
147
    return after_update;
 
148
  }
89
149
  virtual bool check(Session *session, set_var *var);
90
150
  bool check_enum(Session *session, set_var *var, const TYPELIB *enum_names);
91
151
  bool check_set(Session *session, set_var *var, TYPELIB *enum_names);
92
152
  virtual bool update(Session *session, set_var *var)=0;
93
153
  virtual void set_default(Session *, enum_var_type)
94
154
  {}
95
 
  virtual SHOW_TYPE show_type() { return SHOW_UNDEF; }
 
155
  virtual SHOW_TYPE show_type()
 
156
  {
 
157
    return SHOW_UNDEF;
 
158
  }
96
159
  virtual unsigned char *value_ptr(Session *, enum_var_type, const LEX_STRING *)
97
 
  { return 0; }
 
160
  {
 
161
    return 0;
 
162
  }
98
163
  virtual bool check_type(enum_var_type type)
99
 
  { return type != OPT_GLOBAL; }                /* Error if not GLOBAL */
 
164
  {
 
165
    return type != OPT_GLOBAL;
 
166
  }             /* Error if not GLOBAL */
100
167
  virtual bool check_update_type(Item_result type)
101
 
  { return type != INT_RESULT; }                /* Assume INT */
 
168
  {
 
169
    return type != INT_RESULT;
 
170
  }             /* Assume INT */
102
171
  virtual bool check_default(enum_var_type)
103
 
  { return option_limits == 0; }
 
172
  {
 
173
    return option_limits == 0;
 
174
  }
104
175
  Item *item(Session *session, enum_var_type type, const LEX_STRING *base);
105
 
  virtual bool is_struct() { return 0; }
106
 
  virtual bool is_readonly() const { return 0; }
107
 
  virtual sys_var_pluginvar *cast_pluginvar() { return 0; }
108
 
 
109
 
private:
110
 
  bool m_allow_empty_value;
 
176
  virtual bool is_struct()
 
177
  {
 
178
    return 0;
 
179
  }
 
180
  virtual bool is_readonly() const
 
181
  {
 
182
    return 0;
 
183
  }
 
184
  virtual sys_var_pluginvar *cast_pluginvar()
 
185
  {
 
186
    return 0;
 
187
  }
111
188
};
112
189
 
113
 
 
114
 
/*
115
 
  A base class for all variables that require its access to
116
 
  be guarded with a mutex.
117
 
*/
118
 
 
 
190
/**
 
191
 * A base class for all variables that require its access to
 
192
 * be guarded with a mutex.
 
193
 */
119
194
class sys_var_global: public sys_var
120
195
{
121
196
protected:
122
197
  pthread_mutex_t *guard;
123
198
public:
124
 
  sys_var_global(const char *name_arg, sys_after_update_func after_update_arg,
 
199
  sys_var_global(const char *name_arg,
 
200
                 sys_after_update_func after_update_arg,
125
201
                 pthread_mutex_t *guard_arg)
126
 
    :sys_var(name_arg, after_update_arg), guard(guard_arg) {}
 
202
    :
 
203
      sys_var(name_arg, after_update_arg), 
 
204
      guard(guard_arg) 
 
205
  {}
127
206
};
128
207
 
129
 
 
130
208
class sys_var_uint32_t_ptr :public sys_var
131
209
{
132
210
  uint32_t *value;
898
976
  /* light check for PS */
899
977
};
900
978
 
901
 
 
902
979
/* MySQL internal variables */
903
 
 
904
980
class set_var :public set_var_base
905
981
{
906
982
public: