BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSMySQLWrapper.hh
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2023.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef BDSMYSQLWRAPPER_H
20#define BDSMYSQLWRAPPER_H
21
22#include "globals.hh"
23
24#include <fstream>
25#include <vector>
26#include <string>
27
28class BDSMySQLTable;
29
30#define _NEXT if(!NextToken()) return;
31#define _NEXTINPUT if(!NextInputToken()) return;
32#define CMD_CREATE "CREATE"
33#define CMD_TABLE "TABLE"
34#define CMD_INSERT "INSERT"
35#define CMD_INTO "INTO"
36#define CMD_VALUES "VALUES"
37#define CMD_DROP "DROP"
38#define CMD_DATABASE "DATABASE"
39#define CMD_USE "USE"
40#define CMD_IF "IF"
41#define CMD_EXISTS "EXISTS"
42
50{
51public:
52 explicit BDSMySQLWrapper (const G4String& SQLFileName);
54
55 std::vector<BDSMySQLTable*> ConstructTable();
56
57 G4int GetComponentN() {return ComponentN;}
58
59 std::vector<BDSMySQLTable*> table;
60
61private:
62 BDSMySQLWrapper() = delete;
63 // Data Members for Class Attributes
64
65 std::ifstream ifs;
66
67 G4String CurrentTableName;
68 G4String InsertTableName;
69 G4int ComponentN;
70
71 G4int tableN;
72
73 void ReadLine();
74 void RemoveCommentsFromLine(std::string& value);
75 void RemoveQuotesFromLine(std::string& value);
76 void RemoveWhitespace(std::string&);
77 void RemoveWhitespace(G4String&);
78 void TokenizeLine();
79 std::vector<std::string> _tokens;
80 std::vector<std::string>::iterator _tokens_iter;
81
82 void BeginTokens();
83 bool NextToken();
84 bool NextInputToken();
85 bool EndTokens();
86 std::string Token();
87 bool EndOfLine();
88 bool EmptyToken();
89 void ProceedToEndOfLine();
90 G4int ParseComponent();
91 //Methods for carrying out the various instructions:
92 void Create();
93 void CreateDatabase();
94 void CreateTable();
95 void Insert();
96 void InsertInto();
97 void Values();
98
99 std::string _currentLine;
100 bool _startOfFile;
101};
102
103#endif
Representation of a mysql table.
Wrapper for mysql file handling.