Home | History | Annotate | Download | only in dicnode
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef LATINIME_DIC_NODE_STATE_OUTPUT_H
     18 #define LATINIME_DIC_NODE_STATE_OUTPUT_H
     19 
     20 #include <cstring> // for memcpy()
     21 #include <stdint.h>
     22 
     23 #include "defines.h"
     24 
     25 namespace latinime {
     26 
     27 class DicNodeStateOutput {
     28  public:
     29     DicNodeStateOutput() : mOutputtedLength(0) {
     30         init();
     31     }
     32 
     33     virtual ~DicNodeStateOutput() {}
     34 
     35     void init() {
     36         mOutputtedLength = 0;
     37         mWordBuf[0] = 0;
     38     }
     39 
     40     void init(const DicNodeStateOutput *const stateOutput) {
     41         memcpy(mWordBuf, stateOutput->mWordBuf,
     42                 stateOutput->mOutputtedLength * sizeof(mWordBuf[0]));
     43         mOutputtedLength = stateOutput->mOutputtedLength;
     44         if (mOutputtedLength < MAX_WORD_LENGTH) {
     45             mWordBuf[mOutputtedLength] = 0;
     46         }
     47     }
     48 
     49     void addSubword(const uint16_t additionalSubwordLength, const int *const additionalSubword) {
     50         if (additionalSubword) {
     51             memcpy(&mWordBuf[mOutputtedLength], additionalSubword,
     52                     additionalSubwordLength * sizeof(mWordBuf[0]));
     53             mOutputtedLength = static_cast<uint16_t>(mOutputtedLength + additionalSubwordLength);
     54             if (mOutputtedLength < MAX_WORD_LENGTH) {
     55                 mWordBuf[mOutputtedLength] = 0;
     56             }
     57         }
     58     }
     59 
     60     // TODO: Remove
     61     int getCodePointAt(const int id) const {
     62         return mWordBuf[id];
     63     }
     64 
     65     // TODO: Move to private
     66     int mWordBuf[MAX_WORD_LENGTH];
     67 
     68  private:
     69     // Caution!!!
     70     // Use a default copy constructor and an assign operator because shallow copies are ok
     71     // for this class
     72     uint16_t mOutputtedLength;
     73 };
     74 } // namespace latinime
     75 #endif // LATINIME_DIC_NODE_STATE_OUTPUT_H
     76