// Generated by gtkmmproc -- DO NOT MODIFY!


#include <libgdamm/metastore.h>
#include <libgdamm/private/metastore_p.h>

// -*- C++ -*- // this is for the .ccg, I realize gensig puts one in

/* metastore.cc
 * 
 * Copyright 2003 libgdamm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <libgdamm/metastore.h>
#include <libgda/gda-meta-store.h>
#include <libgda/gda-enum-types.h>

namespace Gnome
{

namespace Gda
{
  
Glib::RefPtr<DataModel> MetaStore::extract(const Glib::ustring& sql)
{
  GError* gerror = 0;
  Glib::RefPtr<DataModel> retval = Glib::wrap(gda_meta_store_extract(gobj(), sql.c_str(), &gerror));

  if(gerror)
    ::Glib::Error::throw_exception(gerror);

  return retval;
}

bool MetaStore::modify(const Glib::ustring& sql, const Glib::RefPtr<DataModel>& data_model, const Glib::ustring& condition)
{
  GError* gerror = 0;
  bool retval = static_cast<bool>(gda_meta_store_modify(gobj(), sql.c_str(), Glib::unwrap(data_model), condition.c_str(), &gerror));

  if(gerror)
    ::Glib::Error::throw_exception(gerror);

  return retval;
}

bool MetaStore::get_attribute_value(const Glib::ustring& att_name, Glib::ustring& att_value)
{
  GError* gerror = 0;
  gchar* c_att_value = 0;
  bool retval = gda_meta_store_get_attribute_value(gobj(), att_name.c_str(), &c_att_value, &gerror);

  if(gerror)
    ::Glib::Error::throw_exception(gerror);
  if (c_att_value)
    att_value = c_att_value;

  return retval;
}

}

} /* namespace Gnome */


namespace
{


static const Glib::SignalProxyInfo MetaStore_signal_meta_reset_info =
{
  "meta-reset",
  (GCallback) &Glib::SignalProxyNormal::slot0_void_callback,
  (GCallback) &Glib::SignalProxyNormal::slot0_void_callback
};


} // anonymous namespace


Gnome::Gda::MetaStoreError::MetaStoreError(Gnome::Gda::MetaStoreError::Code error_code, const Glib::ustring& error_message)
:
  Glib::Error (GDA_META_STORE_ERROR, error_code, error_message)
{}

Gnome::Gda::MetaStoreError::MetaStoreError(GError* gobject)
:
  Glib::Error (gobject)
{}

Gnome::Gda::MetaStoreError::Code Gnome::Gda::MetaStoreError::code() const
{
  return static_cast<Code>(Glib::Error::code());
}

void Gnome::Gda::MetaStoreError::throw_func(GError* gobject)
{
  throw Gnome::Gda::MetaStoreError(gobject);
}

// static
GType Glib::Value<Gnome::Gda::MetaStoreError::Code>::value_type()
{
  return gda_meta_store_error_get_type();
}

// static
GType Glib::Value<Gnome::Gda::SqlIdentifierStyle>::value_type()
{
  return gda_sql_identifier_style_get_type();
}


namespace Glib
{

Glib::RefPtr<Gnome::Gda::MetaStore> wrap(GdaMetaStore* object, bool take_copy)
{
  return Glib::RefPtr<Gnome::Gda::MetaStore>( dynamic_cast<Gnome::Gda::MetaStore*> (Glib::wrap_auto ((GObject*)(object), take_copy)) );
  //We use dynamic_cast<> in case of multiple inheritance.
}

} /* namespace Glib */


namespace Gnome
{

namespace Gda
{


/* The *_Class implementation: */

const Glib::Class& MetaStore_Class::init()
{
  if(!gtype_) // create the GType if necessary
  {
    // Glib::Class has to know the class init function to clone custom types.
    class_init_func_ = &MetaStore_Class::class_init_function;

    // This is actually just optimized away, apparently with no harm.
    // Make sure that the parent type has been created.
    //CppClassParent::CppObjectType::get_type();

    // Create the wrapper type, with the same class/instance size as the base type.
    register_derived_type(gda_meta_store_get_type());

    // Add derived versions of interfaces, if the C type implements any interfaces:

  }

  return *this;
}


void MetaStore_Class::class_init_function(void* g_class, void* class_data)
{
  BaseClassType *const klass = static_cast<BaseClassType*>(g_class);
  CppClassParent::class_init_function(klass, class_data);


  klass->meta_reset = &meta_reset_callback;
}


void MetaStore_Class::meta_reset_callback(GdaMetaStore* self)
{
  Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
      Glib::ObjectBase::_get_current_wrapper((GObject*)self));

  // Non-gtkmmproc-generated custom classes implicitly call the default
  // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
  // generated classes can use this optimisation, which avoids the unnecessary
  // parameter conversions if there is no possibility of the virtual function
  // being overridden:
  if(obj_base && obj_base->is_derived_())
  {
    CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
    if(obj) // This can be NULL during destruction.
    {
      #ifdef GLIBMM_EXCEPTIONS_ENABLED
      try // Trap C++ exceptions which would normally be lost because this is a C callback.
      {
      #endif //GLIBMM_EXCEPTIONS_ENABLED
        // Call the virtual member method, which derived classes might override.
        obj->on_meta_reset();
        return;
      #ifdef GLIBMM_EXCEPTIONS_ENABLED
      }
      catch(...)
      {
        Glib::exception_handlers_invoke();
      }
      #endif //GLIBMM_EXCEPTIONS_ENABLED
    }
  }

  BaseClassType *const base = static_cast<BaseClassType*>(
        g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
    );

  // Call the original underlying C function:
  if(base && base->meta_reset)
    (*base->meta_reset)(self);
}


Glib::ObjectBase* MetaStore_Class::wrap_new(GObject* object)
{
  return new MetaStore((GdaMetaStore*)object);
}


/* The implementation: */

GdaMetaStore* MetaStore::gobj_copy()
{
  reference();
  return gobj();
}

MetaStore::MetaStore(const Glib::ConstructParams& construct_params)
:
  Glib::Object(construct_params)
{

}

MetaStore::MetaStore(GdaMetaStore* castitem)
:
  Glib::Object((GObject*)(castitem))
{}


MetaStore::~MetaStore()
{}


MetaStore::CppClassType MetaStore::metastore_class_; // initialize static member

GType MetaStore::get_type()
{
  return metastore_class_.init().get_type();
}


GType MetaStore::get_base_type()
{
  return gda_meta_store_get_type();
}


MetaStore::MetaStore(const Glib::ustring& cnc_string)
:
  // Mark this class as non-derived to allow C++ vfuncs to be skipped.
  Glib::ObjectBase(0),
  Glib::Object(Glib::ConstructParams(metastore_class_.init(), "cnc_string", cnc_string.c_str(), static_cast<char*>(0)))
{
  

}

Glib::RefPtr<MetaStore> MetaStore::create(const Glib::ustring& cnc_string)
{
  return Glib::RefPtr<MetaStore>( new MetaStore(cnc_string) );
}

int MetaStore::get_version() const
{
  return gda_meta_store_get_version(const_cast<GdaMetaStore*>(gobj()));
}

bool MetaStore::modify_with_context(MetaContext* context, const Glib::RefPtr<DataModel>& new_data)
{
  GError* gerror = 0;
  bool retvalue = gda_meta_store_modify_with_context(gobj(), context, Glib::unwrap(new_data), &(gerror));
  if(gerror)
    ::Glib::Error::throw_exception(gerror);

  return retvalue;

}

Glib::RefPtr<DataModel> MetaStore::create_modify_data_model(const Glib::ustring& table_name)
{
  return Glib::wrap(gda_meta_store_create_modify_data_model(gobj(), table_name.c_str()));
}

void MetaStore::set_identifiers_style(SqlIdentifierStyle style)
{
gda_meta_store_set_identifiers_style(gobj(), ((GdaSqlIdentifierStyle)(style))); 
}

Glib::RefPtr<MetaStruct> MetaStore::schema_get_structure()
{
  GError* gerror = 0;
  Glib::RefPtr<MetaStruct> retvalue = Glib::wrap(gda_meta_store_schema_get_structure(gobj(), &(gerror)));
  if(gerror)
    ::Glib::Error::throw_exception(gerror);

  return retvalue;

}

std::vector<Glib::ustring> MetaStore::schema_get_all_tables()
{
  return Glib::SListHandler<Glib::ustring>::slist_to_vector(gda_meta_store_schema_get_all_tables(gobj()), Glib::OWNERSHIP_SHALLOW);
}

std::vector<Glib::ustring> MetaStore::schema_get_depend_tables(const Glib::ustring& table_name)
{
  return Glib::SListHandler<Glib::ustring>::slist_to_vector(gda_meta_store_schema_get_depend_tables(gobj(), table_name.c_str()), Glib::OWNERSHIP_SHALLOW);
}

bool MetaStore::set_attribute_value(const Glib::ustring& att_name, const Glib::ustring& att_value)
{
  GError* gerror = 0;
  bool retvalue = gda_meta_store_set_attribute_value(gobj(), att_name.c_str(), att_value.c_str(), &(gerror));
  if(gerror)
    ::Glib::Error::throw_exception(gerror);

  return retvalue;

}

bool MetaStore::schema_add_custom_object(const Glib::ustring& xml_description)
{
  GError* gerror = 0;
  bool retvalue = gda_meta_store_schema_add_custom_object(gobj(), xml_description.c_str(), &(gerror));
  if(gerror)
    ::Glib::Error::throw_exception(gerror);

  return retvalue;

}

bool MetaStore::schema_remove_custom_object(const Glib::ustring& obj_name)
{
  GError* gerror = 0;
  bool retvalue = gda_meta_store_schema_remove_custom_object(gobj(), obj_name.c_str(), &(gerror));
  if(gerror)
    ::Glib::Error::throw_exception(gerror);

  return retvalue;

}

Glib::RefPtr<Connection> MetaStore::get_internal_connection()
{
  return Glib::wrap(gda_meta_store_get_internal_connection(gobj()));
}

Glib::RefPtr<const Connection> MetaStore::get_internal_connection() const
{
  return Glib::wrap(gda_meta_store_get_internal_connection(const_cast<GdaMetaStore*>(gobj())));
}


Glib::SignalProxy0< void > MetaStore::signal_meta_reset()
{
  return Glib::SignalProxy0< void >(this, &MetaStore_signal_meta_reset_info);
}


#ifdef GLIBMM_PROPERTIES_ENABLED
Glib::PropertyProxy_ReadOnly< Glib::RefPtr<Connection> > MetaStore::property_cnc() const
{
  return Glib::PropertyProxy_ReadOnly< Glib::RefPtr<Connection> >(this, "cnc");
}
#endif //GLIBMM_PROPERTIES_ENABLED


void Gnome::Gda::MetaStore::on_meta_reset()
{
  BaseClassType *const base = static_cast<BaseClassType*>(
      g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
  );

  if(base && base->meta_reset)
    (*base->meta_reset)(gobj());
}


} // namespace Gda

} // namespace Gnome


