summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/Filedata.h
blob: 1b85b71442b8d7bf9cb398de4efc60be0246c662 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef __FILEDATA_H
#define __FILEDATA_H

#include <time.h>

class CFiledata
{
    unsigned char* data;
    bool m_own;
 public:
    CFiledata(tchar* d)
    {
        data = (unsigned char*)d;
        m_own = false;
    }
    CFiledata(time_t dt, tchar* nm)
    {
        int nlen = ustrlen(nm)+1;
        data = new unsigned char[sizeof(time_t)+sizeof(tchar)*nlen];
        *((time_t *)data) = dt;
        memcpy(data+sizeof(time_t), nm, sizeof(tchar)*nlen);
        m_own = true;
    }
    ~CFiledata()
    {
        if (m_own && data != NULL)
        {
            delete [] data;
//      odebug << "~Filedata: deleting" << oendl;
        }
        else
        {
//      odebug << "~Filedata: not deleting" << oendl;
        }
    }
    tchar* name() const { return (tchar*)(data+sizeof(time_t)); }
    time_t date() { return *((time_t *)data); }
    void setdate(time_t _t) { *((time_t *)data) = _t; }
    unsigned char* content() { return data; }
    size_t length() const { return sizeof(time_t)+sizeof(tchar)*(ustrlen(name())+1); }
    bool operator==(const CFiledata& rhs)
    {
        return ((length() == rhs.length()) && (memcmp(data, rhs.data, length()) == 0));
    }
    bool samename(const CFiledata& rhs)
    {
        return (ustrcmp((tchar *)(data+sizeof(time_t)),(tchar *)(rhs.data+sizeof(time_t))) == 0);
    }
};

#endif