<commit_before>// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <string>
#include <vector>

#include "base/memory/scoped_ptr.h"
#include "base/rand_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/sessions/session_types.h"
#include "chrome/browser/sync/glue/synced_session_tracker.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace browser_sync {

typedef testing::Test SyncedSessionTrackerTest;

TEST_F(SyncedSessionTrackerTest, GetSession) {
  SyncedSessionTracker tracker;
  SyncedSession* session1 = tracker.GetSession("tag");
  SyncedSession* session2 = tracker.GetSession("tag2");
  ASSERT_EQ(session1, tracker.GetSession("tag"));
  ASSERT_NE(session1, session2);
  // Should clean up memory on it's own.
}

TEST_F(SyncedSessionTrackerTest, GetTabUnmapped) {
  SyncedSessionTracker tracker;
  SessionTab* tab = tracker.GetTab("tag", 0);
  ASSERT_EQ(tab, tracker.GetTab("tag", 0));
  // Should clean up memory on it's own.
}

TEST_F(SyncedSessionTrackerTest, PutWindowInSession) {
  SyncedSessionTracker tracker;
  tracker.PutWindowInSession("tag", 0);
  SyncedSession* session = tracker.GetSession("tag");
  ASSERT_EQ(1U, session->windows.size());
  // Should clean up memory on it's own.
}

TEST_F(SyncedSessionTrackerTest, PutTabInWindow) {
  SyncedSessionTracker tracker;
  tracker.PutWindowInSession("tag", 10);
  tracker.PutTabInWindow("tag", 10, 15, 0);  // win id 10, tab id 15, tab ind 0.
  SyncedSession* session = tracker.GetSession("tag");
  ASSERT_EQ(1U, session->windows.size());
  ASSERT_EQ(1U, session->windows[10]->tabs.size());
  ASSERT_EQ(tracker.GetTab("tag", 15), session->windows[10]->tabs[0]);
  // Should clean up memory on it's own.
}

TEST_F(SyncedSessionTrackerTest, LookupAllForeignSessions) {
  SyncedSessionTracker tracker;
  std::vector<const SyncedSession*> sessions;
  ASSERT_FALSE(tracker.LookupAllForeignSessions(&sessions));
  tracker.GetSession("tag1");
  tracker.GetSession("tag2");
  tracker.PutWindowInSession("tag1", 0);
  tracker.PutTabInWindow("tag1", 0, 15, 0);
  SessionTab* tab = tracker.GetTab("tag1", 15);
  ASSERT_TRUE(tab);
  tab->navigations.push_back(TabNavigation(
      0, GURL("valid_url"), GURL("referrer"),
      string16(ASCIIToUTF16("title")),
      std::string("state"), content::PageTransitionFromInt(0)));
  ASSERT_TRUE(tracker.LookupAllForeignSessions(&sessions));
  // Only the session with a valid window and tab gets returned.
  ASSERT_EQ(1U, sessions.size());
  ASSERT_EQ("tag1", sessions[0]->session_tag);
}

TEST_F(SyncedSessionTrackerTest, LookupSessionWindows) {
  SyncedSessionTracker tracker;
  std::vector<const SessionWindow*> windows;
  ASSERT_FALSE(tracker.LookupSessionWindows("tag1", &windows));
  tracker.GetSession("tag1");
  tracker.PutWindowInSession("tag1", 0);
  tracker.PutWindowInSession("tag1", 2);
  tracker.GetSession("tag2");
  tracker.PutWindowInSession("tag2", 0);
  tracker.PutWindowInSession("tag2", 2);
  ASSERT_TRUE(tracker.LookupSessionWindows("tag1", &windows));
  ASSERT_EQ(2U, windows.size());  // Only windows from tag1 session.
  ASSERT_NE((SessionWindow*)NULL, windows[0]);
  ASSERT_NE((SessionWindow*)NULL, windows[1]);
  ASSERT_NE(windows[1], windows[0]);
}

TEST_F(SyncedSessionTrackerTest, LookupSessionTab) {
  SyncedSessionTracker tracker;
  const SessionTab* tab;
  ASSERT_FALSE(tracker.LookupSessionTab("tag1", 5, &tab));
  tracker.GetSession("tag1");
  tracker.PutWindowInSession("tag1", 0);
  tracker.PutTabInWindow("tag1", 0, 5, 0);
  ASSERT_TRUE(tracker.LookupSessionTab("tag1", 5, &tab));
  ASSERT_NE((SessionTab*)NULL, tab);
}

TEST_F(SyncedSessionTrackerTest, Complex) {
  const std::string tag1 = "tag";
  const std::string tag2 = "tag2";
  const std::string tag3 = "tag3";
  SyncedSessionTracker tracker;
  std::vector<SessionTab*> tabs1, tabs2;
  SessionTab* temp_tab;
  ASSERT_TRUE(tracker.Empty());
  ASSERT_EQ(0U, tracker.num_synced_sessions());
  ASSERT_EQ(0U, tracker.num_synced_tabs(tag1));
  tabs1.push_back(tracker.GetTab(tag1, 0));
  tabs1.push_back(tracker.GetTab(tag1, 1));
  tabs1.push_back(tracker.GetTab(tag1, 2));
  ASSERT_EQ(3U, tracker.num_synced_tabs(tag1));
  ASSERT_EQ(0U, tracker.num_synced_sessions());
  temp_tab = tracker.GetTab(tag1, 0);  // Already created.
  ASSERT_EQ(3U, tracker.num_synced_tabs(tag1));
  ASSERT_EQ(0U, tracker.num_synced_sessions());
  ASSERT_EQ(tabs1[0], temp_tab);
  tabs2.push_back(tracker.GetTab(tag2, 0));
  ASSERT_EQ(1U, tracker.num_synced_tabs(tag2));
  ASSERT_EQ(0U, tracker.num_synced_sessions());
  ASSERT_FALSE(tracker.DeleteSession(tag3));

  SyncedSession* session = tracker.GetSession(tag1);
  SyncedSession* session2 = tracker.GetSession(tag2);
  SyncedSession* session3 = tracker.GetSession(tag3);
  ASSERT_EQ(3U, tracker.num_synced_sessions());

  ASSERT_TRUE(session);
  ASSERT_TRUE(session2);
  ASSERT_TRUE(session3);
  ASSERT_NE(session, session2);
  ASSERT_NE(session2, session3);
  ASSERT_TRUE(tracker.DeleteSession(tag3));
  ASSERT_EQ(2U, tracker.num_synced_sessions());

  tracker.PutWindowInSession(tag1, 0);      // Create a window.
  tracker.PutTabInWindow(tag1, 0, 2, 0);    // No longer unmapped.
  ASSERT_EQ(3U, tracker.num_synced_tabs(tag1));      // Has not changed.

  const SessionTab *tab_ptr;
  ASSERT_TRUE(tracker.LookupSessionTab(tag1, 0, &tab_ptr));
  ASSERT_EQ(tab_ptr, tabs1[0]);
  ASSERT_TRUE(tracker.LookupSessionTab(tag1, 2, &tab_ptr));
  ASSERT_EQ(tab_ptr, tabs1[2]);
  ASSERT_FALSE(tracker.LookupSessionTab(tag1, 3, &tab_ptr));
  ASSERT_EQ(static_cast<const SessionTab*>(NULL), tab_ptr);

  std::vector<const SessionWindow*> windows;
  ASSERT_TRUE(tracker.LookupSessionWindows(tag1, &windows));
  ASSERT_EQ(1U, windows.size());
  ASSERT_TRUE(tracker.LookupSessionWindows(tag2, &windows));
  ASSERT_EQ(0U, windows.size());

  // The sessions don't have valid tabs, lookup should not succeed.
  std::vector<const SyncedSession*> sessions;
  ASSERT_FALSE(tracker.LookupAllForeignSessions(&sessions));

  tracker.Clear();
  ASSERT_EQ(0U, tracker.num_synced_tabs(tag1));
  ASSERT_EQ(0U, tracker.num_synced_tabs(tag2));
  ASSERT_EQ(0U, tracker.num_synced_sessions());
}

TEST_F(SyncedSessionTrackerTest, ManyGetTabs) {
  SyncedSessionTracker tracker;
  ASSERT_TRUE(tracker.Empty());
  const int kMaxSessions = 10;
  const int kMaxTabs = 1000;
  const int kMaxAttempts = 10000;
  for (int j=0; j<kMaxSessions; ++j) {
    std::string tag = "tag" + j;
    for (int i=0; i<kMaxAttempts; ++i) {
      // More attempts than tabs means we'll sometimes get the same tabs,
      // sometimes have to allocate new tabs.
      int rand_tab_num = base::RandInt(0, kMaxTabs);
      SessionTab* tab = tracker.GetTab(tag, rand_tab_num);
      ASSERT_TRUE(tab);
    }
  }
}

TEST_F(SyncedSessionTrackerTest, SessionTracking) {
  SyncedSessionTracker tracker;
  ASSERT_TRUE(tracker.Empty());
  std::string tag1 = "tag1";
  std::string tag2 = "tag2";

  // Create some session information that is stale.
  SyncedSession* session1= tracker.GetSession(tag1);
  tracker.PutWindowInSession(tag1, 0);
  tracker.PutTabInWindow(tag1, 0, 0, 0);
  tracker.PutTabInWindow(tag1, 0, 1, 1);
  tracker.GetTab(tag1, 2)->window_id.set_id(0);  // Will be an unmapped tab.
  tracker.GetTab(tag1, 3)->window_id.set_id(0);  // Will be an unmapped tab.
  tracker.PutWindowInSession(tag1, 1);
  tracker.PutTabInWindow(tag1, 1, 4, 0);
  tracker.PutTabInWindow(tag1, 1, 5, 1);
  ASSERT_EQ(2U, session1->windows.size());
  ASSERT_EQ(2U, session1->windows[0]->tabs.size());
  ASSERT_EQ(2U, session1->windows[1]->tabs.size());
  ASSERT_EQ(6U, tracker.num_synced_tabs(tag1));

  // Create a session that should not be affected.
  SyncedSession* session2 = tracker.GetSession(tag2);
  tracker.PutWindowInSession(tag2, 2);
  tracker.PutTabInWindow(tag2, 2, 1, 0);
  ASSERT_EQ(1U, session2->windows.size());
  ASSERT_EQ(1U, session2->windows[2]->tabs.size());
  ASSERT_EQ(1U, tracker.num_synced_tabs(tag2));

  // Reset tracking and get the current windows/tabs.
  // We simulate moving a tab from one window to another, then closing the first
  // window (including it's one remaining tab), and opening a new tab on the
  // remaining window.
  tracker.GetTab(tag1, 6);  // New tab, arrived before meta node so unmapped.
  tracker.ResetSessionTracking(tag1);
  tracker.PutWindowInSession(tag1, 0);
  tracker.PutTabInWindow(tag1, 0, 0, 0);
  // Tab 1 is closed.
  tracker.PutTabInWindow(tag1, 0, 2, 1);  // No longer unmapped.
  // Tab 3 was unmapped and does not get used.
  tracker.PutTabInWindow(tag1, 0, 4, 2);  // Moved from window 1.
  // Window 1 was closed, along with tab 5.
  tracker.PutTabInWindow(tag1, 0, 6, 3);  // No longer unmapped.
  // Session 2 should not be affected.
  tracker.CleanupSession(tag1);

  // Verify that only those parts of the session not owned have been removed.
  ASSERT_EQ(1U, session1->windows.size());
  ASSERT_EQ(4U, session1->windows[0]->tabs.size());
  ASSERT_EQ(1U, session2->windows.size());
  ASSERT_EQ(1U, session2->windows[2]->tabs.size());
  ASSERT_EQ(2U, tracker.num_synced_sessions());
  ASSERT_EQ(4U, tracker.num_synced_tabs(tag1));
  ASSERT_EQ(1U, tracker.num_synced_tabs(tag2));

  // All memory should be properly deallocated by destructor for the
  // SyncedSessionTracker.
}

}  // namespace browser_sync
<commit_msg>Use base::StringPrintf to fix SyncedSessionTrackerTest.ManyGetTabs under AddressSanitizer Review URL: http://codereview.chromium.org/8492009<commit_after>// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <string>
#include <vector>

#include "base/memory/scoped_ptr.h"
#include "base/rand_util.h"
#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/sessions/session_types.h"
#include "chrome/browser/sync/glue/synced_session_tracker.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace browser_sync {

typedef testing::Test SyncedSessionTrackerTest;

TEST_F(SyncedSessionTrackerTest, GetSession) {
  SyncedSessionTracker tracker;
  SyncedSession* session1 = tracker.GetSession("tag");
  SyncedSession* session2 = tracker.GetSession("tag2");
  ASSERT_EQ(session1, tracker.GetSession("tag"));
  ASSERT_NE(session1, session2);
  // Should clean up memory on it's own.
}

TEST_F(SyncedSessionTrackerTest, GetTabUnmapped) {
  SyncedSessionTracker tracker;
  SessionTab* tab = tracker.GetTab("tag", 0);
  ASSERT_EQ(tab, tracker.GetTab("tag", 0));
  // Should clean up memory on it's own.
}

TEST_F(SyncedSessionTrackerTest, PutWindowInSession) {
  SyncedSessionTracker tracker;
  tracker.PutWindowInSession("tag", 0);
  SyncedSession* session = tracker.GetSession("tag");
  ASSERT_EQ(1U, session->windows.size());
  // Should clean up memory on it's own.
}

TEST_F(SyncedSessionTrackerTest, PutTabInWindow) {
  SyncedSessionTracker tracker;
  tracker.PutWindowInSession("tag", 10);
  tracker.PutTabInWindow("tag", 10, 15, 0);  // win id 10, tab id 15, tab ind 0.
  SyncedSession* session = tracker.GetSession("tag");
  ASSERT_EQ(1U, session->windows.size());
  ASSERT_EQ(1U, session->windows[10]->tabs.size());
  ASSERT_EQ(tracker.GetTab("tag", 15), session->windows[10]->tabs[0]);
  // Should clean up memory on it's own.
}

TEST_F(SyncedSessionTrackerTest, LookupAllForeignSessions) {
  SyncedSessionTracker tracker;
  std::vector<const SyncedSession*> sessions;
  ASSERT_FALSE(tracker.LookupAllForeignSessions(&sessions));
  tracker.GetSession("tag1");
  tracker.GetSession("tag2");
  tracker.PutWindowInSession("tag1", 0);
  tracker.PutTabInWindow("tag1", 0, 15, 0);
  SessionTab* tab = tracker.GetTab("tag1", 15);
  ASSERT_TRUE(tab);
  tab->navigations.push_back(TabNavigation(
      0, GURL("valid_url"), GURL("referrer"),
      string16(ASCIIToUTF16("title")),
      std::string("state"), content::PageTransitionFromInt(0)));
  ASSERT_TRUE(tracker.LookupAllForeignSessions(&sessions));
  // Only the session with a valid window and tab gets returned.
  ASSERT_EQ(1U, sessions.size());
  ASSERT_EQ("tag1", sessions[0]->session_tag);
}

TEST_F(SyncedSessionTrackerTest, LookupSessionWindows) {
  SyncedSessionTracker tracker;
  std::vector<const SessionWindow*> windows;
  ASSERT_FALSE(tracker.LookupSessionWindows("tag1", &windows));
  tracker.GetSession("tag1");
  tracker.PutWindowInSession("tag1", 0);
  tracker.PutWindowInSession("tag1", 2);
  tracker.GetSession("tag2");
  tracker.PutWindowInSession("tag2", 0);
  tracker.PutWindowInSession("tag2", 2);
  ASSERT_TRUE(tracker.LookupSessionWindows("tag1", &windows));
  ASSERT_EQ(2U, windows.size());  // Only windows from tag1 session.
  ASSERT_NE((SessionWindow*)NULL, windows[0]);
  ASSERT_NE((SessionWindow*)NULL, windows[1]);
  ASSERT_NE(windows[1], windows[0]);
}

TEST_F(SyncedSessionTrackerTest, LookupSessionTab) {
  SyncedSessionTracker tracker;
  const SessionTab* tab;
  ASSERT_FALSE(tracker.LookupSessionTab("tag1", 5, &tab));
  tracker.GetSession("tag1");
  tracker.PutWindowInSession("tag1", 0);
  tracker.PutTabInWindow("tag1", 0, 5, 0);
  ASSERT_TRUE(tracker.LookupSessionTab("tag1", 5, &tab));
  ASSERT_NE((SessionTab*)NULL, tab);
}

TEST_F(SyncedSessionTrackerTest, Complex) {
  const std::string tag1 = "tag";
  const std::string tag2 = "tag2";
  const std::string tag3 = "tag3";
  SyncedSessionTracker tracker;
  std::vector<SessionTab*> tabs1, tabs2;
  SessionTab* temp_tab;
  ASSERT_TRUE(tracker.Empty());
  ASSERT_EQ(0U, tracker.num_synced_sessions());
  ASSERT_EQ(0U, tracker.num_synced_tabs(tag1));
  tabs1.push_back(tracker.GetTab(tag1, 0));
  tabs1.push_back(tracker.GetTab(tag1, 1));
  tabs1.push_back(tracker.GetTab(tag1, 2));
  ASSERT_EQ(3U, tracker.num_synced_tabs(tag1));
  ASSERT_EQ(0U, tracker.num_synced_sessions());
  temp_tab = tracker.GetTab(tag1, 0);  // Already created.
  ASSERT_EQ(3U, tracker.num_synced_tabs(tag1));
  ASSERT_EQ(0U, tracker.num_synced_sessions());
  ASSERT_EQ(tabs1[0], temp_tab);
  tabs2.push_back(tracker.GetTab(tag2, 0));
  ASSERT_EQ(1U, tracker.num_synced_tabs(tag2));
  ASSERT_EQ(0U, tracker.num_synced_sessions());
  ASSERT_FALSE(tracker.DeleteSession(tag3));

  SyncedSession* session = tracker.GetSession(tag1);
  SyncedSession* session2 = tracker.GetSession(tag2);
  SyncedSession* session3 = tracker.GetSession(tag3);
  ASSERT_EQ(3U, tracker.num_synced_sessions());

  ASSERT_TRUE(session);
  ASSERT_TRUE(session2);
  ASSERT_TRUE(session3);
  ASSERT_NE(session, session2);
  ASSERT_NE(session2, session3);
  ASSERT_TRUE(tracker.DeleteSession(tag3));
  ASSERT_EQ(2U, tracker.num_synced_sessions());

  tracker.PutWindowInSession(tag1, 0);      // Create a window.
  tracker.PutTabInWindow(tag1, 0, 2, 0);    // No longer unmapped.
  ASSERT_EQ(3U, tracker.num_synced_tabs(tag1));      // Has not changed.

  const SessionTab *tab_ptr;
  ASSERT_TRUE(tracker.LookupSessionTab(tag1, 0, &tab_ptr));
  ASSERT_EQ(tab_ptr, tabs1[0]);
  ASSERT_TRUE(tracker.LookupSessionTab(tag1, 2, &tab_ptr));
  ASSERT_EQ(tab_ptr, tabs1[2]);
  ASSERT_FALSE(tracker.LookupSessionTab(tag1, 3, &tab_ptr));
  ASSERT_EQ(static_cast<const SessionTab*>(NULL), tab_ptr);

  std::vector<const SessionWindow*> windows;
  ASSERT_TRUE(tracker.LookupSessionWindows(tag1, &windows));
  ASSERT_EQ(1U, windows.size());
  ASSERT_TRUE(tracker.LookupSessionWindows(tag2, &windows));
  ASSERT_EQ(0U, windows.size());

  // The sessions don't have valid tabs, lookup should not succeed.
  std::vector<const SyncedSession*> sessions;
  ASSERT_FALSE(tracker.LookupAllForeignSessions(&sessions));

  tracker.Clear();
  ASSERT_EQ(0U, tracker.num_synced_tabs(tag1));
  ASSERT_EQ(0U, tracker.num_synced_tabs(tag2));
  ASSERT_EQ(0U, tracker.num_synced_sessions());
}

TEST_F(SyncedSessionTrackerTest, ManyGetTabs) {
  SyncedSessionTracker tracker;
  ASSERT_TRUE(tracker.Empty());
  const int kMaxSessions = 10;
  const int kMaxTabs = 1000;
  const int kMaxAttempts = 10000;
  for (int j=0; j<kMaxSessions; ++j) {
    std::string tag = base::StringPrintf("tag%d", j);
    for (int i=0; i<kMaxAttempts; ++i) {
      // More attempts than tabs means we'll sometimes get the same tabs,
      // sometimes have to allocate new tabs.
      int rand_tab_num = base::RandInt(0, kMaxTabs);
      SessionTab* tab = tracker.GetTab(tag, rand_tab_num);
      ASSERT_TRUE(tab);
    }
  }
}

TEST_F(SyncedSessionTrackerTest, SessionTracking) {
  SyncedSessionTracker tracker;
  ASSERT_TRUE(tracker.Empty());
  std::string tag1 = "tag1";
  std::string tag2 = "tag2";

  // Create some session information that is stale.
  SyncedSession* session1= tracker.GetSession(tag1);
  tracker.PutWindowInSession(tag1, 0);
  tracker.PutTabInWindow(tag1, 0, 0, 0);
  tracker.PutTabInWindow(tag1, 0, 1, 1);
  tracker.GetTab(tag1, 2)->window_id.set_id(0);  // Will be an unmapped tab.
  tracker.GetTab(tag1, 3)->window_id.set_id(0);  // Will be an unmapped tab.
  tracker.PutWindowInSession(tag1, 1);
  tracker.PutTabInWindow(tag1, 1, 4, 0);
  tracker.PutTabInWindow(tag1, 1, 5, 1);
  ASSERT_EQ(2U, session1->windows.size());
  ASSERT_EQ(2U, session1->windows[0]->tabs.size());
  ASSERT_EQ(2U, session1->windows[1]->tabs.size());
  ASSERT_EQ(6U, tracker.num_synced_tabs(tag1));

  // Create a session that should not be affected.
  SyncedSession* session2 = tracker.GetSession(tag2);
  tracker.PutWindowInSession(tag2, 2);
  tracker.PutTabInWindow(tag2, 2, 1, 0);
  ASSERT_EQ(1U, session2->windows.size());
  ASSERT_EQ(1U, session2->windows[2]->tabs.size());
  ASSERT_EQ(1U, tracker.num_synced_tabs(tag2));

  // Reset tracking and get the current windows/tabs.
  // We simulate moving a tab from one window to another, then closing the first
  // window (including it's one remaining tab), and opening a new tab on the
  // remaining window.
  tracker.GetTab(tag1, 6);  // New tab, arrived before meta node so unmapped.
  tracker.ResetSessionTracking(tag1);
  tracker.PutWindowInSession(tag1, 0);
  tracker.PutTabInWindow(tag1, 0, 0, 0);
  // Tab 1 is closed.
  tracker.PutTabInWindow(tag1, 0, 2, 1);  // No longer unmapped.
  // Tab 3 was unmapped and does not get used.
  tracker.PutTabInWindow(tag1, 0, 4, 2);  // Moved from window 1.
  // Window 1 was closed, along with tab 5.
  tracker.PutTabInWindow(tag1, 0, 6, 3);  // No longer unmapped.
  // Session 2 should not be affected.
  tracker.CleanupSession(tag1);

  // Verify that only those parts of the session not owned have been removed.
  ASSERT_EQ(1U, session1->windows.size());
  ASSERT_EQ(4U, session1->windows[0]->tabs.size());
  ASSERT_EQ(1U, session2->windows.size());
  ASSERT_EQ(1U, session2->windows[2]->tabs.size());
  ASSERT_EQ(2U, tracker.num_synced_sessions());
  ASSERT_EQ(4U, tracker.num_synced_tabs(tag1));
  ASSERT_EQ(1U, tracker.num_synced_tabs(tag2));

  // All memory should be properly deallocated by destructor for the
  // SyncedSessionTracker.
}

}  // namespace browser_sync
<|endoftext|>


<commit_before>// @(#)root/meta:$Name:  $:$Id: GenericClassInfo.cxx,v 1.1 2002/05/09 20:53:21 brun Exp $
// Author: Philippe Canal 08/05/2002

/*************************************************************************
 * Copyright (C) 1995-2002, Rene Brun, Fons Rademakers and al.           *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "Rtypes.h"
#include "TNamed.h"
#include "TClass.h"

namespace ROOT {

   const InitBehavior *DefineBehavior(void * /*parent_type*/,
                                      void * /*actual_type*/)
   {

      // This function loads the default behavior for the
      // loading of classes.

      static DefaultInitBehavior theDefault;
      return &theDefault;
   }

   GenericClassInfo::GenericClassInfo(const char *fullClassname,
                                      const char *declFileName, Int_t declFileLine,
                                      const type_info &info, const InitBehavior  *action,
                                      void *showmembers, VoidFuncPtr_t dictionary,
                                      IsAFunc_t isa, Int_t pragmabits)
      : fAction(action), fClassName(fullClassname),
        fDeclFileName(declFileName), fDeclFileLine(declFileLine),
        fDictionary(dictionary), fInfo(info), fIsA(isa), fShowMembers(showmembers),
        fVersion(1)
   {
      Init(pragmabits);
   }

   GenericClassInfo::GenericClassInfo(const char *fullClassname, Int_t version,
                                      const char *declFileName, Int_t declFileLine,
                                      const type_info &info, const InitBehavior  *action,
                                      void* showmembers,  VoidFuncPtr_t dictionary,
                                      IsAFunc_t isa, Int_t pragmabits)
      : fAction(action), fClassName(fullClassname),
        fDeclFileName(declFileName), fDeclFileLine(declFileLine),
        fDictionary(dictionary), fInfo(info), fIsA(isa), fShowMembers(showmembers),
        fVersion(version)
   {
      Init(pragmabits);
   }

   GenericClassInfo::GenericClassInfo(const char *fullClassname, Int_t version,
                                      const char *declFileName, Int_t declFileLine,
                                      const type_info &info, const InitBehavior  *action,
                                      void* showmembers,  VoidFuncPtr_t dictionary,
                                      Int_t pragmabits)
      : fAction(action), fClassName(fullClassname),
        fDeclFileName(declFileName), fDeclFileLine(declFileLine),
        fDictionary(dictionary), fInfo(info), fIsA(0), fShowMembers(showmembers),
        fVersion(version)
   {
      Init(pragmabits);
   }

   GenericClassInfo::GenericClassInfo(const char *fullClassname, Int_t version,
                                      const char *declFileName, Int_t declFileLine,
                                      const type_info &info, const InitBehavior  *action,
                                      VoidFuncPtr_t dictionary,
                                      Int_t pragmabits)
      : fAction(action), fClassName(fullClassname),
        fDeclFileName(declFileName), fDeclFileLine(declFileLine),
        fDictionary(dictionary), fInfo(info), fIsA(0), fShowMembers(0),
        fVersion(version)
   {
      Init(pragmabits);
   }

   void GenericClassInfo::Init(Int_t pragmabits)
   {
      if (!fAction) return;
      GetAction().Register(fClassName,
                           fVersion,
                           fInfo, // typeid(RootClass),
                           fDictionary,
                           pragmabits);
   }

   GenericClassInfo::~GenericClassInfo()
   {
      if (fAction) GetAction().Unregister(GetClassName());
   }

   const InitBehavior &GenericClassInfo::GetAction() const
   {
      return *fAction;
   }

   TClass *GenericClassInfo::GetClass()
   {
      if (!fClass && fAction) {
         fClass = GetAction().CreateClass(GetClassName(),
                                          GetVersion(),
                                          GetInfo(),
                                          GetIsA(),
                                          (ShowMembersFunc_t)GetShowMembers(),
                                          GetDeclFileName(),
                                          GetImplFileName(),
                                          GetDeclFileLine(),
                                          GetImplFileLine());
      }
      return fClass;
   }

   const char *GenericClassInfo::GetClassName() const
   {
      return fClassName;
   }

   const type_info &GenericClassInfo::GetInfo() const
   {
      return fInfo;
   }

   void *GenericClassInfo::GetShowMembers() const
   {
      return fShowMembers;
   }

   void GenericClassInfo::SetFromTemplate()
   {
      TNamed *info = ROOT::RegisterClassTemplate(GetClassName(), 0, 0);
      if (info) SetImplFile(info->GetTitle(), info->GetUniqueID());
   }

   Int_t GenericClassInfo::SetImplFile(const char *file, Int_t line)
   {
      fImplFileName = file;
      fImplFileLine = line;
      if (fClass) fClass->AddImplFile(file,line);
      return 0;
   }

   Short_t GenericClassInfo::SetVersion(Short_t version)
   {
      ROOT::ResetClassVersion(fClass, GetClassName(),version);
      fVersion = version;
      return version;
   }

   const char *GenericClassInfo::GetDeclFileName() const
   {
      return fDeclFileName;
   }

   Int_t GenericClassInfo::GetDeclFileLine() const
   {
      return fDeclFileLine;
   }

   const char *GenericClassInfo::GetImplFileName()
   {
      if (!fImplFileName) SetFromTemplate();
      return fImplFileName;
   }

   Int_t GenericClassInfo::GetImplFileLine()
   {
      if (!fImplFileLine) SetFromTemplate();
      return fImplFileLine;
   }

   Int_t GenericClassInfo::GetVersion() const
   {
      return fVersion;
   }

   TClass *GenericClassInfo::IsA(const void *obj)
   {
      return (GetIsA())(obj);
   }

   IsAFunc_t GenericClassInfo::GetIsA() const
   {
      return fIsA;
   }

}
<commit_msg>In the GenericClassInfo destructor, return immediatly if gROOT is null. This case happens when the TROOT destructor itself is called. Without this protection, most programs crashed at the end.<commit_after>// @(#)root/meta:$Name:  $:$Id: GenericClassInfo.cxx,v 1.2 2002/05/09 22:57:37 rdm Exp $
// Author: Philippe Canal 08/05/2002

/*************************************************************************
 * Copyright (C) 1995-2002, Rene Brun, Fons Rademakers and al.           *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TROOT.h"
#include "TClass.h"

namespace ROOT {

   const InitBehavior *DefineBehavior(void * /*parent_type*/,
                                      void * /*actual_type*/)
   {

      // This function loads the default behavior for the
      // loading of classes.

      static DefaultInitBehavior theDefault;
      return &theDefault;
   }

   GenericClassInfo::GenericClassInfo(const char *fullClassname,
                                      const char *declFileName, Int_t declFileLine,
                                      const type_info &info, const InitBehavior  *action,
                                      void *showmembers, VoidFuncPtr_t dictionary,
                                      IsAFunc_t isa, Int_t pragmabits)
      : fAction(action), fClassName(fullClassname),
        fDeclFileName(declFileName), fDeclFileLine(declFileLine),
        fDictionary(dictionary), fInfo(info), fIsA(isa), fShowMembers(showmembers),
        fVersion(1)
   {
      Init(pragmabits);
   }

   GenericClassInfo::GenericClassInfo(const char *fullClassname, Int_t version,
                                      const char *declFileName, Int_t declFileLine,
                                      const type_info &info, const InitBehavior  *action,
                                      void* showmembers,  VoidFuncPtr_t dictionary,
                                      IsAFunc_t isa, Int_t pragmabits)
      : fAction(action), fClassName(fullClassname),
        fDeclFileName(declFileName), fDeclFileLine(declFileLine),
        fDictionary(dictionary), fInfo(info), fIsA(isa), fShowMembers(showmembers),
        fVersion(version)
   {
      Init(pragmabits);
   }

   GenericClassInfo::GenericClassInfo(const char *fullClassname, Int_t version,
                                      const char *declFileName, Int_t declFileLine,
                                      const type_info &info, const InitBehavior  *action,
                                      void* showmembers,  VoidFuncPtr_t dictionary,
                                      Int_t pragmabits)
      : fAction(action), fClassName(fullClassname),
        fDeclFileName(declFileName), fDeclFileLine(declFileLine),
        fDictionary(dictionary), fInfo(info), fIsA(0), fShowMembers(showmembers),
        fVersion(version)
   {
      Init(pragmabits);
   }

   GenericClassInfo::GenericClassInfo(const char *fullClassname, Int_t version,
                                      const char *declFileName, Int_t declFileLine,
                                      const type_info &info, const InitBehavior  *action,
                                      VoidFuncPtr_t dictionary,
                                      Int_t pragmabits)
      : fAction(action), fClassName(fullClassname),
        fDeclFileName(declFileName), fDeclFileLine(declFileLine),
        fDictionary(dictionary), fInfo(info), fIsA(0), fShowMembers(0),
        fVersion(version)
   {
      Init(pragmabits);
   }

   void GenericClassInfo::Init(Int_t pragmabits)
   {
      if (!fAction) return;
      GetAction().Register(fClassName,
                           fVersion,
                           fInfo, // typeid(RootClass),
                           fDictionary,
                           pragmabits);
   }

   GenericClassInfo::~GenericClassInfo()
   {
      if (!gROOT) return;
      if (fAction) GetAction().Unregister(GetClassName());
   }

   const InitBehavior &GenericClassInfo::GetAction() const
   {
      return *fAction;
   }

   TClass *GenericClassInfo::GetClass()
   {
      if (!fClass && fAction) {
         fClass = GetAction().CreateClass(GetClassName(),
                                          GetVersion(),
                                          GetInfo(),
                                          GetIsA(),
                                          (ShowMembersFunc_t)GetShowMembers(),
                                          GetDeclFileName(),
                                          GetImplFileName(),
                                          GetDeclFileLine(),
                                          GetImplFileLine());
      }
      return fClass;
   }

   const char *GenericClassInfo::GetClassName() const
   {
      return fClassName;
   }

   const type_info &GenericClassInfo::GetInfo() const
   {
      return fInfo;
   }

   void *GenericClassInfo::GetShowMembers() const
   {
      return fShowMembers;
   }

   void GenericClassInfo::SetFromTemplate()
   {
      TNamed *info = ROOT::RegisterClassTemplate(GetClassName(), 0, 0);
      if (info) SetImplFile(info->GetTitle(), info->GetUniqueID());
   }

   Int_t GenericClassInfo::SetImplFile(const char *file, Int_t line)
   {
      fImplFileName = file;
      fImplFileLine = line;
      if (fClass) fClass->AddImplFile(file,line);
      return 0;
   }

   Short_t GenericClassInfo::SetVersion(Short_t version)
   {
      ROOT::ResetClassVersion(fClass, GetClassName(),version);
      fVersion = version;
      return version;
   }

   const char *GenericClassInfo::GetDeclFileName() const
   {
      return fDeclFileName;
   }

   Int_t GenericClassInfo::GetDeclFileLine() const
   {
      return fDeclFileLine;
   }

   const char *GenericClassInfo::GetImplFileName()
   {
      if (!fImplFileName) SetFromTemplate();
      return fImplFileName;
   }

   Int_t GenericClassInfo::GetImplFileLine()
   {
      if (!fImplFileLine) SetFromTemplate();
      return fImplFileLine;
   }

   Int_t GenericClassInfo::GetVersion() const
   {
      return fVersion;
   }

   TClass *GenericClassInfo::IsA(const void *obj)
   {
      return (GetIsA())(obj);
   }

   IsAFunc_t GenericClassInfo::GetIsA() const
   {
      return fIsA;
   }

}
<|endoftext|>


<commit_before>// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/webui/chromeos/login/core_oobe_handler.h"

#include "base/values.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/chromeos/accessibility_util.h"
#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"

namespace {

// JS API callbacks names.
const char kJsApiScreenStateInitialize[] = "screenStateInitialize";
const char kJsApiToggleAccessibility[] = "toggleAccessibility";

}  // namespace

namespace chromeos {

// Note that show_oobe_ui_ defaults to false because WizardController assumes
// OOBE UI is not visible by default.
CoreOobeHandler::CoreOobeHandler(OobeUI* oobe_ui)
    : oobe_ui_(oobe_ui),
      show_oobe_ui_(false),
      version_info_updater_(this) {
}

CoreOobeHandler::~CoreOobeHandler() {
}

void CoreOobeHandler::GetLocalizedStrings(
    base::DictionaryValue* localized_strings) {
  localized_strings->SetString(
      "productName", l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
}

void CoreOobeHandler::Initialize() {
  UpdateOobeUIVisibility();
#if defined(OFFICIAL_BUILD)
  version_info_updater_.StartUpdate(true);
#else
  version_info_updater_.StartUpdate(false);
#endif
}

void CoreOobeHandler::RegisterMessages() {
  web_ui_->RegisterMessageCallback(kJsApiToggleAccessibility,
      NewCallback(this, &CoreOobeHandler::OnToggleAccessibility));
  web_ui_->RegisterMessageCallback(kJsApiScreenStateInitialize,
      NewCallback(this, &CoreOobeHandler::OnInitialized));
}

void CoreOobeHandler::OnInitialized(const base::ListValue* args) {
  oobe_ui_->InitializeHandlers();
}

void CoreOobeHandler::OnToggleAccessibility(const base::ListValue* args) {
  accessibility::ToggleAccessibility(web_ui_);
}

void CoreOobeHandler::ShowOobeUI(bool show) {
  if (show == show_oobe_ui_)
    return;

  show_oobe_ui_ = show;

  if (page_is_ready())
    UpdateOobeUIVisibility();
}

void CoreOobeHandler::UpdateOobeUIVisibility() {
  base::FundamentalValue showValue(show_oobe_ui_);
  web_ui_->CallJavascriptFunction("cr.ui.Oobe.showOobeUI", showValue);
}

void CoreOobeHandler::OnOSVersionLabelTextUpdated(
    const std::string& os_version_label_text) {
  UpdateLabel("version", os_version_label_text);
}

void CoreOobeHandler::OnBootTimesLabelTextUpdated(
    const std::string& boot_times_label_text) {
  UpdateLabel("boot-times", boot_times_label_text);
}

void CoreOobeHandler::UpdateLabel(const std::string& id,
                                  const std::string& text) {
  base::StringValue id_value(UTF8ToUTF16(id));
  base::StringValue text_value(UTF8ToUTF16(text));
  web_ui_->CallJavascriptFunction("cr.ui.Oobe.setLabelText",
                                  id_value,
                                  text_value);
}

}  // namespace chromeos
<commit_msg>Add a title to the OOBE screen so that is doesn't say 'unknown'<commit_after>// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/webui/chromeos/login/core_oobe_handler.h"

#include "base/values.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/chromeos/accessibility_util.h"
#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"

namespace {

// JS API callbacks names.
const char kJsApiScreenStateInitialize[] = "screenStateInitialize";
const char kJsApiToggleAccessibility[] = "toggleAccessibility";

}  // namespace

namespace chromeos {

// Note that show_oobe_ui_ defaults to false because WizardController assumes
// OOBE UI is not visible by default.
CoreOobeHandler::CoreOobeHandler(OobeUI* oobe_ui)
    : oobe_ui_(oobe_ui),
      show_oobe_ui_(false),
      version_info_updater_(this) {
}

CoreOobeHandler::~CoreOobeHandler() {
}

void CoreOobeHandler::GetLocalizedStrings(
    base::DictionaryValue* localized_strings) {
  localized_strings->SetString(
      "title", l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
  localized_strings->SetString(
      "productName", l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
}

void CoreOobeHandler::Initialize() {
  UpdateOobeUIVisibility();
#if defined(OFFICIAL_BUILD)
  version_info_updater_.StartUpdate(true);
#else
  version_info_updater_.StartUpdate(false);
#endif
}

void CoreOobeHandler::RegisterMessages() {
  web_ui_->RegisterMessageCallback(kJsApiToggleAccessibility,
      NewCallback(this, &CoreOobeHandler::OnToggleAccessibility));
  web_ui_->RegisterMessageCallback(kJsApiScreenStateInitialize,
      NewCallback(this, &CoreOobeHandler::OnInitialized));
}

void CoreOobeHandler::OnInitialized(const base::ListValue* args) {
  oobe_ui_->InitializeHandlers();
}

void CoreOobeHandler::OnToggleAccessibility(const base::ListValue* args) {
  accessibility::ToggleAccessibility(web_ui_);
}

void CoreOobeHandler::ShowOobeUI(bool show) {
  if (show == show_oobe_ui_)
    return;

  show_oobe_ui_ = show;

  if (page_is_ready())
    UpdateOobeUIVisibility();
}

void CoreOobeHandler::UpdateOobeUIVisibility() {
  base::FundamentalValue showValue(show_oobe_ui_);
  web_ui_->CallJavascriptFunction("cr.ui.Oobe.showOobeUI", showValue);
}

void CoreOobeHandler::OnOSVersionLabelTextUpdated(
    const std::string& os_version_label_text) {
  UpdateLabel("version", os_version_label_text);
}

void CoreOobeHandler::OnBootTimesLabelTextUpdated(
    const std::string& boot_times_label_text) {
  UpdateLabel("boot-times", boot_times_label_text);
}

void CoreOobeHandler::UpdateLabel(const std::string& id,
                                  const std::string& text) {
  base::StringValue id_value(UTF8ToUTF16(id));
  base::StringValue text_value(UTF8ToUTF16(text));
  web_ui_->CallJavascriptFunction("cr.ui.Oobe.setLabelText",
                                  id_value,
                                  text_value);
}

}  // namespace chromeos
<|endoftext|>


<commit_before>#ifndef COFFEE_MILL_COMMON_DEFERED_READER_HPP
#define COFFEE_MILL_COMMON_DEFERED_READER_HPP
#include <mill/common/Trajectory.hpp>
#include <string_view>
#include <optional>
#include <iterator>
#include <cstddef>

namespace mill
{

class DeferedReaderBase;

class ReaderIterator
{
  public:
    using iterator_category = std::input_iterator_tag;
    using difference_type   = std::ptrdiff_t;
    using value_type        = Snapshot;
    using reference         = value_type&;
    using pointer           = value_type*;

  public:
    explicit ReaderIterator(DeferedReaderBase& reader)
        : current_(std::nullopt), reader_(std::addressof(reader))
    {}

    const value_type& operator* () const
    {
        if(!current_) {current_ = reader_->read_frame();}
        return *current_;
    }
    const value_type* operator->() const
    {
        if(!current_) {current_ = reader_->read_frame();}
        return std::addressof(*current_);
    }

    ReaderIterator& operator++()
    {
        current_ = reader_->read_frame();
        return *this;
    }
    ReaderIterator  operator++(int)
    {
        current_ = reader_->read_frame();
        return *this;
    }

    bool             is_eof()    const noexcept {return reader_->is_eof();}
    std::size_t      current()   const noexcept {return reader_->current();}
    std::string_view file_name() const noexcept {return reader_->file_name();}

  private:
    std::optional<value_type> current_;
    DeferedReaderBase*        reader_;
};

inline bool operator==(const ReaderIterator& lhs, const ReaderIterator& rhs)
{
    return std::make_tuple(lhs->is_eof(), lhs->current(), lhs->file_name()) ==
           std::make_tuple(lhs->is_eof(), lhs->current(), lhs->file_name());
}
inline bool operator!=(const ReaderIterator& lhs, const ReaderIterator& rhs)
{
    return !(lhs == rhs);
}

class DeferedReaderBase
{
  public:
    using trajectory_type = Trajectory;
    using snapshot_type   = Snapshot;
    using attribute_container_type = trajectory_type::attribute_container_type;

  public:

    attribute_container_type read_header()                     = 0;
    trajectory_type          read()                            = 0;
    snapshot_type            read_frame()                      = 0;
    snapshot_type            read_frame(const std::size_t idx) = 0;

    bool             is_eof()    const noexcept = 0;
    std::size_t      current()   const noexcept = 0;
    std::string_view file_name() const noexcept = 0;
};

} // mill
#endif// COFFEE_MILL_COMMON_DEFERED_READER_HPP
<commit_msg>:sparkles: add ReaderIteratorSentinel<commit_after>#ifndef COFFEE_MILL_COMMON_DEFERED_READER_HPP
#define COFFEE_MILL_COMMON_DEFERED_READER_HPP
#include <mill/common/Trajectory.hpp>
#include <string_view>
#include <optional>
#include <iterator>
#include <cstddef>

namespace mill
{

class ReaderIterator;
class ReaderIteratorSentinel;

class DeferedReaderBase
{
  public:
    using trajectory_type = Trajectory;
    using snapshot_type   = Snapshot;
    using attribute_container_type = trajectory_type::attribute_container_type;

  public:

    virtual ~DeferedReaderBase() = default;

    virtual attribute_container_type read_header()                     = 0;
    virtual trajectory_type          read()                            = 0;
    virtual snapshot_type            read_frame()                      = 0;
    virtual snapshot_type            read_frame(const std::size_t idx) = 0;

    ReaderIterator         begin();
    ReaderIteratorSentinel end();

    virtual bool             is_eof()    const noexcept = 0;
    virtual std::size_t      current()   const noexcept = 0;
    virtual std::string_view file_name() const noexcept = 0;
};

class ReaderIterator
{
  public:
    using iterator_category = std::input_iterator_tag;
    using difference_type   = std::ptrdiff_t;
    using value_type        = Snapshot;
    using reference         = value_type&;
    using pointer           = value_type*;

  public:
    explicit ReaderIterator(DeferedReaderBase& reader)
        : current_(std::nullopt), reader_(std::addressof(reader))
    {}

    value_type& operator*()
    {
        if(!current_) {current_ = reader_->read_frame();}
        return *current_;
    }
    value_type* operator->()
    {
        if(!current_) {current_ = reader_->read_frame();}
        return std::addressof(*current_);
    }

    ReaderIterator& operator++()
    {
        current_ = reader_->read_frame();
        return *this;
    }
    ReaderIterator  operator++(int)
    {
        current_ = reader_->read_frame();
        return *this;
    }

    bool             is_eof()    const noexcept {return reader_->is_eof();}
    std::size_t      current()   const noexcept {return reader_->current();}
    std::string_view file_name() const noexcept {return reader_->file_name();}

  private:
    std::optional<value_type> current_;
    DeferedReaderBase*        reader_;
};

inline bool operator==(const ReaderIterator& lhs, const ReaderIterator& rhs)
{
    return std::make_tuple(lhs.is_eof(), lhs.current(), lhs.file_name()) ==
           std::make_tuple(rhs.is_eof(), rhs.current(), rhs.file_name());
}
inline bool operator!=(const ReaderIterator& lhs, const ReaderIterator& rhs)
{
    return !(lhs == rhs);
}

class ReaderIteratorSentinel
{
  public:
    using iterator_category = std::input_iterator_tag;
    using difference_type   = std::ptrdiff_t;
    using value_type        = Snapshot;
    using reference         = value_type&;
    using pointer           = value_type*;

  public:
    explicit ReaderIteratorSentinel(DeferedReaderBase& reader)
        : file_name_(reader.file_name())
    {}

    bool             is_eof()    const noexcept {return true;}
    std::string_view file_name() const noexcept {return file_name_;}

  private:
    std::string_view file_name_;
};

inline bool operator==(
        const ReaderIteratorSentinel& lhs, const ReaderIteratorSentinel& rhs)
{
    return lhs.file_name() == rhs.file_name();
}
inline bool operator!=(
        const ReaderIteratorSentinel& lhs, const ReaderIteratorSentinel& rhs)
{
    return !(lhs == rhs);
}

inline bool operator==(const ReaderIterator& lhs, const ReaderIteratorSentinel& rhs)
{
    return lhs.is_eof() && (lhs.file_name() == rhs.file_name());
}
inline bool operator==(const ReaderIteratorSentinel& lhs, const ReaderIterator& rhs)
{
    return rhs.is_eof() && (lhs.file_name() == rhs.file_name());
}

inline ReaderIterator DeferedReaderBase::begin()
{
    return ReaderIterator(*this);
}
inline ReaderIteratorSentinel DeferedReaderBase::end()
{
    return ReaderIteratorSentinel(*this);
}

} // mill
#endif// COFFEE_MILL_COMMON_DEFERED_READER_HPP
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: parametricpolypolygonfactory.cxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: kz $ $Date: 2006-12-13 15:43:25 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    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
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_slideshow.hxx"

#include <canvas/debug.hxx>

#include <com/sun/star/animations/TransitionType.hpp>
#include <com/sun/star/animations/TransitionSubType.hpp>

#include "parametricpolypolygonfactory.hxx"
#include "barwipepolypolygon.hxx"
#include "boxwipe.hxx"
#include "fourboxwipe.hxx"
#include "barndoorwipe.hxx"
#include "doublediamondwipe.hxx"
#include "veewipe.hxx"
#include "iriswipe.hxx"
#include "ellipsewipe.hxx"
#include "checkerboardwipe.hxx"
#include "randomwipe.hxx"
#include "waterfallwipe.hxx"
#include "clockwipe.hxx"
#include "fanwipe.hxx"
#include "pinwheelwipe.hxx"
#include "snakewipe.hxx"
#include "spiralwipe.hxx"
#include "sweepwipe.hxx"
#include "figurewipe.hxx"
#include "zigzagwipe.hxx"

using namespace ::com::sun::star;

namespace slideshow
{
    namespace internal
    {
        ParametricPolyPolygonSharedPtr
        ParametricPolyPolygonFactory::createClipPolyPolygon(
            sal_Int16 nType, sal_Int16 nSubType )
        {
            using namespace ::com::sun::star::animations::TransitionType;
            using namespace ::com::sun::star::animations::TransitionSubType;

            switch (nType)
            {
            case BARWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new BarWipePolyPolygon );
            case BLINDSWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new BarWipePolyPolygon( 6 ) );
            case BOXWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new BoxWipe( nSubType == LEFTCENTER ||
                                 nSubType == TOPCENTER ||
                                 nSubType == RIGHTCENTER||
                                 nSubType == BOTTOMCENTER ) );
            case FOURBOXWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new FourBoxWipe( nSubType == CORNERSOUT ) );
            case BARNDOORWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new BarnDoorWipe );
            case DIAGONALWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new BarWipePolyPolygon );
            case VEEWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new VeeWipe );
            case IRISWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new IrisWipe );
            case ELLIPSEWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new EllipseWipe(nSubType) );
            case CHECKERBOARDWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new CheckerBoardWipe );
            case RANDOMBARWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new RandomWipe( 128, true /* bars */ ) );
            case DISSOLVE:
                return ParametricPolyPolygonSharedPtr(
                    new RandomWipe( 16 * 16, // for now until dxcanvas is faster
//                                     64 * 64 /* elements */,
                                    false /* dissolve */ ) );
            case WATERFALLWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new WaterfallWipe(
                        128,
                        // flipOnYAxis:
                        nSubType == VERTICALRIGHT ||
                        nSubType == HORIZONTALLEFT ) );
            case CLOCKWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new ClockWipe );
            case FANWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new FanWipe( // center:
                                 nSubType == CENTERTOP ||
                                 nSubType == CENTERRIGHT ) );
            case PINWHEELWIPE: {
                sal_Int32 blades;
                switch (nSubType) {
                case ONEBLADE:
                    blades = 1;
                    break;
                case THREEBLADE:
                    blades = 3;
                    break;
                case FOURBLADE:
                    blades = 4;
                    break;
                case EIGHTBLADE:
                    blades = 8;
                    break;
                default:
                    blades = 2;
                    break;
                }
                return ParametricPolyPolygonSharedPtr(
                    new PinWheelWipe( blades ) );
            }
            case SNAKEWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new SnakeWipe(
                        // elements:
                        64 * 64,
                        // diagonal:
                        nSubType == TOPLEFTDIAGONAL ||
                        nSubType == TOPRIGHTDIAGONAL ||
                        nSubType == BOTTOMRIGHTDIAGONAL ||
                        nSubType == BOTTOMLEFTDIAGONAL,
                        // flipOnYAxis:
                        nSubType == TOPLEFTVERTICAL ||
                        nSubType == TOPRIGHTDIAGONAL ||
                        nSubType == BOTTOMLEFTDIAGONAL
                        ) );
            case PARALLELSNAKESWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new ParallelSnakesWipe(
                        // elements:
                        64 * 64,
                        // diagonal:
                        nSubType == DIAGONALBOTTOMLEFTOPPOSITE ||
                        nSubType == DIAGONALTOPLEFTOPPOSITE,
                        // flipOnYAxis:
                        nSubType == VERTICALBOTTOMLEFTOPPOSITE ||
                        nSubType == HORIZONTALTOPLEFTOPPOSITE ||
                        nSubType == DIAGONALTOPLEFTOPPOSITE,
                        // opposite:
                        nSubType == VERTICALTOPLEFTOPPOSITE ||
                        nSubType == VERTICALBOTTOMLEFTOPPOSITE ||
                        nSubType == HORIZONTALTOPLEFTOPPOSITE ||
                        nSubType == HORIZONTALTOPRIGHTOPPOSITE ||
                        nSubType == DIAGONALBOTTOMLEFTOPPOSITE ||
                        nSubType == DIAGONALTOPLEFTOPPOSITE
                        ) );
            case SPIRALWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new SpiralWipe(
                        // elements:
                        64 * 64,
                        // flipOnYAxis:
                        nSubType == TOPLEFTCOUNTERCLOCKWISE ||
                        nSubType == TOPRIGHTCOUNTERCLOCKWISE ||
                        nSubType == BOTTOMRIGHTCOUNTERCLOCKWISE ||
                        nSubType == BOTTOMLEFTCOUNTERCLOCKWISE ) );
            case BOXSNAKESWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new BoxSnakesWipe(
                        // elements:
                        64 * 64,
                        // fourBox:
                        nSubType == FOURBOXVERTICAL ||
                        nSubType == FOURBOXHORIZONTAL ) );
            case SINGLESWEEPWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new SweepWipe(
                        // center:
                        nSubType == CLOCKWISETOP ||
                        nSubType == CLOCKWISERIGHT ||
                        nSubType == CLOCKWISEBOTTOM ||
                        nSubType == CLOCKWISELEFT,
                        // single:
                        true,
                        // oppositeVertical:
                        false,
                        // flipOnYAxis:
                        nSubType == COUNTERCLOCKWISEBOTTOMLEFT ||
                        nSubType == COUNTERCLOCKWISETOPRIGHT
                        ) );
            case DOUBLESWEEPWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new SweepWipe(
                        // center:
                        nSubType == PARALLELVERTICAL ||
                        nSubType == PARALLELDIAGONAL ||
                        nSubType == OPPOSITEVERTICAL ||
                        nSubType == OPPOSITEHORIZONTAL,
                        // single:
                        false,
                        // oppositeVertical:
                        nSubType == OPPOSITEVERTICAL ||
                        nSubType == OPPOSITEHORIZONTAL,
                        // flipOnYAxis:
                        false ) );
            case DOUBLEFANWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new FanWipe(
                        //center:
                        true,
                        // single:
                        false,
                        // fanIn:
                        nSubType == FANINVERTICAL ||
                        nSubType == FANINHORIZONTAL ) );
            case TRIANGLEWIPE:
                return ParametricPolyPolygonSharedPtr(
                    FigureWipe::createTriangleWipe() );
            case ARROWHEADWIPE:
                return ParametricPolyPolygonSharedPtr(
                    FigureWipe::createArrowHeadWipe() );
            case PENTAGONWIPE:
                return ParametricPolyPolygonSharedPtr(
                    FigureWipe::createPentagonWipe() );
            case HEXAGONWIPE:
                return ParametricPolyPolygonSharedPtr(
                    FigureWipe::createHexagonWipe() );
            case STARWIPE: {
                sal_Int32 points;
                switch (nSubType) {
                case FIVEPOINT:
                    points = 5;
                    break;
                case SIXPOINT:
                    points = 6;
                    break;
                default:
                    points = 4;
                    break;
                }
                return ParametricPolyPolygonSharedPtr(
                    FigureWipe::createStarWipe(points) );
            }
            case MISCDIAGONALWIPE: {
                switch (nSubType) {
                case DOUBLEBARNDOOR:
                    return ParametricPolyPolygonSharedPtr(
                        new BarnDoorWipe( true /* doubled */ ) );
                case DOUBLEDIAMOND:
                    return ParametricPolyPolygonSharedPtr(
                        new DoubleDiamondWipe );
                }
                break;
            }
            case ZIGZAGWIPE:
                return ParametricPolyPolygonSharedPtr( new ZigZagWipe(5) );
            case BARNZIGZAGWIPE:
                return ParametricPolyPolygonSharedPtr( new BarnZigZagWipe(5) );

            case BOWTIEWIPE:
            case BARNVEEWIPE:
            case EYEWIPE:
            case ROUNDRECTWIPE:
            case MISCSHAPEWIPE:
            case SALOONDOORWIPE:
            case WINDSHIELDWIPE:
                // for now, map to barwipe transition
                return ParametricPolyPolygonSharedPtr(
                    new BarWipePolyPolygon );

            default:
            case PUSHWIPE:
            case SLIDEWIPE:
            case FADE:
                ENSURE_AND_THROW( false,
                                  "createShapeClipPolyPolygonAnimation(): Transition type mismatch" );
            }

            return ParametricPolyPolygonSharedPtr();
        }
    }
}
<commit_msg>INTEGRATION: CWS changefileheader (1.7.74); FILE MERGED 2008/03/31 14:00:25 rt 1.7.74.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: parametricpolypolygonfactory.cxx,v $
 * $Revision: 1.8 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_slideshow.hxx"

#include <canvas/debug.hxx>

#include <com/sun/star/animations/TransitionType.hpp>
#include <com/sun/star/animations/TransitionSubType.hpp>

#include "parametricpolypolygonfactory.hxx"
#include "barwipepolypolygon.hxx"
#include "boxwipe.hxx"
#include "fourboxwipe.hxx"
#include "barndoorwipe.hxx"
#include "doublediamondwipe.hxx"
#include "veewipe.hxx"
#include "iriswipe.hxx"
#include "ellipsewipe.hxx"
#include "checkerboardwipe.hxx"
#include "randomwipe.hxx"
#include "waterfallwipe.hxx"
#include "clockwipe.hxx"
#include "fanwipe.hxx"
#include "pinwheelwipe.hxx"
#include "snakewipe.hxx"
#include "spiralwipe.hxx"
#include "sweepwipe.hxx"
#include "figurewipe.hxx"
#include "zigzagwipe.hxx"

using namespace ::com::sun::star;

namespace slideshow
{
    namespace internal
    {
        ParametricPolyPolygonSharedPtr
        ParametricPolyPolygonFactory::createClipPolyPolygon(
            sal_Int16 nType, sal_Int16 nSubType )
        {
            using namespace ::com::sun::star::animations::TransitionType;
            using namespace ::com::sun::star::animations::TransitionSubType;

            switch (nType)
            {
            case BARWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new BarWipePolyPolygon );
            case BLINDSWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new BarWipePolyPolygon( 6 ) );
            case BOXWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new BoxWipe( nSubType == LEFTCENTER ||
                                 nSubType == TOPCENTER ||
                                 nSubType == RIGHTCENTER||
                                 nSubType == BOTTOMCENTER ) );
            case FOURBOXWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new FourBoxWipe( nSubType == CORNERSOUT ) );
            case BARNDOORWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new BarnDoorWipe );
            case DIAGONALWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new BarWipePolyPolygon );
            case VEEWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new VeeWipe );
            case IRISWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new IrisWipe );
            case ELLIPSEWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new EllipseWipe(nSubType) );
            case CHECKERBOARDWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new CheckerBoardWipe );
            case RANDOMBARWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new RandomWipe( 128, true /* bars */ ) );
            case DISSOLVE:
                return ParametricPolyPolygonSharedPtr(
                    new RandomWipe( 16 * 16, // for now until dxcanvas is faster
//                                     64 * 64 /* elements */,
                                    false /* dissolve */ ) );
            case WATERFALLWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new WaterfallWipe(
                        128,
                        // flipOnYAxis:
                        nSubType == VERTICALRIGHT ||
                        nSubType == HORIZONTALLEFT ) );
            case CLOCKWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new ClockWipe );
            case FANWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new FanWipe( // center:
                                 nSubType == CENTERTOP ||
                                 nSubType == CENTERRIGHT ) );
            case PINWHEELWIPE: {
                sal_Int32 blades;
                switch (nSubType) {
                case ONEBLADE:
                    blades = 1;
                    break;
                case THREEBLADE:
                    blades = 3;
                    break;
                case FOURBLADE:
                    blades = 4;
                    break;
                case EIGHTBLADE:
                    blades = 8;
                    break;
                default:
                    blades = 2;
                    break;
                }
                return ParametricPolyPolygonSharedPtr(
                    new PinWheelWipe( blades ) );
            }
            case SNAKEWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new SnakeWipe(
                        // elements:
                        64 * 64,
                        // diagonal:
                        nSubType == TOPLEFTDIAGONAL ||
                        nSubType == TOPRIGHTDIAGONAL ||
                        nSubType == BOTTOMRIGHTDIAGONAL ||
                        nSubType == BOTTOMLEFTDIAGONAL,
                        // flipOnYAxis:
                        nSubType == TOPLEFTVERTICAL ||
                        nSubType == TOPRIGHTDIAGONAL ||
                        nSubType == BOTTOMLEFTDIAGONAL
                        ) );
            case PARALLELSNAKESWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new ParallelSnakesWipe(
                        // elements:
                        64 * 64,
                        // diagonal:
                        nSubType == DIAGONALBOTTOMLEFTOPPOSITE ||
                        nSubType == DIAGONALTOPLEFTOPPOSITE,
                        // flipOnYAxis:
                        nSubType == VERTICALBOTTOMLEFTOPPOSITE ||
                        nSubType == HORIZONTALTOPLEFTOPPOSITE ||
                        nSubType == DIAGONALTOPLEFTOPPOSITE,
                        // opposite:
                        nSubType == VERTICALTOPLEFTOPPOSITE ||
                        nSubType == VERTICALBOTTOMLEFTOPPOSITE ||
                        nSubType == HORIZONTALTOPLEFTOPPOSITE ||
                        nSubType == HORIZONTALTOPRIGHTOPPOSITE ||
                        nSubType == DIAGONALBOTTOMLEFTOPPOSITE ||
                        nSubType == DIAGONALTOPLEFTOPPOSITE
                        ) );
            case SPIRALWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new SpiralWipe(
                        // elements:
                        64 * 64,
                        // flipOnYAxis:
                        nSubType == TOPLEFTCOUNTERCLOCKWISE ||
                        nSubType == TOPRIGHTCOUNTERCLOCKWISE ||
                        nSubType == BOTTOMRIGHTCOUNTERCLOCKWISE ||
                        nSubType == BOTTOMLEFTCOUNTERCLOCKWISE ) );
            case BOXSNAKESWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new BoxSnakesWipe(
                        // elements:
                        64 * 64,
                        // fourBox:
                        nSubType == FOURBOXVERTICAL ||
                        nSubType == FOURBOXHORIZONTAL ) );
            case SINGLESWEEPWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new SweepWipe(
                        // center:
                        nSubType == CLOCKWISETOP ||
                        nSubType == CLOCKWISERIGHT ||
                        nSubType == CLOCKWISEBOTTOM ||
                        nSubType == CLOCKWISELEFT,
                        // single:
                        true,
                        // oppositeVertical:
                        false,
                        // flipOnYAxis:
                        nSubType == COUNTERCLOCKWISEBOTTOMLEFT ||
                        nSubType == COUNTERCLOCKWISETOPRIGHT
                        ) );
            case DOUBLESWEEPWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new SweepWipe(
                        // center:
                        nSubType == PARALLELVERTICAL ||
                        nSubType == PARALLELDIAGONAL ||
                        nSubType == OPPOSITEVERTICAL ||
                        nSubType == OPPOSITEHORIZONTAL,
                        // single:
                        false,
                        // oppositeVertical:
                        nSubType == OPPOSITEVERTICAL ||
                        nSubType == OPPOSITEHORIZONTAL,
                        // flipOnYAxis:
                        false ) );
            case DOUBLEFANWIPE:
                return ParametricPolyPolygonSharedPtr(
                    new FanWipe(
                        //center:
                        true,
                        // single:
                        false,
                        // fanIn:
                        nSubType == FANINVERTICAL ||
                        nSubType == FANINHORIZONTAL ) );
            case TRIANGLEWIPE:
                return ParametricPolyPolygonSharedPtr(
                    FigureWipe::createTriangleWipe() );
            case ARROWHEADWIPE:
                return ParametricPolyPolygonSharedPtr(
                    FigureWipe::createArrowHeadWipe() );
            case PENTAGONWIPE:
                return ParametricPolyPolygonSharedPtr(
                    FigureWipe::createPentagonWipe() );
            case HEXAGONWIPE:
                return ParametricPolyPolygonSharedPtr(
                    FigureWipe::createHexagonWipe() );
            case STARWIPE: {
                sal_Int32 points;
                switch (nSubType) {
                case FIVEPOINT:
                    points = 5;
                    break;
                case SIXPOINT:
                    points = 6;
                    break;
                default:
                    points = 4;
                    break;
                }
                return ParametricPolyPolygonSharedPtr(
                    FigureWipe::createStarWipe(points) );
            }
            case MISCDIAGONALWIPE: {
                switch (nSubType) {
                case DOUBLEBARNDOOR:
                    return ParametricPolyPolygonSharedPtr(
                        new BarnDoorWipe( true /* doubled */ ) );
                case DOUBLEDIAMOND:
                    return ParametricPolyPolygonSharedPtr(
                        new DoubleDiamondWipe );
                }
                break;
            }
            case ZIGZAGWIPE:
                return ParametricPolyPolygonSharedPtr( new ZigZagWipe(5) );
            case BARNZIGZAGWIPE:
                return ParametricPolyPolygonSharedPtr( new BarnZigZagWipe(5) );

            case BOWTIEWIPE:
            case BARNVEEWIPE:
            case EYEWIPE:
            case ROUNDRECTWIPE:
            case MISCSHAPEWIPE:
            case SALOONDOORWIPE:
            case WINDSHIELDWIPE:
                // for now, map to barwipe transition
                return ParametricPolyPolygonSharedPtr(
                    new BarWipePolyPolygon );

            default:
            case PUSHWIPE:
            case SLIDEWIPE:
            case FADE:
                ENSURE_AND_THROW( false,
                                  "createShapeClipPolyPolygonAnimation(): Transition type mismatch" );
            }

            return ParametricPolyPolygonSharedPtr();
        }
    }
}
<|endoftext|>


<commit_before>// DnaMatchingAndVariationDetection.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include "Sequence.h"

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	// Define the sample sequences.
	char sequence1[33] = "ACAAGATGCCATTGTCCCCCGGCCTCCTGCTG";

	// Create the necessary Sequence objects.
	Sequence s1;

	// Initialize the Sequence objects.
	s1.Initialize(sequence1);

	// Define a search key.
	const int SEARCH_KEY_SIZE = 3;
	char searchKey[SEARCH_KEY_SIZE + 1] = "CCC";

	// Test sequence 1 and search functionality.
	cout << "Sequence 1: \""; s1.PrintSequence(); cout << "\"" << endl;
	cout << "    - Size: " << s1.GetSize() << endl;
	cout << "Search Key: " << searchKey << endl;
	cout << "    - Keys Found: " << s1.Search(searchKey, SEARCH_KEY_SIZE) << endl;

	return 0;
}<commit_msg>Expanded sequence search testing to include both valid and non-valid search keys<commit_after>// DnaMatchingAndVariationDetection.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include "Sequence.h"

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	// Define the sample sequences.
	char sequence1[33] = "ACAAGATGCCATTGTCCCCCGGCCTCCTGCTG";
	char sequence2[17] = "CTGCTGCTCTCCGGGG";

	// Create the necessary Sequence objects.
	Sequence s1, s2;

	// Initialize the Sequence objects.
	s1.Initialize(sequence1);
	s2.Initialize(sequence2, 16);

	// Define search keys.
	const int SEARCH_KEY_SIZE_1 = 3;
	char searchKey1[SEARCH_KEY_SIZE_1 + 1] = "CCC";
	char searchKey2[SEARCH_KEY_SIZE_1 + 1] = "AAA";
	const int SEARCH_KEY_SIZE_2 = 8;
	char searchKey3[SEARCH_KEY_SIZE_2 + 1] = "CTCCGGGG";
	char searchKey4[SEARCH_KEY_SIZE_2 + 1] = "CTGCTGCG";

	// Test sequence 1 (default sequence size) and search functionality.
	cout << "Sequence 1: \""; s1.PrintSequence(); cout << "\"" << endl;
	cout << "    - Size: " << s1.GetSize() << endl;
	cout << "Search Key: " << searchKey1 << endl;
	cout << "    - Keys Found: " << s1.Search(searchKey1, SEARCH_KEY_SIZE_1) << endl;
	cout << "Search Key: " << searchKey2 << endl;
	cout << "    - Keys Found: " << s1.Search(searchKey2, SEARCH_KEY_SIZE_1) << endl << endl;

	// Test sequence 2 (specified sequence size) and search functionality.
	cout << "Sequence 2: \""; s2.PrintSequence(); cout << "\"" << endl;
	cout << "    - Size: " << s2.GetSize() << endl;
	cout << "Search Key: " << searchKey3 << endl;
	cout << "    - Keys Found: " << s2.Search(searchKey3, SEARCH_KEY_SIZE_2) << endl;
	cout << "Search Key: " << searchKey4 << endl;
	cout << "    - Keys Found: " << s2.Search(searchKey4, SEARCH_KEY_SIZE_2) << endl << endl;

	return 0;
}<|endoftext|>


<commit_before>//$Id$

#ifndef MECHANICTRANSLATIONALMASS_HPP_INCLUDED
#define MECHANICTRANSLATIONALMASS_HPP_INCLUDED

#include <sstream>

#include "../../ComponentEssentials.h"
#include "../../ComponentUtilities.h"

namespace hopsan {

    //!
    //! @brief
    //! @ingroup MechanicalComponents
    //!
    class MechanicTranslationalMass : public ComponentQ
    {

    private:
        double m, B, k;
        double mLength;         //This length is not accesible by the user,
                                //it is set from the start values by the c-components in the ends
        double *mpND_f1, *mpND_x1, *mpND_v1, *mpND_c1, *mpND_Zx1, *mpND_f2, *mpND_x2, *mpND_v2, *mpND_c2, *mpND_Zx2;  //Node data pointers
        double f1, x1, v1, c1, Zx1, f2, x2, v2, c2, Zx2;                                                    //Node data variables
        double mNum[3];
        double mDen[3];
        SecondOrderFilter mFilter;
        Integrator mInt;
        Port *mpP1, *mpP2;

    public:
        static Component *Creator()
        {
            return new MechanicTranslationalMass("TranslationalMass");
        }

        MechanicTranslationalMass(const std::string name) : ComponentQ(name)
        {
            //Set member attributes
            m = 1.0;
            B = 10;
            k = 0.0;

            //Add ports to the component
            mpP1 = addPowerPort("P1", "NodeMechanic");
            mpP2 = addPowerPort("P2", "NodeMechanic");

            //Register changable parameters to the HOPSAN++ core
            registerParameter("m", "Mass", "[kg]",                  m);
            registerParameter("B", "Viscous Friction", "[Ns/m]",    B);
            registerParameter("k", "Spring Coefficient", "[N/m]",   k);
        }

        void initialize()
        {
            //Assign node data pointers
            mpND_f1 = getSafeNodeDataPtr(mpP1, NodeMechanic::FORCE);
            mpND_x1 = getSafeNodeDataPtr(mpP1, NodeMechanic::POSITION);
            mpND_v1 = getSafeNodeDataPtr(mpP1, NodeMechanic::VELOCITY);
            mpND_c1 = getSafeNodeDataPtr(mpP1, NodeMechanic::WAVEVARIABLE);
            mpND_Zx1 = getSafeNodeDataPtr(mpP1, NodeMechanic::CHARIMP);

            mpND_f2 = getSafeNodeDataPtr(mpP2, NodeMechanic::FORCE);
            mpND_x2 = getSafeNodeDataPtr(mpP2, NodeMechanic::POSITION);
            mpND_v2 = getSafeNodeDataPtr(mpP2, NodeMechanic::VELOCITY);
            mpND_c2 = getSafeNodeDataPtr(mpP2, NodeMechanic::WAVEVARIABLE);
            mpND_Zx2 = getSafeNodeDataPtr(mpP2, NodeMechanic::CHARIMP);

            //Initialization
            f1 = (*mpND_f1);
            x1 = (*mpND_x1);
            v1 = (*mpND_v1);
            x2 = (*mpND_x2);

            mLength = x1+x2;

            mNum[0] = 0.0;
            mNum[1] = 1.0;
            mNum[2] = 0.0;
            mDen[0] = m;
            mDen[1] = B;
            mDen[2] = k;
            mFilter.initialize(mTimestep, mNum, mDen, -f1, -v1);
            mInt.initialize(mTimestep, -v1, -x1+mLength);

            //Print debug message if velocities do not match
            if(mpP1->readNode(NodeMechanic::VELOCITY) != -mpP2->readNode(NodeMechanic::VELOCITY))
            {
                std::stringstream ss;
                ss << "Start velocities does not match, {" << getName() << "::" << mpP1->getPortName() <<
                        "} and {" << getName() << "::" << mpP2->getPortName() << "}.";
                this->addDebugMessage(ss.str());
            }
        }

        void simulateOneTimestep()
        {
            //Get variable values from nodes
            c1 = (*mpND_c1);
            Zx1 = (*mpND_Zx1);
            c2 = (*mpND_c2);
            Zx2 = (*mpND_Zx2);

            //Mass equations
            mDen[1] = B+Zx1+Zx2;

            mFilter.setDen(mDen);
            v2 = mFilter.update(c1-c2);
            v1 = -v2;
            x2 = mInt.update(v2);
            x1 = -x2 + mLength;
            f1 = c1 + Zx1*v1;
            f2 = c2 + Zx2*v2;

            //Write new values to nodes
            (*mpND_f1) = f1;
            (*mpND_x1) = x1;
            (*mpND_v1) = v1;
            (*mpND_f2) = f2;
            (*mpND_x2) = x2;
            (*mpND_v2) = v2;
        }
    };
}

#endif // MECHANICTRANSLATIONALMASS_HPP_INCLUDED

<commit_msg>Added max and min positions for translational mass.<commit_after>//$Id$

#ifndef MECHANICTRANSLATIONALMASS_HPP_INCLUDED
#define MECHANICTRANSLATIONALMASS_HPP_INCLUDED

#include <sstream>
#include <math.h>

#include "../../ComponentEssentials.h"
#include "../../ComponentUtilities.h"

namespace hopsan {

    //!
    //! @brief
    //! @ingroup MechanicalComponents
    //!
    class MechanicTranslationalMass : public ComponentQ
    {

    private:
        double m, B, k, xMin, xMax;
        double mLength;         //This length is not accesible by the user,
                                //it is set from the start values by the c-components in the ends
        double *mpND_f1, *mpND_x1, *mpND_v1, *mpND_c1, *mpND_Zx1, *mpND_f2, *mpND_x2, *mpND_v2, *mpND_c2, *mpND_Zx2;  //Node data pointers
        double f1, x1, v1, c1, Zx1, f2, x2, v2, c2, Zx2;                                                    //Node data variables
        double mNum[3];
        double mDen[3];
        SecondOrderFilter mFilter;
        Integrator mInt;
        Port *mpP1, *mpP2;

    public:
        static Component *Creator()
        {
            return new MechanicTranslationalMass("TranslationalMass");
        }

        MechanicTranslationalMass(const std::string name) : ComponentQ(name)
        {
            //Set member attributes
            m = 1.0;
            B = 10;
            k = 0.0;
            xMin = -1000.0;
            xMax = 1000.0;

            //Add ports to the component
            mpP1 = addPowerPort("P1", "NodeMechanic");
            mpP2 = addPowerPort("P2", "NodeMechanic");

            //Register changable parameters to the HOPSAN++ core
            registerParameter("m", "Mass", "[kg]",                  m);
            registerParameter("B", "Viscous Friction", "[Ns/m]",    B);
            registerParameter("k", "Spring Coefficient", "[N/m]",   k);
            registerParameter("x_min", "Minimum Position", "[m]",   xMin);
            registerParameter("x_max", "Maximum Position", "[m]",   xMax);
        }

        void initialize()
        {
            //Assign node data pointers
            mpND_f1 = getSafeNodeDataPtr(mpP1, NodeMechanic::FORCE);
            mpND_x1 = getSafeNodeDataPtr(mpP1, NodeMechanic::POSITION);
            mpND_v1 = getSafeNodeDataPtr(mpP1, NodeMechanic::VELOCITY);
            mpND_c1 = getSafeNodeDataPtr(mpP1, NodeMechanic::WAVEVARIABLE);
            mpND_Zx1 = getSafeNodeDataPtr(mpP1, NodeMechanic::CHARIMP);

            mpND_f2 = getSafeNodeDataPtr(mpP2, NodeMechanic::FORCE);
            mpND_x2 = getSafeNodeDataPtr(mpP2, NodeMechanic::POSITION);
            mpND_v2 = getSafeNodeDataPtr(mpP2, NodeMechanic::VELOCITY);
            mpND_c2 = getSafeNodeDataPtr(mpP2, NodeMechanic::WAVEVARIABLE);
            mpND_Zx2 = getSafeNodeDataPtr(mpP2, NodeMechanic::CHARIMP);

            //Initialization
            f1 = (*mpND_f1);
            x1 = (*mpND_x1);
            v1 = (*mpND_v1);
            x2 = (*mpND_x2);

            mLength = x1+x2;

            mNum[0] = 0.0;
            mNum[1] = 1.0;
            mNum[2] = 0.0;
            mDen[0] = m;
            mDen[1] = B;
            mDen[2] = k;
            mFilter.initialize(mTimestep, mNum, mDen, -f1, -v1);
            mInt.initialize(mTimestep, -v1, -x1+mLength);

            //Print debug message if velocities do not match
            if(mpP1->readNode(NodeMechanic::VELOCITY) != -mpP2->readNode(NodeMechanic::VELOCITY))
            {
                std::stringstream ss;
                ss << "Start velocities does not match, {" << getName() << "::" << mpP1->getPortName() <<
                        "} and {" << getName() << "::" << mpP2->getPortName() << "}.";
                this->addDebugMessage(ss.str());
            }
        }

        void simulateOneTimestep()
        {
            //Get variable values from nodes
            c1 = (*mpND_c1);
            Zx1 = (*mpND_Zx1);
            c2 = (*mpND_c2);
            Zx2 = (*mpND_Zx2);

            //Mass equations
            mDen[1] = B+Zx1+Zx2;

            mFilter.setDen(mDen);
            v2 = mFilter.update(c1-c2);

            x2 = mInt.update(v2);

            if(x2<xMin)
            {
                x2=xMin;
                v2=std::min(0.0, v2);
            }
            if(x2>xMax)
            {
                x2=xMax;
                v2=std::max(0.0, v2);
            }

            v1 = -v2;
            x1 = -x2 + mLength;
            f1 = c1 + Zx1*v1;
            f2 = c2 + Zx2*v2;

            //Write new values to nodes
            (*mpND_f1) = f1;
            (*mpND_x1) = x1;
            (*mpND_v1) = v1;
            (*mpND_f2) = f2;
            (*mpND_x2) = x2;
            (*mpND_v2) = v2;
        }
    };
}

#endif // MECHANICTRANSLATIONALMASS_HPP_INCLUDED

<|endoftext|>