0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DataGeneratorQualifier.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
22 #ifndef Hypertable_Lib_DataGeneratorQualifier_h
23 #define Hypertable_Lib_DataGeneratorQualifier_h
24 
25 #include "Cell.h"
26 #include "DataGeneratorRandom.h"
28 
29 #include <Common/Config.h>
30 #include <Common/Logger.h>
31 #include <Common/String.h>
32 
33 #include <boost/shared_array.hpp>
34 
35 using namespace Hypertable;
36 
37 namespace Hypertable {
38 
39  class QualifierSpec {
40  public:
41  QualifierSpec() : type(-1), order(RANDOM), size(-1) { }
42  int type;
43  int order;
44  int size;
45  std::string charset;
46  unsigned seed;
47  std::string distribution;
48  };
49 
50  class Qualifier : public QualifierSpec {
51  public:
53  virtual ~Qualifier() { }
54  virtual bool next() = 0;
55  virtual std::string &get() = 0;
56  };
57 
58  class QualifierString : public Qualifier {
59  public:
61  HT_ASSERT(size > 0);
62  m_render_buf.reset( new char [ size + 1 ] );
63  ((char *)m_render_buf.get())[ size ] = 0;
64  }
65  virtual ~QualifierString() { }
66  virtual bool next() {
67  if (charset.length() > 0)
68  random_fill_with_chars((char *)m_render_buf.get(), size, charset.c_str());
69  else
71  m_qualifier = m_render_buf.get();
72  return false;
73  }
74  virtual std::string &get() { return m_qualifier; }
75  private:
76  boost::shared_array<const char> m_render_buf;
77  std::string m_qualifier;
78  };
79 
81  public:
82  static Qualifier *create(QualifierSpec &spec) {
83  if (spec.type == STRING)
84  return new QualifierString(spec);
85  else
86  HT_ASSERT(!"Invalid qualifier type");
87  }
88  };
89 
90 }
91 
92 #endif // Hypertable_Lib_DataGeneratorQualifier_h
boost::shared_array< const char > m_render_buf
Qualifier(QualifierSpec &spec)
virtual bool next()=0
static Qualifier * create(QualifierSpec &spec)
#define HT_ASSERT(_e_)
Definition: Logger.h:396
Logging routines and macros.
Hypertable definitions
void random_fill_with_chars(char *buf, size_t len, const char *charset=nullptr)
Fills a buffer with random values from a set of characters.
A String class based on std::string.
QualifierString(QualifierSpec &spec)
Configuration settings.