Hi all,

I have a type "Colour" which I want to store in a single field rather than a different table or multiple fields. To accomplish this, I specialized the sql_value_traits template.

However, when I try to use it as a field:


    template<typename Action>
    void
    persist(Action & a)
    {
      dbo::field(a,m_colour,"colour");
    }

I get the following error:

vendor/Wt/Wt/Dbo/DbAction_impl.h:19: error: 'struct w::Colour' has no member named 'persist'

Now of course, I understand that objects which map to tables need this persist method, but do custom fields as well?

I've attached the source code of my Colour class.

Thanks for your time.

Sohail
#ifndef INCLUDED_COLOUR_HPP
#define INCLUDED_COLOUR_HPP

#include "model/Model.hpp"
#include <limits>
#include <iostream>

namespace w
{
  struct Colour
  {
    typedef boost::uint8_t  channel_t;
    typedef boost::uint32_t encoded_t;

    Colour(channel_t r,
           channel_t g,
           channel_t b,
           channel_t a = 0)
    {
      red()   = r;
      green() = g;
      blue()  = b;
      alpha() = a;
    }

    explicit
    Colour(encoded_t e = 0)
    {
      red()   = (e >> 0) & 0xff;
      green() = (e >> 8) & 0xff;
      blue()  = (e >> 16) & 0xff;
      alpha() = (e >> 24) & 0xff;
    }

    channel_t&
    red()
    { return m_red; }

    channel_t
    red() const
    { return m_red; }

    channel_t&
    green()
    { return m_green; }

    channel_t
    green() const
    { return m_green; }

    channel_t&
    blue()
    { return m_blue; }

    channel_t
    blue() const
    { return m_blue; }

    channel_t&
    alpha()
    { return m_alpha; }

    channel_t
    alpha() const
    { return m_alpha; }

    encoded_t
    encoded() const
    {
      return
        (red()   << 0)  |
        (green() << 8)  |
        (blue()  << 16) |
        (alpha() << 24)
        ;
    }

  private:
    channel_t m_red,
      m_green,
      m_blue,
      m_alpha;
  };
}

namespace Wt
{
  namespace Dbo
  {

    template<>
    struct WTDBO_API sql_value_traits<w::Colour,void> :
      sql_value_traits<int>
    {
      typedef sql_value_traits<int> base;

      static void bind(w::Colour const & c, SqlStatement *statement, int column,
                       int size);
      static bool read(w::Colour & c, SqlStatement * statement, int column,
                       int size);
    };

  }
}

#endif // COLOUR_HPP
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to