Path: blob/master/src/jdk.accessibility/windows/native/jaccessinspector/MessageHistory.cpp
40957 views
/*1* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include <windows.h> // includes basic windows functionality26#include <iterator>27#include "MessageHistory.h"2829size_t MessageHistory::sm_MaxMessages = 1000;3031void MessageHistory::AddMessage(const char * message) {32if ( ( NULL == message ) || ( 0 == message [0] ) ) {33return;34}3536if ( m_Messages.size() >= sm_MaxMessages ) {37// Remove the oldest message38m_Messages.pop_front();39}4041m_Messages.push_back(std::string (message) );42m_CurrentPosition = m_Messages.end();43-- m_CurrentPosition;44}4546const char * MessageHistory::GetFirstMessage() {47if ( m_Messages.empty() ) {48return "";49}5051m_CurrentPosition = m_Messages.begin();52return (*m_CurrentPosition).c_str();53}5455const char * MessageHistory::GetPreviousMessage() {56if ( m_Messages.empty() ) {57return "";58}5960if ( m_CurrentPosition != m_Messages.begin() ) {61-- m_CurrentPosition;62}6364return (*m_CurrentPosition).c_str();65}6667const char * MessageHistory::GetNextMessage() {68if ( m_Messages.empty() ) {69return "";70}7172++ m_CurrentPosition;73if ( m_CurrentPosition == m_Messages.end() ) {74-- m_CurrentPosition;75}7677return (*m_CurrentPosition).c_str();78}7980const char * MessageHistory::GetLastMessage()81{82if ( m_Messages.empty() ) {83return "";84}8586m_CurrentPosition = m_Messages.end();87-- m_CurrentPosition;88return (*m_CurrentPosition).c_str();89}9091BOOL MessageHistory::IsFirstMessage() {92if ( m_Messages.empty() ) {93return FALSE;94}95if ( m_CurrentPosition == m_Messages.begin() ) {96return TRUE;97}98return FALSE;99}100101BOOL MessageHistory::IsLastMessage() {102if ( m_Messages.empty() ) {103return FALSE;104}105stringlist::const_iterator itTest = m_Messages.end();106-- itTest;107if ( itTest == m_CurrentPosition ) {108return TRUE;109}110return FALSE;111}112113size_t MessageHistory::GetMessageCount() {114size_t ret_val = m_Messages.size();115return ret_val;116}117118const char * MessageHistory::GetCurrentMessage() {119if ( m_Messages.empty() ) {120return "";121}122123return (*m_CurrentPosition).c_str();124}125126const char * MessageHistory::GetMessage(const size_t messageIndex) {127if ( m_Messages.empty() ) {128return "";129}130131if ( messageIndex >= m_Messages.size() ) {132return "";133}134135stringlist::const_iterator it = m_Messages.begin();136std::advance(it, messageIndex);137m_CurrentPosition = it;138139return (*it).c_str();140}141142size_t MessageHistory::GetCurrentMessageIndex() {143if ( m_Messages.empty() ) {144return 0;145}146147stringlist::const_iterator itBegin = m_Messages.begin();148size_t ret_val = std::distance(itBegin, m_CurrentPosition);149return ret_val;150}151152void MessageHistory::clear() {153m_Messages.clear();154}155156157