Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Textgeom conditionals #76

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Next Next commit
G4tgrFileIn: added some preprocessor-like conditionals
  • Loading branch information
Dominik Werthmueller committed Jul 30, 2024
commit 9ef1d60596517791cc9822f295e256f3675244da
6 changes: 6 additions & 0 deletions source/persistency/ascii/include/G4tgrFileIn.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#define G4tgrFileIn_hh 1

#include <vector>
#include <map>

#include "globals.hh"

Expand All @@ -60,6 +61,7 @@ class G4tgrFileIn
// Access data members

G4int Nline() { return theLineNo[theCurrentFile]; }
G4bool IgnoreLine() const { return ignoreLine; }

const G4String& GetName() { return theName; }

Expand All @@ -81,6 +83,10 @@ class G4tgrFileIn

std::vector<G4String> theNames;

std::map<G4String, G4String> theMacros;

G4bool ignoreLine = false;

G4int theCurrentFile = -1;
// Index of file being read in theFiles

Expand Down
124 changes: 124 additions & 0 deletions source/persistency/ascii/src/G4tgrFileIn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,130 @@ G4int G4tgrFileIn::GetWordsInLine(std::vector<G4String>& wordlist)
OpenNewFile(wordlist[1].c_str());
isok = GetWordsInLine(wordlist);
}
// check for 'define'
else if(wordlist[0] == "#define")
{
if(wordlist.size() != 2 && wordlist.size() != 3)
{
ErrorInLine();
G4String ErrMessage =
"'#define' should have one or two arguments (macro name, [macro body])!";
G4Exception("G4tgrFileIn::GetWordsInLine()", "InvalidInput",
FatalException, ErrMessage);
}

#ifdef G4VERBOSE
if(G4tgrMessenger::GetVerboseLevel() >= 3)
{
G4cout << " G4tgrFileIn::GetWordsInLine() - Define found !" << G4endl;
}
#endif
G4String macroBody;
if(wordlist.size() == 3)
{
macroBody = wordlist[2];
wordlist.pop_back();
}
theMacros[wordlist[1]] = macroBody;
wordlist.pop_back();
wordlist.pop_back();
}
// check for 'undef'
else if(wordlist[0] == "#undef")
{
if(wordlist.size() != 2)
{
ErrorInLine();
G4String ErrMessage =
"'#undef' should have as second argument, the macro name !";
G4Exception("G4tgrFileIn::GetWordsInLine()", "InvalidInput",
FatalException, ErrMessage);
}

#ifdef G4VERBOSE
if(G4tgrMessenger::GetVerboseLevel() >= 3)
{
G4cout << " G4tgrFileIn::GetWordsInLine() - Undef found !" << G4endl;
}
#endif
theMacros.erase(wordlist[1]);
wordlist.pop_back();
wordlist.pop_back();
}
// check for 'ifdef'
else if(wordlist[0] == "#ifdef")
{
if(wordlist.size() != 2)
{
ErrorInLine();
G4String ErrMessage =
"'#ifdef' should have as second argument, the macro name!";
G4Exception("G4tgrFileIn::GetWordsInLine()", "InvalidInput",
FatalException, ErrMessage);
}

#ifdef G4VERBOSE
if(G4tgrMessenger::GetVerboseLevel() >= 3)
{
G4cout << " G4tgrFileIn::GetWordsInLine() - Ifdef found !" << G4endl;
}
#endif
if (theMacros.find(wordlist[1]) == theMacros.end())
ignoreLine = true;
else
ignoreLine = false;
wordlist.pop_back();
wordlist.pop_back();
}
// check for 'ifndef'
else if(wordlist[0] == "#ifndef")
{
if(wordlist.size() != 2)
{
ErrorInLine();
G4String ErrMessage =
"'#ifndef' should have as second argument, the macro name!";
G4Exception("G4tgrFileIn::GetWordsInLine()", "InvalidInput",
FatalException, ErrMessage);
}

#ifdef G4VERBOSE
if(G4tgrMessenger::GetVerboseLevel() >= 3)
{
G4cout << " G4tgrFileIn::GetWordsInLine() - Ifndef found !" << G4endl;
}
#endif
if (theMacros.find(wordlist[1]) == theMacros.end())
ignoreLine = false;
else
ignoreLine = true;
wordlist.pop_back();
wordlist.pop_back();
}
// check for 'else'
else if(wordlist[0] == "#else")
{
#ifdef G4VERBOSE
if(G4tgrMessenger::GetVerboseLevel() >= 3)
{
G4cout << " G4tgrFileIn::GetWordsInLine() - else found !" << G4endl;
}
#endif
ignoreLine = !ignoreLine;
wordlist.pop_back();
}
// check for 'endif'
else if(wordlist[0] == "#endif")
{
#ifdef G4VERBOSE
if(G4tgrMessenger::GetVerboseLevel() >= 3)
{
G4cout << " G4tgrFileIn::GetWordsInLine() - endif found !" << G4endl;
}
#endif
ignoreLine = false;
wordlist.pop_back();
}

return isok;
}
Expand Down