summaryrefslogtreecommitdiff
path: root/l10ntools/inc/po.hxx
blob: 9163e6a10230f1c086ef50591dd839fa0e29be90 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#ifndef _PO_INCLUDED
#define _PO_INCLUDED

#include <fstream>
#include <rtl/string.hxx>
#include <boost/noncopyable.hpp>

class PoOfstream;
class PoIfstream;

class GenPoEntry
{
private:

    OString    m_sWhiteSpace;
    OString    m_sExtractCom;
    OString    m_sReference;
    OString    m_sContext;
    OString    m_sUnTransStr;
    OString    m_sTransStr;
    bool       m_bFuzzy;
    bool       m_bNull;
    OString    m_sKeyId;

public:

                        GenPoEntry();
    virtual             ~GenPoEntry();
                        //Default copy constructor and copy operator work well

    virtual OString     getWhiteSpace() const   { return m_sWhiteSpace; }
    virtual OString     getExtractCom() const   { return m_sExtractCom; }
    virtual OString     getReference() const    { return m_sReference; }
    virtual OString     getContext() const      { return m_sContext; }
    virtual OString     getUnTransStr() const   { return m_sUnTransStr; }
    virtual OString     getTransStr() const     { return m_sTransStr; }
    virtual bool        getFuzzy() const        { return m_bFuzzy; }
    virtual bool        isNull() const          { return m_bNull; }
    virtual OString     getKeyId() const        { return m_sKeyId; }

    virtual void        setWhiteSpace(const OString& rWhiteSpace);
    virtual void        setExtractCom(const OString& rExtractCom);
    virtual void        setReference(const OString& rReference);
    virtual void        setContext(const OString& rContext);
    virtual void        setUnTransStr(const OString& rUnTransStr);
    virtual void        setTransStr(const OString& rTransStr);
    virtual void        setFuzzy(const bool bFuzzy);
    virtual void        genKeyId();

    virtual void        writeToFile(std::ofstream& rOFStream) const;
    virtual void        readFromFile(std::ifstream& rIFStream);
};

class PoEntry
{
private:

    GenPoEntry m_aGenPo;
    bool m_bIsInitialized;

public:

    friend class PoOfstream;
    friend class PoIfstream;

    enum SDFPART { PROJECT, SOURCEFILE, DUMMY, RESOURCETYPE, GROUPID,
                    LOCALID, HELPID, PLATFORM, WIDTH, LANGUAGEID,
                    TEXT, HELPTEXT, QUICKHELPTEXT, TITLE, TIMESTAMP };
    enum TYPE { TTEXT=TEXT, TQUICKHELPTEXT=QUICKHELPTEXT, TTITLE=TITLE };
    enum Exception { INVALIDSDFLINE };

                    PoEntry();
                    PoEntry(const OString& rSDFLine,
                            const TYPE eType = TTEXT);
                    ~PoEntry();
                    //Default copy constructor and copy operator work well

    OString         getSourceFile() const;
    OString         getGroupId() const;
    OString         getLocalId() const;
    OString         getResourceType() const;
    TYPE            getType() const;
    OString         getUnTransStr() const;
    OString         getTransStr() const;
    bool            getFuzzy() const;
    OString         getKeyId() const;
    void            setUnTransStr(const OString& rUnTransStr);
    void            setTransStr(const OString& rTransStr);
    void            setFuzzy(const bool bFuzzy);

    static bool     IsInSameComp(const PoEntry& rPo1,const PoEntry& rPo2);

};

class PoHeader
{
private:

    GenPoEntry m_aGenPo;
    bool m_bIsInitialized;

public:

    friend class PoOfstream;
    friend class PoIfstream;

    enum Exception { NOLANG };

                    PoHeader();
                    PoHeader( const OString& rExtSrc );
                    PoHeader( std::ifstream& rOldPo );
                    ~PoHeader();
                    //Default copy constructor and copy operator work well

    OString         getLanguage() const;
};

class PoOfstream: private boost::noncopyable
{
private:

    std::ofstream   m_aOutPut;
    bool            m_bIsAfterHeader;

public:
            PoOfstream();
            ~PoOfstream();
    bool    isOpen() const  { return m_aOutPut.is_open(); }

    void    open(const OString& rFileName);
    void    close();
    void    writeHeader(const PoHeader& rHeader);
    void    writeEntry(const PoEntry& rPo);
};

class PoIfstream: private boost::noncopyable
{
private:

    std::ifstream   m_aInPut;
    bool            m_bIsAfterHeader;
    bool            m_bEof;

public:

    enum Exception { INVALIDENTRY, INVALIDHEADER };

            PoIfstream();
            ~PoIfstream();
    bool    isOpen() const  { return m_aInPut.is_open(); }
    bool    eof() const     { return m_bEof; }

    void    open(const OString& rFileName);
    void    close();
    void    readHeader(PoHeader& rHeader);
    void    readEntry(PoEntry& rPo);
};

#endif // _PO_INCLUDED

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */