TclXXFiberSectionCommand.cpp

For developers writing C++, Fortran, Java, code who have questions or comments to make.

Moderators: silvia, selimgunay, Moderators

Post Reply
motalaat
Posts: 17
Joined: Wed Jul 21, 2004 11:10 am
Location: UC Berkeley
Contact:

TclXXFiberSectionCommand.cpp

Post by motalaat » Sat Nov 05, 2005 6:49 pm

I have written a XXFiberSection2d class [XX is a dummy] which is a modification on the existing one. The class is up and running. My question has to do with considerations of good coding.

It is recommended practice that - instead of adding the required interpreter command in the original TclModel BuilderSectionCommand.cpp - one should write his/her own interpreter-command file (call it TclXXFiberSectionCommand.cpp) and only include a declaration for it (call it TclModelBuilder_addXXFiberSection) in the original file; along with an if-clause which calls the external command when requested. It has been a practice I kept successfully with materials, however, with the fiber section, I have run across the following problem:

The TclModelBuilder_addXXFiberSection command needs to call the addPatch() method to parse the subcommands in the {}. This method exists in the original TclModel BuilderSectionCommand.cpp file. When it is called from outside the file, it returns an error. This happens because it checks for the value of the integer variable "currentSectionTag". This variable is declared "Static int" in TclModel BuilderSectionCommand.cpp, and my limited knowledge of C++ doesn't help me to think of a way to change its value when I call the addPatch() command from my TclXXFiberSectionCommand.cpp file. I had to revert to the not-so-elegant solution of copying and pasting all my interpreter commands into the original file and discarding TclXXFiberSectionCommand.cpp during compilation, but I am sure there must be a way around it that will keep my interpreter comands "external". The only thing I can think of is to copy the addPatch() method to my external file and rename it but that would be flimsy patchwork.

Can one type something like

Code: Select all

TclModelBuilderSectionCommand::currentSectionTag = 1
? I have tried this exact one but it won't recognize it because TclModelBuilderSectionCommand is a filename - not a class.

I guess the question boils down to, "how to change the value of a static variable which is declared and exists in another file and does not belong to any method or class? C++ pundits, any clue?

Post Reply