Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Lounge

Name: Voiden Froze !!Bj5xlFz8N6pmNy3 2011-12-14 9:54

Okay /prog/ let's have a code-off!

The most fun way of carrying text over long lines, typical to that of your favorite    , in the language of your choice.

Let's kick off with some simple FIOCthp:


# -*- coding: cp1252 -*-
MAX_LINE_LENGTH =  60
a="""The list methods make it very easy to use a list as a stack, where the last element added is the first element retrieved (“last-in, first-out”). To add an item to the top of the stack, use append(). To retrieve an item from the top of the stack, use pop() without an explicit index. For example:"""

def cut_lines(words,result,line=''):
    if len(words):
        if len(words[0])>MAX_LINE_LENGTH:
            result.append(words.pop(0))
        else:
            test = line+words[0]+' '
            if len(test)<=MAX_LINE_LENGTH:
                words.pop(0)
                cut_lines(words,result,test)
            else:
                result.append(line)
                cut_lines(words,result)
    else:
        result.append(line)
       
def carry_lines(a):
    words=a.split()
    result=[]
    cut_lines(words,result)
    return result

for element in carry_lines(a):
    print element

Name: Anonymous 2011-12-14 10:42



#include "BatteryShell.h"

#include "base/SingletonHolder.h"

#include "COMv2/BatteryObjClass.h"
#include "COMv2/BatteryInstance.h"

#ifndef NO_SIM_GUI
#include "GUI/BatteryPanel.h"
#endif

//##ModelId=3F219FFC0203
DiscoverPolicy msf::BatteryShell::_policy;

//##ModelId=3FE235FD0272
//##ModelId=3FE235FD0286
//##ModelId=3FE235FD0287
msf::BatteryShell::BatteryShell(string name) :
    SimShell(name, _policy)
{
    Output::debug(DBG_SIM, DBG_CONSTRUC, "BatteryShell::BatteryShell(%s)\n", name.c_str());
    int updates;
    int acquisitions;
    _policy.requestSizes(updates, acquisitions);
    if ( ! updates ) {
    _policy.addUpdateRequest(
        SingletonHolder<msf::BatteryObjClass>::Instance().getAttributeHandle(
        msf::BatteryObjClass::VOLTAGE));
    _policy.addUpdateRequest(
        SingletonHolder<msf::BatteryObjClass>::Instance().getAttributeHandle(
        msf::BatteryObjClass::CAPACITY));
    _policy.addUpdateRequest(
        SingletonHolder<msf::BatteryObjClass>::Instance().getAttributeHandle(
        msf::BatteryObjClass::MAXIMUMCAPACITY));
    }
#ifndef NO_SIM_GUI
    _panel = new BatteryPanel(name);
    if ( getStatus() != GenericObjShell::READY ) {
    _panel->disable();
    }
#endif
}

//##ModelId=3FE235FD027C
msf::BatteryShell::~BatteryShell()
{
#ifndef NO_SIM_GUI
    if ( _panel ) delete _panel;
#endif
    Output::debug(DBG_SIM, DBG_DESTRUC, "~BatteryShell()\n");
}

void BatteryShell::reflect(ftk::HANDLE h)
{
#ifndef NO_SIM_GUI
    static ftk::HANDLE maxCapacity =
        SingletonHolder<BatteryObjClass>::Instance().getAttributeHandle(BatteryObjClass::MAXIMUMCAPACITY);
    static ftk::HANDLE currentCapacity =
        SingletonHolder<BatteryObjClass>::Instance().getAttributeHandle(BatteryObjClass::CAPACITY);
    static ftk::HANDLE currentVoltage =
        SingletonHolder<BatteryObjClass>::Instance().getAttributeHandle(BatteryObjClass::VOLTAGE);
    static ftk::HANDLE nomVoltage =
        SingletonHolder<BatteryObjClass>::Instance().getAttributeHandle(BatteryObjClass::NOMINALVOLTAGE);
   
    BatteryInstance* battery = dynamic_cast<BatteryInstance*>(supplierGet());
    BatteryPanel* panel = dynamic_cast<BatteryPanel*>(_panel);

    if ( battery && panel ) {

    if (h == maxCapacity) {
        panel->setMaximumCapacity(battery->maximumCapacityGet());
        return;
    }
    if (h == currentCapacity) {
        panel->setCurrentCapacity(battery->capacityGet());
        return;
    }
    if (h == nomVoltage) {
        panel->setNominalVoltage(battery->nominalVoltageGet());
        return;
    }
    if (h == currentVoltage) {
        panel->setCurrentVoltage(battery->voltageGet());
        return;
    }
    }
#endif
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List