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