inlib  1.2.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes
inlib::wroot::key Class Reference
Inheritance diagram for inlib::wroot::key:
Inheritance graph
[legend]
Collaboration diagram for inlib::wroot::key:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 key (ifile &a_file, seek a_seek_parent_dir, const std::string &a_object_name, const std::string &a_object_title, const std::string &a_object_class, uint32 a_object_size)
virtual ~key ()
uint16 cycle () const
void set_cycle (uint16 a_cycle)
const std::string & object_name () const
std::string object_name ()
const std::string & object_class () const
std::string object_class ()
bool write_self ()
bool write_file (uint32 &a_nbytes)
void set_number_of_bytes (uint32 a_n)
uint32 number_of_bytes () const
uint32 object_size () const
seek seek_key () const
short key_length () const
char * data_buffer ()
const char * eob () const
bool to_buffer (wbuf &a_wb) const

Static Public Member Functions

static unsigned int std_string_record_size (const std::string &x)

Protected Member Functions

 key (const key &a_from)
keyoperator= (const key &)
uint32 record_size (uint32 a_version) const
bool initialize (uint32 a_nbytes)

Static Protected Member Functions

static std::string sout (const std::string &a_string)

Protected Attributes

ifilem_file
uint32 m_buf_size
char * m_buffer
uint32 m_nbytes
uint32 m_version
uint32 m_object_size
date m_date
uint16 m_key_length
uint16 m_cycle
seek m_seek_key
seek m_seek_parent_dir
std::string m_object_class
std::string m_object_name
std::string m_object_title

Detailed Description

Definition at line 21 of file key.


Constructor & Destructor Documentation

inlib::wroot::key::key ( ifile a_file,
seek  a_seek_parent_dir,
const std::string &  a_object_name,
const std::string &  a_object_title,
const std::string &  a_object_class,
uint32  a_object_size 
) [inline]

Definition at line 37 of file key.

  :m_file(a_file)
  ,m_buf_size(0)
  ,m_buffer(0)
  // Record :
  ,m_nbytes(0)
  ,m_version(class_version())
  ,m_object_size(a_object_size)
  ,m_date(0)
  ,m_key_length(0)
  ,m_cycle(0)
  ,m_seek_key(0)
  ,m_seek_parent_dir(0)
  ,m_object_class(a_object_class)
  ,m_object_name(a_object_name)
  ,m_object_title(a_object_title)
  {
#ifdef INLIB_MEM
    mem::increment(s_class().c_str());
#endif

    if(a_object_size) {
      if(m_file.END()>START_BIG_FILE()) m_version += 1000;
    }
    if(m_version>1000) {
    } else {
      if(a_seek_parent_dir>START_BIG_FILE()) m_version += 1000;
    }

    m_key_length = record_size(m_version);

    initialize(a_object_size);

    m_seek_parent_dir = a_seek_parent_dir;
  }
virtual inlib::wroot::key::~key ( ) [inline, virtual]

Definition at line 77 of file key.

                {
    delete [] m_buffer;
#ifdef INLIB_MEM
    mem::decrement(s_class().c_str());
#endif
  }
inlib::wroot::key::key ( const key a_from) [inline, protected]

Definition at line 84 of file key.

                        :m_file(a_from.m_file){
#ifdef INLIB_MEM
    mem::increment(s_class().c_str());
#endif
  }

Member Function Documentation

uint16 inlib::wroot::key::cycle ( ) const [inline]

Definition at line 91 of file key.

{return m_cycle;}
char* inlib::wroot::key::data_buffer ( ) [inline]

Definition at line 141 of file key.

{return m_buffer + m_key_length;}
const char* inlib::wroot::key::eob ( ) const [inline]

Definition at line 142 of file key.

{return m_buffer + m_buf_size;}
bool inlib::wroot::key::initialize ( uint32  a_nbytes) [inline, protected]

Definition at line 216 of file key.

                                   {
    uint32 nsize = m_key_length+a_nbytes;

    m_date = get_date();

    if(a_nbytes) {//GB
      m_seek_key = m_file.END();
      m_file.set_END(m_seek_key+nsize);
    } else { //basket
      m_seek_key = 0;
    }

    delete [] m_buffer;
    m_buffer = new char[nsize];
    m_buf_size = nsize;
    m_nbytes = nsize;

    return true;
  }
short inlib::wroot::key::key_length ( ) const [inline]

Definition at line 139 of file key.

{return m_key_length;}
uint32 inlib::wroot::key::number_of_bytes ( ) const [inline]

Definition at line 134 of file key.

{return m_nbytes;}
const std::string& inlib::wroot::key::object_class ( ) const [inline]

Definition at line 97 of file key.

{return m_object_class;}
std::string inlib::wroot::key::object_class ( ) [inline]

Definition at line 98 of file key.

{return m_object_class;}
const std::string& inlib::wroot::key::object_name ( ) const [inline]

Definition at line 94 of file key.

{return m_object_name;}
std::string inlib::wroot::key::object_name ( ) [inline]

Definition at line 95 of file key.

{return m_object_name;}
uint32 inlib::wroot::key::object_size ( ) const [inline]

Definition at line 136 of file key.

{return m_object_size;}
key& inlib::wroot::key::operator= ( const key ) [inline, protected]

Definition at line 89 of file key.

{return *this;}
uint32 inlib::wroot::key::record_size ( uint32  a_version) const [inline, protected]

Definition at line 195 of file key.

                                             {
    // Return the size in bytes of the key header structure.
    uint32 nbytes = sizeof(m_nbytes);
    nbytes += sizeof(short);
    nbytes += sizeof(m_object_size);
    nbytes += sizeof(date);
    nbytes += sizeof(m_key_length);
    nbytes += sizeof(m_cycle);
    if(a_version>1000) {
      nbytes += sizeof(seek);
      nbytes += sizeof(seek);
    } else {
      nbytes += sizeof(seek32);
      nbytes += sizeof(seek32);
    }
    nbytes += std_string_record_size(m_object_class);
    nbytes += std_string_record_size(m_object_name);
    nbytes += std_string_record_size(m_object_title);
    return nbytes;
  }
seek inlib::wroot::key::seek_key ( ) const [inline]

Definition at line 138 of file key.

{return m_seek_key;}
void inlib::wroot::key::set_cycle ( uint16  a_cycle) [inline]

Definition at line 92 of file key.

{m_cycle = a_cycle;}
void inlib::wroot::key::set_number_of_bytes ( uint32  a_n) [inline]

Definition at line 133 of file key.

{m_nbytes = a_n;}
static std::string inlib::wroot::key::sout ( const std::string &  a_string) [inline, static, protected]

Definition at line 191 of file key.

                                                   {
    return std::string("\"")+a_string+"\"";
  }
static unsigned int inlib::wroot::key::std_string_record_size ( const std::string &  x) [inline, static]

Definition at line 29 of file key.

                                                                 {
    // Returns size string will occupy on I/O buffer.
    if (x.size() > 254)
      return x.size()+sizeof(unsigned char)+sizeof(int);
    else
      return x.size()+sizeof(unsigned char);
  }
bool inlib::wroot::key::to_buffer ( wbuf a_wb) const [inline]

Definition at line 144 of file key.

                                   {
    if(!a_wb.write(m_nbytes)) return false;
    short version = m_version;
    if(!a_wb.write(version)) return false;
    if(!a_wb.write(m_object_size)) return false;
    unsigned int date = 0; //FIXME
    if(!a_wb.write(date)) return false;
    if(!a_wb.write(m_key_length)) return false;
    if(!a_wb.write(m_cycle)) return false;
    if(version>1000) {
      if(!a_wb.write(m_seek_key)) return false;
      if(!a_wb.write(m_seek_parent_dir)) return false;
    } else {
      if(m_seek_key>START_BIG_FILE()) {
        m_file.out() << "inlib::wroot::key::to_buffer :"
                     << " attempt to write big seek "
                     << m_seek_key << " on 32 bits."
                     << std::endl;
        return false;
      }
      if(!a_wb.write((seek32)m_seek_key)) return false;
      if(m_seek_parent_dir>START_BIG_FILE()) {
        m_file.out() << "inlib::wroot::key::to_buffer :"
                     << " (2) attempt to write big seek "
                     << m_seek_parent_dir << " on 32 bits."
                     << std::endl;
        return false;
      }
      if(!a_wb.write((seek32)m_seek_parent_dir)) return false;
    }
    if(!a_wb.write(m_object_class)) return false;
    if(!a_wb.write(m_object_name)) return false;
    if(!a_wb.write(m_object_title)) return false;
    if(m_file.verbose()) {
      m_file.out() << "inlib::wroot::key::to_buffer :"
                   << " nbytes : " << m_nbytes
                   << ", object class : " << sout(m_object_class)
                   << ", object name : " << sout(m_object_name)
                   << ", object title : " << sout(m_object_title)
                   << ", object size : " << m_object_size
                   << "." 
                   << std::endl;
    }
    return true;
  }
bool inlib::wroot::key::write_file ( uint32 a_nbytes) [inline]

Definition at line 106 of file key.

                                   {
    if(!m_file.set_pos(m_seek_key)) {
      a_nbytes = 0;
      return false;
    }
    if(!m_file.write_buffer(m_buffer,m_nbytes)) {
      a_nbytes = 0;
      return false;
    }

    if(m_file.verbose()) {
      m_file.out() << "inlib::wroot::key::write_file :"
                   << " writing " << m_nbytes << " bytes"
                   << " at address " << m_seek_key
                   << " for ID=" << sout(m_object_name)
                   << " Title=" << sout(m_object_title) << "."
                   << std::endl;
    }

    delete [] m_buffer; //???
    m_buffer = 0;
    m_buf_size = 0;

    a_nbytes = m_nbytes;
    return true;
  }
bool inlib::wroot::key::write_self ( ) [inline]

Definition at line 100 of file key.

                    {
    char* buffer = m_buffer;
    wbuf wb(m_file.out(),m_file.byte_swap(),eob(),buffer);
    return to_buffer(wb);
  }

Member Data Documentation

Definition at line 237 of file key.

char* inlib::wroot::key::m_buffer [protected]

Definition at line 238 of file key.

Definition at line 245 of file key.

Definition at line 243 of file key.

Definition at line 236 of file key.

Definition at line 244 of file key.

Definition at line 240 of file key.

std::string inlib::wroot::key::m_object_class [protected]

Definition at line 248 of file key.

std::string inlib::wroot::key::m_object_name [protected]

Definition at line 249 of file key.

Definition at line 242 of file key.

std::string inlib::wroot::key::m_object_title [protected]

Definition at line 250 of file key.

Definition at line 246 of file key.

Definition at line 247 of file key.

Definition at line 241 of file key.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines