Commit 2577412d authored by Hiroshi Sumita's avatar Hiroshi Sumita
Browse files

Modify API of candidates().

This CL changes API only.
Internal behavior will be changed in another CL.

BUG=None
TEST=Run a test

Review URL: http://codereview.appspot.com/5437086
parent abf1fe97
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ libpyzy_built_h_sources = \
libpyzy_c_sources = \
	PyZyInputContext.cc \
	PyZyBopomofoContext.cc \
        PyZyCandidates.cc \
	PyZyConfig.cc \
	PyZyDatabase.cc \
	PyZyDoublePinyinContext.cc \
@@ -70,6 +71,7 @@ libpyzy_h_sources = \
	PyZyInputContext.h \
	PyZyBopomofo.h \
	PyZyBopomofoContext.h \
        PyZyCandidates.h \
	PyZyConfig.h \
	PyZyDatabase.h \
	PyZyDoublePinyinContext.h \

src/PyZyCandidates.cc

0 → 100644
+48 −0
Original line number Diff line number Diff line
/* vim:set et ts=4 sts=4:
 *
 * libpyzy - The Chinese PinYin and Bopomofo conversion library.
 *
 * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
 *
 * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */

#include "PyZyCandidates.h"

namespace PyZy {

ConcreteCandidates::~ConcreteCandidates () {
}

const Candidate & ConcreteCandidates::get (size_t index) const {
  return m_candidates[index];
}

const size_t ConcreteCandidates::size () const {
  // TODO(hsumita): replace it.
  // return m_size;
  return m_candidates.size ();
}

void ConcreteCandidates::clear() {
  m_candidates.clear ();
}

void ConcreteCandidates::push_back (const Candidate &candidate) {
  m_candidates.push_back (candidate);
}

}  // namespace PyZy

src/PyZyCandidates.h

0 → 100644
+47 −0
Original line number Diff line number Diff line
/* vim:set et ts=4 sts=4:
 *
 * libpyzy - The Chinese PinYin and Bopomofo conversion library.
 *
 * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
 *
 * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */
#ifndef __PYZY_CANDIDATES_H_
#define __PYZY_CANDIDATES_H_

#include "PyZyInputContext.h"

#include <string>
#include <vector>

namespace PyZy {

class ConcreteCandidates : public Candidates {
public:
  virtual ~ConcreteCandidates();
    virtual const Candidate & get (size_t index) const;
    virtual const size_t size () const;
    virtual void clear ();
    virtual void push_back (const Candidate &candidate);

private:
    std::vector<Candidate> m_candidates;
    size_t m_size;
};

}  // namespace PyZy

#endif  // __PYZY_CANDIDATES_H_
+8 −1
Original line number Diff line number Diff line
@@ -40,6 +40,13 @@ struct Candidate {
    CandidateType type;
};

class Candidates {
public:
    virtual ~Candidates () { }
    virtual const Candidate & get (size_t index) const = 0;
    virtual const size_t size () const = 0;
};

class InputContext {
public:
    virtual ~InputContext (void) { }
@@ -107,7 +114,7 @@ public:
    virtual const std::string & restText (void) const = 0;
    virtual const std::string & auxiliaryText (void) const = 0;
    // TODO(hsumita): Change return value to "class Candidates".
    virtual const std::vector<Candidate> & candidates () const = 0;
    virtual const Candidates & candidates () const = 0;
    virtual unsigned int cursor () const = 0;
    virtual unsigned int focusedCandidate () const = 0;
};
+4 −4
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include <string>
#include <vector>
#include "PyZyInputContext.h"
#include "PyZyCandidates.h"
#include "PyZyConfig.h"
#include "PyZyPinyinArray.h"
#include "PyZyPhraseEditor.h"
@@ -44,7 +45,6 @@ struct Preedit {
    }
};


class PhoneticContext : public InputContext {
public:
    PhoneticContext (Config & config, PhoneticContext::Observer *observer);
@@ -69,7 +69,7 @@ public:
    virtual const std::string & conversionText (void) const { return m_preedit_text.candidate_text; }
    virtual const std::string & restText (void) const { return m_preedit_text.rest_text; }
    virtual const std::string & auxiliaryText (void) const { return m_auxiliary_text; }
    virtual const std::vector<Candidate> & candidates () const { return m_candidates; }
    virtual const Candidates & candidates () const { return m_candidates; }
    virtual unsigned int cursor () const { return m_cursor; }
    virtual unsigned int focusedCandidate () const { return m_focused_candidate; }

@@ -120,8 +120,8 @@ protected:
    std::string                 m_selected_special_phrase;
    String                      m_text;
    Preedit                     m_preedit_text;
    std::vector<Candidate>      m_candidates;
    std::string                 m_auxiliary_text;
    ConcreteCandidates          m_candidates;

private:
    PhoneticContext::Observer  *m_observer;
Loading