Since I'm almost broke and stressed out, I've been spending all my time
hacking on ktechlab... I just spent most of the morning figuring out how
to better to link pin currents to nodal currents...
Here's a bad pattern I came across in Component:
#############################
void Component::setNodalCurrents() {
const ElementMapList::iterator end = m_elementMapList.end();
for (ElementMapList::iterator it = m_elementMapList.begin(); it != end;
++it) {
ElementMap m = (*it);
for (int i = 0; i < 4; i++) {
if (m.n[i]) {
m.n[i]->mergeCurrent(m.e->readCurrent(i));
}
}
}
}
########################
See that? We have a loop here that basically manipulates a datastructure
in another class and then sends it another data structure
__FROM_THE_SAME_CLASS__. This should never happen, here's a better code:
###############################
void Component::setNodalCurrents() {
const ElementMapList::iterator end = m_elementMapList.end();
for (ElementMapList::iterator it = m_elementMapList.begin(); it != end;
++it) {
(*it).mergeCurrents();
}
}
void ElementMap::mergeCurrents()
{
for (int i = 0; i < 4; i++) {
if (n[i]) {
n[i]->mergeCurrent(e->readCurrent(i));
}
}
}
##############################
See, that's much better. ;)
--
New president: Here we go again...
Chemistry.com: A total rip-off.
Powers are not rights.
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Ktechlab-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ktechlab-devel