Jump to content

  • Log In with Google      Sign In   
  • Create Account

Codarki

Member Since 17 Feb 2004
Offline Last Active Sep 13 2013 07:22 PM

Topics I've Started

Happy Yule

22 December 2010 - 11:07 AM

Happy Yule

Local newspaper had a angry reader message that christmas was celebration of Jesus and non christians should not be allowed to have christian holidays. I always thought it was pagan festival. So I read a bit to educate myself.

It seems to be in winter solstice to celebrate Sol god. Or more recentyle in northern europe, to celebrate Norse god Odin. Julius Ceasar declared winter solstice to be December 25th at 46 BCE. Though atleast here at northern we celebrate it at 24th.

From 13th century Iceland books:
Quote:

Odin was referred to by many names in Skaldic poetry, some of which describe his appearance or functions. These include Síðgrani, Síðskeggr, Langbarðr, (all meaning "long beard") and Jólnir ("Yule figure").

According to Phyllis Siefker, children would place their boots, filled with carrots, straw, or sugar, near the chimney for Odin's flying horse, Sleipnir, to eat. Odin would then reward those children for their kindness by replacing Sleipnir's food with gifts or candy. This practice, survived in Germany, Belgium, and the Netherlands after the adoption of Christianity and became associated with Saint Nicholas as a result of the process of Christianization

Reindeers are from 1823 poem about St. Nicholas. Also some have made comparisons to Odins 8 legged horse that could leap distances.

Quote:

Saint Nicholas on December 6 came to be celebrated in many countries with the giving of gifts. In 16th-17th century Europe, many Protestants changed the gift bringer to the Christ Child or Christkindl, and the date for giving gifts changed from December 6 to Christmas Eve.

Christmas tree tradition is from Estonia and Germany from 15th and 16th century. Church banned gift giving in middle ages, and then retracted and attributed it to Saint Nicholas.

According to gospel of Luke (luke 1:5) Jesus was born during the reign of Herod the Great and when Cyrenius was governor of Syria. That means he born before 4 BC or around AD 6-7. According to John 8:57 he born around 18 BC. If they cant be sure about the year, I cant be sure they nailed Jesus' birth date aswell.

To me, it really doesn't matter anymore for which god the christmas belongs to. It's a great world-wide holiday. It just annoys me a bit when I see christians trying to tell others who can celebrate it.

Btw. I just scratched the issue but I gotta read up on Norse mythology more, just to understand my roots better. (Moon's day, Tyr's day, Odin's day, Thor's day, Freyja's day, Washing day, Sun's day)

Booze to get mind off the code

28 October 2010 - 09:57 AM

Do you do it?

Coding can be very stressful. I've had sleeping problems for years, usually cant get my mind off the problems, or trying to invent the silver bullet to save the project and not screw the deadline. No sleep destroys the mind and booze helps to put me at sleep, but leaving with a bit hangover..

I'm not interested about the dead brain cells becouse alcohol. How do you put your mind to sleep?

Decided to roll out custom RTTI.

02 March 2009 - 07:09 PM

So I'll ask my question before the gory details. Is it guaranteed that there is unique static const char* within a program, for the following? static char const my_constant[] = "constant_text"; I was to implementet event handling framework for my C++ UI lib. My goals was: - Simple to use and relatively simple to extend. - Separate handling of different events from each others, ie input handler does not need to know about paint events. - To allow components implement only specific event handlers. - Avoid dynamic_cast. - Extensible events and handlers. UI paint event does not know about graphics API, therefore I create matching d3d_paint_event, which has graphics device in its context, and handler for it. Now my first approach was to have abstract event handler interface for each event type. Then have event_dispatch_table inherit these handlers for double dispatch, then act as proxy and redirect them to invidual handlers. This worked ok, but it soon became apparent I would have to write bunch of proxy classes for stripping down the unwanted handlers, and bunch of adapter classes for converting events to graphics API or project specific events. Too much boiler plate. To avoid dynamic casts, next approach was kind of std::map of std::type_info to event handlers, to query handlers runtime. It seems std::type_info operator== is not much better than dynamic_cast, it performs strcmp() under the hood. No good. My requirements for std::type_info aren't so strict. I dont need to support multiple inheritance, nor any issues with DLLs (vtlb/type_info replication). Tried to stay away from implementing my own RTTI, but my options ran out. So I came up with this, using char* comparison. Is it guaranteed that there is unique static const char* within a program? Simplified example, compiles and works. I templatised the id, so it could be specialized to std::type_info aswell.
#include <boost/shared_ptr.hpp>
#include <map>

// helper struct to allow partial specialization for Event.
template<typename Event, typename Id = char const*>
struct handler_id_for_event;

// Event A
struct event_a_handler_base;
struct event_a
{
    typedef event_a_handler_base handler_type;
};

// Event A handler
struct event_a_handler_base
{
    typedef event_a event_type;
    virtual ~event_a_handler_base() {}
    virtual void handle(event_a& e) = 0;
};

template<typename Id = char const*>
struct event_a_handler : public event_a_handler_base
{
    static Id id();
};

template<>
char const* event_a_handler<char const*>::id()
{
    return "event_a_handler";
}

template<typename Id>
struct handler_id_for_event<event_a,Id>
{
    // Implicit conversion to Id.
    operator Id()
    {
        return event_a_handler<Id>::id();
    }
};

// Event B
struct event_b_handler_base;
struct event_b
{
    typedef event_b_handler_base handler_type;
};

// Event B handler
struct event_b_handler_base
{
    typedef event_b event_type;
    virtual ~event_b_handler_base() {}
    virtual void handle(event_b& e) = 0;
};

template<typename Id = char const*>
struct event_b_handler : public event_b_handler_base
{
    static Id id();
};

template<typename Id>
Id event_b_handler<Id>::id()
{
    return "event_b_handler";
}

template<typename Id>
struct handler_id_for_event<event_b,Id>
{
    // Implicit conversion to Id.
    operator Id()
    {
        return event_b_handler<Id>::id();
    }
};

// Dispatcher.
template<typename Id = char const*>
class event_dispatch_table
{
public:
    // Handler is required to implement function Id Handler::id().
    template<typename Handler>
    void insert(boost::shared_ptr<Handler> handler)
    {
        assert(m_handlers.find(Handler::id()) == m_handlers.end());
        m_handlers[Handler::id()] = handler;
    }

    // Event is required to provide Event::handler_type().
    // Also specialization for struct handler_id_for_event<Event> is
    // required.
    template<typename Event>
    void dispatch(Event& e)
    {
        Event::handler_type* handler
            = static_cast<Event::handler_type*>(handler_for_event<Event>());
        handler->handle(e);
    }

private:
    template<typename Event>
    void* handler_for_event()
    {
        Id id = handler_id_for_event<Event>();
        assert(m_handlers.find(id) != m_handlers.end());
        assert(m_handlers[id]);
        return m_handlers[id].get();
    }

private:
    std::map<Id,boost::shared_ptr<void> > m_handlers;
};

namespace {
    struct simple_a_handler : public event_a_handler<>
    {
        void handle(event_a&) {}
    };
    struct simple_b_handler : public event_b_handler<>
    {
        void handle(event_b&) {}
    };
}

int main()
{
    event_dispatch_table<> table;
    table.insert(
        boost::shared_ptr<event_a_handler<> >(new simple_a_handler));
    table.insert(
        boost::shared_ptr<event_b_handler<> >(new simple_b_handler));

    event_a a;
    event_b b;
    table.dispatch(a);
    table.dispatch(b);

    return 0;
}


STL weirdness

10 February 2006 - 09:02 AM

Can someone doublecheck if following works in VS 2005 in debug:
#define _HAS_ITERATOR_DEBUGGING 0
#include <string>

int do_stuff(std::string const& text)
{
    std::string::const_iterator i(text.end());
    return 0;
}

int main()
{
    std::string const test1("some_text");

    return do_stuff(test1.substr(0, 3));
}


I made a bugreport of it to msdn, will close it if i messed it.. EDIT: It should crash when it goes to destructor of the temporary string returned from substr. The text.end() (or text.begin()) causes that. [Edited by - Ftn on February 10, 2006 4:08:19 PM]

PARTNERS