text:
"""
This file will dump the inception network to a few formats. Basically this will convert
all of the constants into Variables for the trainable parameters
"""
import os
import sys
import numpy as np
import tensorflow as tf

INCEPTION_V3_IMAGE_SIZE = 299
INCEPTION_V3_IMAGE_MEAN = 128
INCEPTION_V3_IMAGE_STD = 128

def _build_inference_nodes(images, graph, sess_config):
  """
  Add the inference nodes from the inception architecture to the graph.

  NOTE: Variables() default to being trainable

  """

  # we will replace this op with our images
  input_op = graph.get_operation_by_name('Mul')

  # Several options here:
  # pool_3 : raw 2048 features
  # pool_3/_reshape raw 2048 features reshaped for softmax computation
  # softmax : softmax weights
  features_op = graph.get_operation_by_name('pool_3/_reshape')

  ops = graph.get_operations()

  # Find the operations that correspond to the convolutional weights
  # *_params for the convolutional kernels
  # weights for the softmax weights
  weights_ops = [op for op in ops if 'params' in op.name]# or 'weights' in op.name]

  # Find the operations that correspond to the batch normalization biases
  # 'biases' for the softmax bias
  bias_ops = [op for op in ops if 'beta' in op.name or 'gamma' in op.name]# or 'biases' in op.name]

  # Grab the remaining operations for reuse
  reuse_ops = graph.get_operations()
  image_input_index = reuse_ops.index(input_op)
  feature_output_index = reuse_ops.index(features_op)
  reuse_ops = reuse_ops[image_input_index+1:feature_output_index+1]
  # Filter out the weight ops and the
  # batch normalization ops (both the bias and the moving mean / variance)
  reuse_ops = [
    op for op in reuse_ops if (op not in weights_ops) and
                              (op not in bias_ops) and
                              ('moving' not in op.name)
  ]

  # Pull out the current values of the weights and bias
  with tf.Session(graph=graph, config=sess_config):
    weights_orig = dict([(op.name, op.outputs[0].eval()) for op in weights_ops])
    bias_orig = dict([(op.name, op.outputs[0].eval()) for op in bias_ops])

  # T will hold all of the new tensor Variables.
  T = {
    name : tf.Variable(
                initial_value = value,
                name = name,
                collections=['variables', 'weights'] # why weights and not trainable_variables or ...?
          )
    for name, value in weights_orig.iteritems()
  }
  T.update({
    name : tf.Variable(value, name=name)
    for name, value in bias_orig.iteritems()
  })

  # Add in our custom image node
  T[input_op.name] = images

  # Now add in the the remaining nodes of the graph
  for op in reuse_ops:

    # If this is a batch normalization layer, then use our new variables
    # Note: Getting rid of the moving mean and variance will affect the classification
    # performance. You wont ge the same results without them.
    if op.type == 'BatchNormWithGlobalNormalization':
      # t == tensor output of convolution
      t, beta, gamma = [T[op.inputs[i].op.name] for i in [0, 3, 4]]
      mu, var = tf.nn.moments(t, [0, 1, 2], name=op.name+'/')

      T[op.name] = tf.nn.batch_norm_with_global_normalization(
        t = t, m=mu, v=var, beta=beta, gamma=gamma,
        variance_epsilon=1e-8, scale_after_normalization=True,
        name = op.name
      )

    # copy the operation into the graph
    else:
      copied_op = images.graph.create_op(
        op_type = op.type,
        # Convert the Variables to Tensors
        inputs = [tf.convert_to_tensor(T[t.op.name]) for t in op.inputs],
        dtypes = [o.dtype for o in op.outputs],
        name = op.name,
        attrs = op.node_def.attr
      )

      T[op.name] = copied_op.outputs[0]

def dump(output_dir):

  if not os.path.exists(output_dir):
    os.makedirs(output_dir)

  graph = tf.Graph() #tf.get_default_graph()
  graph_def = tf.GraphDef()
  graph_def_file = '../inception_v3/inception_dec_2015/tensorflow_inception_graph.pb'

  # Read in the graph definition
  with tf.gfile.FastGFile(graph_def_file, 'rb') as f:
    graph_def.ParseFromString(f.read())

  # Apply the graph definition to the graph
  with graph.as_default():
    tf.import_graph_def(graph_def, name='')

  # Save off a text format version
  tf.train.write_graph(graph_def, output_dir, 'const_inception_graph.pb', as_text=False)
  tf.train.write_graph(graph_def, output_dir, 'const_inception_graph.pbtxt', as_text=True)

  # we can test the graph:
  print "Testing the original inception network:"
  #image_data = tf.gfile.FastGFile("/Users/GVH/Desktop/cropped_panda.jpg", 'rb').read()
  with tf.Session(graph=graph) as sess:
    softmax_tensor = sess.graph.get_tensor_by_name('softmax:0')
    predictions = sess.run(softmax_tensor)#,
                           #{'DecodeJpeg/contents:0': image_data})
    predictions = np.squeeze(predictions)

    top_k = predictions.argsort()[-5:][::-1]
    for idx in top_k:
      print "%d : %0.5f" % (idx, predictions[idx])

  # construct a placeholder for the images
  #with graph.as_default():
  #images = tf.placeholder(tf.float32, name="images")

  if True:
    image_path = tf.placeholder(tf.string, shape=[], name='image_path')#"/Users/GVH/Desktop/cropped_panda.jpg",
    image = tf.read_file(image_path)
    image = tf.image.decode_jpeg(image, channels=3)
    image = tf.cast(image, tf.float32)
    images = tf.expand_dims(image, 0)
    images = tf.image.resize_images(images, INCEPTION_V3_IMAGE_SIZE, INCEPTION_V3_IMAGE_SIZE)
    images -= INCEPTION_V3_IMAGE_MEAN
    images /= INCEPTION_V3_IMAGE_STD
    batch = images
  else:
    batch = tf.zeros(shape=[1, INCEPTION_V3_IMAGE_SIZE, INCEPTION_V3_IMAGE_SIZE, 3], name="images")

  # Convert the constants to variables
  _build_inference_nodes(batch, graph, None)

  #for var in batch.graph.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES):
  #  print var.name

  default_graph = batch.graph

  tf.train.write_graph(default_graph.as_graph_def(), output_dir, 'var_inception_graph.pb', as_text=False)
  tf.train.write_graph(default_graph.as_graph_def(), output_dir, 'var_inception_graph.pbtxt', as_text=True)

  assign_ops = []
  for op in default_graph.get_operations():
     if op.type == 'Assign':
        assign_ops.append(op)

  saver = tf.train.Saver(default_graph.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES))
  checkpoint_dir = os.path.join(output_dir, 'initial_checkpoint')
  if not os.path.exists(checkpoint_dir):
    os.makedirs(checkpoint_dir)

  #summary_dir = os.path.join(output_dir, 'summary')
  #if not os.path.exists(summary_dir):
  #  os.makedirs(summary_dir)
  #summary = tf.train.SummaryWriter(logdir=summary_dir)

  with default_graph.as_default():
    with tf.Session(graph=default_graph) as sess:

      tf.initialize_all_variables().run()

      #sess.run(assign_ops)

      # Only run the test if you have extracted the softmax weight too
      if False:
        softmax = default_graph.get_operation_by_name('softmax').outputs[0]

        predictions = sess.run(softmax, feed_dict={image_path : "/Users/GVH/Desktop/cropped_panda.jpg"})

        predictions = np.squeeze(predictions)

        print predictions.shape

        top_k = predictions.argsort()[-5:][::-1]
        for idx in top_k:
          print "%d : %0.5f" % (idx, predictions[idx])

      # Create something that we can restore from
      saver.save(
        sess=sess,
        save_path= os.path.join(checkpoint_dir, 'original_inception_v3_with_variables'),
      )

      #graph_def = sess.graph.as_graph_def(add_shapes=True)
      #summary.add_graph(graph_def)

  #summary.flush()
  #summary.close()

if __name__ == '__main__':

  dump(sys.argv[1])

redpajama_set_name: RedPajamaGithub


text:
<!DOCTYPE html>

  <meta charset="utf-8">
  <title>cbft</title>
  <meta name="description" content="">

  <link href="/static/css/prism.css" rel="stylesheet"/>

  <link href="/static/css/app.css" rel="stylesheet"/>
  <link href="/static/css/bootstrap.css" rel="stylesheet"/>
  <link href="/static/css/dashboard.css" rel="stylesheet"/>
  <link href="/static/css/rickshaw.min.css" rel="stylesheet"/>

  <link rel="shortcut icon" href="/static/favicon.ico"/>

            cbft

Indexes

Nodes

Monitor

Manage

Logs


text:
package org.broadinstitute.dsde.rawls.entities

import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
import akka.http.scaladsl.model.{StatusCodes, Uri}
import com.google.api.client.googleapis.json.GoogleJsonResponseException
import com.google.cloud.bigquery.BigQueryException
import com.typesafe.scalalogging.LazyLogging
import io.opencensus.trace.Span
import org.broadinstitute.dsde.rawls.dataaccess.slick.{DataAccess, ReadAction}
import org.broadinstitute.dsde.rawls.dataaccess.{AttributeTempTableType, SamDAO, SlickDataSource}
import org.broadinstitute.dsde.rawls.entities.exceptions.{
  DataEntityException,
  DeleteEntitiesConflictException,
  DeleteEntitiesOfTypeConflictException,
  EntityNotFoundException
}
import org.broadinstitute.dsde.rawls.expressions.ExpressionEvaluator
import org.broadinstitute.dsde.rawls.metrics.RawlsInstrumented
import org.broadinstitute.dsde.rawls.model.AttributeUpdateOperations.{AttributeUpdateOperation, EntityUpdateDefinition}
import org.broadinstitute.dsde.rawls.model.WorkspaceJsonSupport._
import org.broadinstitute.dsde.rawls.model.{
  AttributeEntityReference,
  Entity,
  EntityCopyDefinition,
  EntityQuery,
  ErrorReport,
  SamResourceTypeNames,
  SamWorkspaceActions,
  UserInfo,
  WorkspaceName,
  _
}
import org.broadinstitute.dsde.rawls.util.TracingUtils.traceDBIOWithParent
import org.broadinstitute.dsde.rawls.util.{AttributeSupport, EntitySupport, JsonFilterUtils, WorkspaceSupport}
import org.broadinstitute.dsde.rawls.workspace.AttributeUpdateOperationException
import org.broadinstitute.dsde.rawls.{RawlsException, RawlsExceptionWithErrorReport}
import spray.json.DefaultJsonProtocol._

import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success, Try}

object EntityService {
  def constructor(dataSource: SlickDataSource,
                  samDAO: SamDAO,
                  workbenchMetricBaseName: String,
                  entityManager: EntityManager,
                  pageSizeLimit: Int
  )(ctx: RawlsRequestContext)(implicit executionContext: ExecutionContext): EntityService =
    new EntityService(ctx, dataSource, samDAO, entityManager, workbenchMetricBaseName, pageSizeLimit)
}

class EntityService(protected val ctx: RawlsRequestContext,
                    val dataSource: SlickDataSource,
                    val samDAO: SamDAO,
                    entityManager: EntityManager,
                    override val workbenchMetricBaseName: String,
                    pageSizeLimit: Int
)(implicit protected val executionContext: ExecutionContext)
    extends WorkspaceSupport
    with EntitySupport
    with AttributeSupport
    with LazyLogging
    with RawlsInstrumented
    with JsonFilterUtils {

  import dataSource.dataAccess.driver.api._

  def createEntity(workspaceName: WorkspaceName, entity: Entity): Future[Entity] =
    withAttributeNamespaceCheck(entity) {
      for {
        workspaceContext <- getWorkspaceContextAndPermissions(workspaceName,
                                                              SamWorkspaceActions.write,
                                                              Some(WorkspaceAttributeSpecs(all = false))
        )
        entityManager <- entityManager.resolveProviderFuture(EntityRequestArguments(workspaceContext, ctx))
        result <- entityManager.createEntity(entity)
      } yield result
    }

  def getEntity(workspaceName: WorkspaceName,
                entityType: String,
                entityName: String,
                dataReference: Option[DataReferenceName],
                billingProject: Option[GoogleProjectId]
  ): Future[Entity] =
    getWorkspaceContextAndPermissions(workspaceName,
                                      SamWorkspaceActions.read,
                                      Some(WorkspaceAttributeSpecs(all = false))
    ) flatMap { workspaceContext =>
      val entityRequestArguments = EntityRequestArguments(workspaceContext, ctx, dataReference, billingProject)

      val entityFuture = for {
        entityProvider <- entityManager.resolveProviderFuture(entityRequestArguments)
        entity <- entityProvider.getEntity(entityType, entityName)
      } yield entity

      entityFuture
        .recover { case _: EntityNotFoundException =>
          // could move this error message into EntityNotFoundException and allow it to bubble up
          throw new RawlsExceptionWithErrorReport(
            ErrorReport(StatusCodes.NotFound, s"${entityType} ${entityName} does not exist in $workspaceName")
          )
        }
        .recover(bigQueryRecover)
    }

  def updateEntity(workspaceName: WorkspaceName,
                   entityType: String,
                   entityName: String,
                   operations: Seq[AttributeUpdateOperation]
  ): Future[Entity] =
    withAttributeNamespaceCheck(operations.map(_.name)) {
      getWorkspaceContextAndPermissions(workspaceName,
                                        SamWorkspaceActions.write,
                                        Some(WorkspaceAttributeSpecs(all = false))
      ) flatMap { workspaceContext =>
        dataSource.inTransactionWithAttrTempTable(Set(AttributeTempTableType.Entity)) { dataAccess =>
          withEntity(workspaceContext, entityType, entityName, dataAccess) { entity =>
            val updateAction = Try {
              val updatedEntity = applyOperationsToEntity(entity, operations)
              dataAccess.entityQuery.save(workspaceContext, updatedEntity)
            } match {
              case Success(result) => result
              case Failure(e: AttributeUpdateOperationException) =>
                DBIO.failed(
                  new RawlsExceptionWithErrorReport(
                    errorReport =
                      ErrorReport(StatusCodes.BadRequest,
                                  s"Unable to update entity ${entityType}/${entityName} in ${workspaceName}",
                                  ErrorReport(e)
                      )
                  )
                )
              case Failure(regrets) => DBIO.failed(regrets)
            }
            updateAction
          }
        }
      }
    }

  def deleteEntities(workspaceName: WorkspaceName,
                     entRefs: Seq[AttributeEntityReference],
                     dataReference: Option[DataReferenceName],
                     billingProject: Option[GoogleProjectId]
  ): Future[Set[AttributeEntityReference]] =
    getWorkspaceContextAndPermissions(workspaceName,
                                      SamWorkspaceActions.write,
                                      Some(WorkspaceAttributeSpecs(all = false))
    ) flatMap { workspaceContext =>
      val entityRequestArguments = EntityRequestArguments(workspaceContext, ctx, dataReference, billingProject)

      val deleteFuture = for {
        entityProvider <- entityManager.resolveProviderFuture(entityRequestArguments)
        _ <- entityProvider.deleteEntities(entRefs)
      } yield Set[AttributeEntityReference]()

      deleteFuture
        .recover { case delEx: DeleteEntitiesConflictException =>
          delEx.referringEntities
        }
        .recover(bigQueryRecover)
    }

  def deleteEntitiesOfType(workspaceName: WorkspaceName,
                           entityType: String,
                           dataReference: Option[DataReferenceName],
                           billingProject: Option[GoogleProjectId]
  ) =
    getWorkspaceContextAndPermissions(workspaceName,
                                      SamWorkspaceActions.write,
                                      Some(WorkspaceAttributeSpecs(all = false))
    ) flatMap { workspaceContext =>
      val entityRequestArguments = EntityRequestArguments(workspaceContext, ctx, dataReference, billingProject)

      val deleteFuture = for {
        entityProvider <- entityManager.resolveProviderFuture(entityRequestArguments)
        numberOfEntitiesDeleted <- entityProvider.deleteEntitiesOfType(entityType)
      } yield numberOfEntitiesDeleted

      deleteFuture
        .recover { case delEx: DeleteEntitiesOfTypeConflictException =>
          throw new RawlsExceptionWithErrorReport(
            ErrorReport(
              StatusCodes.Conflict,
              s"Entity type [$entityType] cannot be deleted because there are ${delEx.conflictCount} references " +
                s"to this entity type. All references must be removed before deleting a type."
            )
          )
        }
        .recover(bigQueryRecover)
    }

  def deleteEntityAttributes(workspaceName: WorkspaceName,
                             entityType: String,
                             attributeNames: Set[AttributeName]
  ): Future[Unit] =
    getWorkspaceContextAndPermissions(workspaceName,
                                      SamWorkspaceActions.write,
                                      Some(WorkspaceAttributeSpecs(all = false))
    ) flatMap { workspaceContext =>
      dataSource.inTransaction { dataAccess =>
        dataAccess
          .entityAttributeShardQuery(workspaceContext)
          .deleteAttributes(workspaceContext, entityType, attributeNames) flatMap {
          case Vector(0) =>
            throw new RawlsExceptionWithErrorReport(
              errorReport = ErrorReport(StatusCodes.BadRequest, s"Could not find any of the given attribute names.")
            )
          case _ => DBIO.successful(())
        }
      }
    }

  def renameEntity(workspaceName: WorkspaceName, entityType: String, entityName: String, newName: String): Future[Int] =
    getWorkspaceContextAndPermissions(workspaceName,
                                      SamWorkspaceActions.write,
                                      Some(WorkspaceAttributeSpecs(all = false))
    ) flatMap { workspaceContext =>
      dataSource.inTransaction { dataAccess =>
        withEntity(workspaceContext, entityType, entityName, dataAccess) { entity =>
          dataAccess.entityQuery.get(workspaceContext, entity.entityType, newName) flatMap {
            case None => dataAccess.entityQuery.rename(workspaceContext, entity.entityType, entity.name, newName)
            case Some(_) =>
              throw new RawlsExceptionWithErrorReport(
                errorReport =
                  ErrorReport(StatusCodes.Conflict, s"Destination ${entity.entityType} ${newName} already exists")
              )
          }
        }
      }
    }

  def renameEntityType(workspaceName: WorkspaceName, oldName: String, renameInfo: EntityTypeRename): Future[Int] = {
    import org.broadinstitute.dsde.rawls.dataaccess.slick.{DataAccess, ReadAction}

    def validateExistingType(dataAccess: DataAccess,
                             workspaceContext: Workspace,
                             oldName: String
    ): ReadAction[Boolean] =
      dataAccess.entityQuery.doesEntityTypeAlreadyExist(workspaceContext, oldName) map {
        case Some(true) => true
        case Some(false) =>
          throw new RawlsExceptionWithErrorReport(
            errorReport = ErrorReport(StatusCodes.NotFound, s"Can't find entity type ${oldName}")
          )
        case None =>
          throw new RawlsExceptionWithErrorReport(
            errorReport = ErrorReport(StatusCodes.InternalServerError,
                                      s"Unexpected error; could not determine existence of entity type ${oldName}"
            )
          )
      }

    def validateNewType(dataAccess: DataAccess, workspaceContext: Workspace, newName: String): ReadAction[Boolean] =
      dataAccess.entityQuery.doesEntityTypeAlreadyExist(workspaceContext, newName) map {
        case Some(true) =>
          throw new RawlsExceptionWithErrorReport(
            errorReport = ErrorReport(StatusCodes.Conflict, s"${newName} already exists as an entity type")
          )
        case Some(false) => false
        case None =>
          throw new RawlsExceptionWithErrorReport(
            errorReport = ErrorReport(StatusCodes.InternalServerError,
                                      s"Unexpected error; could not determine existence of entity type ${newName}"
            )
          )
      }

    getWorkspaceContextAndPermissions(workspaceName,
                                      SamWorkspaceActions.write,
                                      Some(WorkspaceAttributeSpecs(all = false))
    ) flatMap { workspaceContext =>
      dataSource.inTransaction { dataAccess =>
        for {
          _ <- validateNewType(dataAccess, workspaceContext, renameInfo.newName)
          _ <- validateExistingType(dataAccess, workspaceContext, oldName)
          renameResult <- dataAccess.entityQuery.changeEntityTypeName(workspaceContext, oldName, renameInfo.newName)
        } yield renameResult
      }
    }
  }

  def evaluateExpression(workspaceName: WorkspaceName,
                         entityType: String,
                         entityName: String,
                         expression: String
  ): Future[Seq[AttributeValue]] =
    getWorkspaceContextAndPermissions(workspaceName,
                                      SamWorkspaceActions.read,
                                      Some(WorkspaceAttributeSpecs(all = false))
    ) flatMap { workspaceContext =>
      dataSource.inTransaction { dataAccess =>
        withSingleEntityRec(entityType, entityName, workspaceContext, dataAccess) { entities =>
          ExpressionEvaluator.withNewExpressionEvaluator(dataAccess, Some(entities)) { evaluator =>
            evaluator.evalFinalAttribute(workspaceContext, expression).asTry map { tryValuesByEntity =>
              tryValuesByEntity match {
                // parsing failure
                case Failure(regret) =>
                  throw new RawlsExceptionWithErrorReport(errorReport = ErrorReport(StatusCodes.BadRequest, regret))
                case Success(valuesByEntity) =>
                  if (valuesByEntity.size != 1) {
                    // wrong number of entities?!
                    throw new RawlsException(
                      s"Expression parsing should have returned a single entity for ${entityType}/$entityName $expression, but returned ${valuesByEntity.size} entities instead"
                    )
                  } else {
                    assert(valuesByEntity.head._1 == entityName)
                    valuesByEntity.head match {
                      case (_, Success(result)) => result.toSeq
                      case (_, Failure(regret)) =>
                        throw new RawlsExceptionWithErrorReport(
                          errorReport = ErrorReport(
                            StatusCodes.BadRequest,
                            "Unable to evaluate expression '${expression}' on ${entityType}/${entityName} in ${workspaceName}",
                            ErrorReport(regret)
                          )
                        )
                    }
                  }
              }
            }
          }
        }
      }
    }

  def entityTypeMetadata(workspaceName: WorkspaceName,
                         dataReference: Option[DataReferenceName],
                         billingProject: Option[GoogleProjectId],
                         useCache: Boolean
  ): Future[Map[String, EntityTypeMetadata]] =
    getWorkspaceContextAndPermissions(workspaceName,
                                      SamWorkspaceActions.read,
                                      Some(WorkspaceAttributeSpecs(all = false))
    ) flatMap { workspaceContext =>
      val entityRequestArguments = EntityRequestArguments(workspaceContext, ctx, dataReference, billingProject)

      val metadataFuture = for {
        entityProvider <- entityManager.resolveProviderFuture(entityRequestArguments)
        metadata <- entityProvider.entityTypeMetadata(useCache)
      } yield metadata

      metadataFuture.recover(bigQueryRecover)
    }

  def listEntities(workspaceName: WorkspaceName, entityType: String): Future[Seq[Entity]] =
    getWorkspaceContextAndPermissions(workspaceName,
                                      SamWorkspaceActions.read,
                                      Some(WorkspaceAttributeSpecs(all = false))
    ) flatMap { workspaceContext =>
      dataSource.inTransaction { dataAccess =>
        traceDBIOWithParent("countActiveEntitiesOfType", ctx) { countContext =>
          dataAccess.entityQuery
            .findActiveEntityByType(workspaceContext.workspaceIdAsUUID, entityType)
            .length
            .result
            .flatMap { entityCount =>
              if (entityCount > pageSizeLimit) {
                throw new RawlsExceptionWithErrorReport(
                  ErrorReport(
                    StatusCodes.BadRequest,
                    s"Result set size of $entityCount cannot exceed $pageSizeLimit. Use the paginated entityQuery API instead."
                  )
                )
              } else {
                traceDBIOWithParent("listActiveEntitiesOfType", countContext) { _ =>
                  dataAccess.entityQuery.listActiveEntitiesOfType(workspaceContext, entityType)
                }.map { r =>
                  r.toSeq
                }
              }
            }
        }
      }
    }

  def queryEntities(workspaceName: WorkspaceName,
                    dataReference: Option[DataReferenceName],
                    entityType: String,
                    query: EntityQuery,
                    billingProject: Option[GoogleProjectId]
  ): Future[EntityQueryResponse] = {
    if (query.pageSize > pageSizeLimit) {
      throw new RawlsExceptionWithErrorReport(
        ErrorReport(StatusCodes.BadRequest, s"Page size cannot exceed $pageSizeLimit")
      )
    }

    getWorkspaceContextAndPermissions(workspaceName,
                                      SamWorkspaceActions.read,
                                      Some(WorkspaceAttributeSpecs(all = false))
    ) flatMap { workspaceContext =>
      val entityRequestArguments = EntityRequestArguments(workspaceContext, ctx, dataReference, billingProject)

      val queryFuture = for {
        entityProvider <- entityManager.resolveProviderFuture(entityRequestArguments)
        entities <- entityProvider.queryEntities(entityType, query, ctx)
      } yield entities

      queryFuture.recover(bigQueryRecover)
    }
  }

  def copyEntities(entityCopyDef: EntityCopyDefinition,
                   uri: Uri,
                   linkExistingEntities: Boolean
  ): Future[EntityCopyResponse] =
    getWorkspaceContextAndPermissions(entityCopyDef.destinationWorkspace,
                                      SamWorkspaceActions.write,
                                      Some(WorkspaceAttributeSpecs(all = false))
    ) flatMap { destWorkspaceContext =>
      getWorkspaceContextAndPermissions(entityCopyDef.sourceWorkspace,
                                        SamWorkspaceActions.read,
                                        Some(WorkspaceAttributeSpecs(all = false))
      ) flatMap { sourceWorkspaceContext =>
        dataSource.inTransaction { dataAccess =>
          for {
            sourceAD <- DBIO.from(
              samDAO.getResourceAuthDomain(SamResourceTypeNames.workspace, sourceWorkspaceContext.workspaceId, ctx)
            )
            destAD <- DBIO.from(
              samDAO.getResourceAuthDomain(SamResourceTypeNames.workspace, destWorkspaceContext.workspaceId, ctx)
            )
            result <- authDomainCheck(sourceAD.toSet, destAD.toSet) flatMap { _ =>
              val entityNames = entityCopyDef.entityNames
              val entityType = entityCopyDef.entityType
              val copyResults = traceDBIOWithParent("checkAndCopyEntities", ctx)(s1 =>
                dataAccess.entityQuery.checkAndCopyEntities(sourceWorkspaceContext,
                                                            destWorkspaceContext,
                                                            entityType,
                                                            entityNames,
                                                            linkExistingEntities,
                                                            s1
                )
              )
              copyResults
            }
          } yield result
        }
      }
    }

  def batchUpdateEntitiesInternal(workspaceName: WorkspaceName,
                                  entityUpdates: Seq[EntityUpdateDefinition],
                                  upsert: Boolean,
                                  dataReference: Option[DataReferenceName],
                                  billingProject: Option[GoogleProjectId]
  ): Future[Traversable[Entity]] =
    getWorkspaceContextAndPermissions(workspaceName,
                                      SamWorkspaceActions.write,
                                      Some(WorkspaceAttributeSpecs(all = false))
    ) flatMap { workspaceContext =>
      val entityRequestArguments = EntityRequestArguments(workspaceContext, ctx, dataReference, billingProject)
      for {
        entityProvider <- entityManager.resolveProviderFuture(entityRequestArguments)
        entities <-
          if (upsert) {
            entityProvider.batchUpsertEntities(entityUpdates)
          } else {
            entityProvider.batchUpdateEntities(entityUpdates)
          }
      } yield entities
    }

  def batchUpdateEntities(workspaceName: WorkspaceName,
                          entityUpdates: Seq[EntityUpdateDefinition],
                          dataReference: Option[DataReferenceName],
                          billingProject: Option[GoogleProjectId]
  ): Future[Traversable[Entity]] =
    batchUpdateEntitiesInternal(workspaceName, entityUpdates, upsert = false, dataReference, billingProject)

  def batchUpsertEntities(workspaceName: WorkspaceName,
                          entityUpdates: Seq[EntityUpdateDefinition],
                          dataReference: Option[DataReferenceName],
                          billingProject: Option[GoogleProjectId]
  ): Future[Traversable[Entity]] =
    batchUpdateEntitiesInternal(workspaceName, entityUpdates, upsert = true, dataReference, billingProject)

  def renameAttribute(workspaceName: WorkspaceName,
                      entityType: String,
                      oldAttributeName: AttributeName,
                      attributeRenameRequest: AttributeRename
  ): Future[Int] =
    withAttributeNamespaceCheck(Seq(attributeRenameRequest.newAttributeName)) {
      getWorkspaceContextAndPermissions(workspaceName,
                                        SamWorkspaceActions.write,
                                        Some(WorkspaceAttributeSpecs(all = false))
      ) flatMap { workspaceContext =>
        def validateNewAttributeName(dataAccess: DataAccess,
                                     workspaceContext: Workspace,
                                     entityType: String,
                                     attributeName: AttributeName
        ): ReadAction[Boolean] =
          dataAccess
            .entityAttributeShardQuery(workspaceContext)
            .doesAttributeNameAlreadyExist(workspaceContext, entityType, attributeName) map {
            case Some(false) => false
            case Some(true) =>
              throw new RawlsExceptionWithErrorReport(
                errorReport =
                  ErrorReport(StatusCodes.Conflict,
                              s"${AttributeName.toDelimitedName(attributeName)} already exists as an attribute name"
                  )
              )
            case None =>
              throw new RawlsExceptionWithErrorReport(
                errorReport = ErrorReport(
                  StatusCodes.InternalServerError,
                  s"Unexpected error; could not determine existence of attribute name ${AttributeName.toDelimitedName(attributeName)}"
                )
              )
          }

        def validateRowsUpdated(rowsUpdated: Int, oldAttributeName: AttributeName): Boolean =
          rowsUpdated match {
            case 0 =>
              throw new RawlsExceptionWithErrorReport(
                errorReport =
                  ErrorReport(StatusCodes.NotFound,
                              s"Can't find attribute name ${AttributeName.toDelimitedName(oldAttributeName)}"
                  )
              )
            case _ => true
          }

        dataSource.inTransaction { dataAccess =>
          val newAttributeName = attributeRenameRequest.newAttributeName
          for {
            _ <- validateNewAttributeName(dataAccess, workspaceContext, entityType, newAttributeName)
            rowsUpdated <- dataAccess
              .entityAttributeShardQuery(workspaceContext)
              .renameAttribute(workspaceContext, entityType, oldAttributeName, newAttributeName)
            _ = validateRowsUpdated(rowsUpdated, oldAttributeName)
          } yield rowsUpdated
        }
      }
    }

  private def bigQueryRecover[U]: PartialFunction[Throwable, U] = {
    case dee: DataEntityException =>
      throw new RawlsExceptionWithErrorReport(ErrorReport(dee.code, dee.getMessage))
    case bqe: BigQueryException =>
      throw new RawlsExceptionWithErrorReport(
        ErrorReport(StatusCodes.getForKey(bqe.getCode).getOrElse(StatusCodes.InternalServerError), bqe.getMessage)
      )
    case gjre: GoogleJsonResponseException =>
      // unlikely to hit this case; we should see BigQueryExceptions instead of GoogleJsonResponseExceptions
      throw new RawlsExceptionWithErrorReport(
        ErrorReport(StatusCodes.getForKey(gjre.getStatusCode).getOrElse(StatusCodes.InternalServerError),
                    gjre.getMessage
        )
      )
    case report: RawlsExceptionWithErrorReport =>
      throw report // don't rewrap these, just rethrow
    case ex: Exception =>
      throw new RawlsExceptionWithErrorReport(
        ErrorReport(StatusCodes.InternalServerError, s"Unexpected error: ${ex.getMessage}", ex)
      )
  }

}


text:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <title>CMAKE_FIND_APPBUNDLE — CMake 3.8.1 Documentation</title>

    <link rel="stylesheet" href="../_static/cmake.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />

    <link rel="shortcut icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="CMAKE_FIND_FRAMEWORK" href="CMAKE_FIND_FRAMEWORK.html" />
    <link rel="prev" title="CMAKE_SYSROOT" href="CMAKE_SYSROOT.html" />

Navigation

          index

          next |

          previous |

    CMake »

    3.8.1 Documentation »

cmake-variables(7) »

CMAKE_FIND_APPBUNDLE¶

This variable affects how find_* commands choose between
OS X Application Bundles and unix-style package components.

On Darwin or systems supporting OS X Application Bundles, the
CMAKE_FIND_APPBUNDLE variable can be set to empty or
one of the following:

FIRST

Try to find application bundles before standard programs.
This is the default on Darwin.

LAST

Try to find application bundles after standard programs.

ONLY

Only try to find application bundles.

NEVER

Never try to find application bundles.

Previous topic

CMAKE_SYSROOT

Next topic

CMAKE_FIND_FRAMEWORK

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">

<input type="text" name="q" />

<input type="submit" value="Go" />

      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>

Navigation

          index

          next |

          previous |

    CMake »

    3.8.1 Documentation »

cmake-variables(7) »

        © Copyright 2000-2017 Kitware, Inc. and Contributors.
      Created using Sphinx 1.5.2.


text:
#include "library/dash/mdat_contents.h"

#include <string>

#include "library/utilities.h"

namespace dash2hls {
// See ISO 14495-12 for details.
//
// Mdat is the raw samples concatenated without any markers or framing.
// Other boxes are required to find the starts and stops of samples.
size_t MdatContents::Parse(const uint8_t* buffer, size_t length) {
  raw_data_ = buffer;
  raw_data_length_ = length;
  return length;
}

std::string MdatContents::PrettyPrint(std::string indent) const {
  std::string result = BoxContents::PrettyPrint(indent);
  result += " " + PrettyPrintValue(raw_data_length_) + " bytes";
  return result;
}
}  // namespace dash2hls


text:
package jj2000.j2k.entropy.decoder;

import jj2000.j2k.entropy.decoder.*;
import jj2000.j2k.entropy.*;
import jj2000.j2k.io.*;
import jj2000.j2k.util.*;
import java.io.*;

/**
 * This class implements the MQ arithmetic decoder. It is implemented using
 * the software conventions decoder for better performance (i.e. execution
 * time performance). The initial states for each context of the MQ-coder are
 * specified in the constructor.
 *
 */

// A trick to test for increased speed: merge the Qe and mPS into 1 thing by
// using the sign bit of Qe to signal mPS (positive-or-0 is 0, negative is 1),
// and doubling the Qe, nMPS and nLPS tables. This gets rid of the swicthLM
// table since it can be integrated as special cases in the doubled nMPS and
// nLPS tables. See the JPEG book, chapter 13. The decoded decision can be
// calculated as (q>>>31).

public class MQDecoder {

    /** The data structures containing the probabilities for the LPS */
    final static
        int qe[]={0x5601, 0x3401, 0x1801, 0x0ac1, 0x0521, 0x0221, 0x5601,
                  0x5401, 0x4801, 0x3801, 0x3001, 0x2401, 0x1c01, 0x1601,
                  0x5601, 0x5401, 0x5101, 0x4801, 0x3801, 0x3401, 0x3001,
                  0x2801, 0x2401, 0x2201, 0x1c01, 0x1801, 0x1601, 0x1401,
                  0x1201, 0x1101, 0x0ac1, 0x09c1, 0x08a1, 0x0521, 0x0441,
                  0x02a1, 0x0221, 0x0141, 0x0111, 0x0085, 0x0049, 0x0025,
                  0x0015, 0x0009, 0x0005, 0x0001, 0x5601 };

    /** The indexes of the next MPS */
    final static
        int nMPS[]={ 1 , 2, 3, 4, 5,38, 7, 8, 9,10,11,12,13,29,15,16,17,
                     18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,
                     35,36,37,38,39,40,41,42,43,44,45,45,46 };

    /** The indexes of the next LPS */
    final static
        int nLPS[]={ 1 , 6, 9,12,29,33, 6,14,14,14,17,18,20,21,14,14,15,
                     16,17,18,19,19,20,21,22,23,24,25,26,27,28,29,30,31,
                     32,33,34,35,36,37,38,39,40,41,42,43,46 };

    /** Whether LPS and MPS should be switched */
    final static
        int switchLM[]={ 1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,
                         0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };

    /** The ByteInputBuffer used to read the compressed bit stream. */
    ByteInputBuffer in;

    /** The current most probable signal for each context */
    int[] mPS;

    /** The current index of each context */
    int[] I;

    /** The current bit code */
    int c;

    /** The bit code counter */
    int cT;

    /** The current interval */
    int a;

    /** The last byte read */
    int b;

    /** Flag indicating if a marker has been found */
    boolean markerFound;

    /** The initial state of each context */
    final int initStates[];

    /**
     * Instantiates a new MQ-decoder, with the specified number of contexts and
     * initial states. The compressed bytestream is read from the 'iStream'
     * object.
     *
     * @param iStream the stream that contains the coded bits
     *
     * @param nrOfContexts The number of contexts used
     *
     * @param initStates The initial state for each context. A reference is
     * kept to this array to reinitialize the contexts whenever 'reset()' or
     * 'resetCtxts()' is called.
     *
     *
     *
     */
    public MQDecoder(ByteInputBuffer iStream, int nrOfContexts,
                     int initStates[]){
        in = iStream;

        // Default initialization of the statistics bins is MPS=0 and
        // I=0
        I=new int[nrOfContexts];
        mPS=new int[nrOfContexts];
        // Save the initial states
        this.initStates = initStates;

        // Initialize
        init();

        // Set the contexts
        resetCtxts();
    }

    /**
     * Decodes 'n' symbols from the bit stream using the same context
     * 'ctxt'. If possible the MQ-coder speedup mode will be used to speed up
     * decoding. The speedup mode is used if Q (the LPS probability for 'ctxt'
     * is low enough) and the A and C registers permit decoding several MPS
     * symbols without renormalization.
     *
     *
Speedup mode should be used when decoding long runs of MPS with high
     * probability with the same context.
     *
     *
This methiod will return the decoded symbols differently if speedup
     * mode was used or not. If true is returned, then speedup mode was used
     * and the 'n' decoded symbols are all the same and it is returned ain
     * bits[0] only. If false is returned then speedup mode was not used, the
     * decoded symbols are probably not all the same and they are returned in
     * bits[0], bits[1], ... bits[n-1].
     *
     * @param bits The array where to put the decoded symbols. Must be of
     * length 'n' or more.
     *
     * @param ctxt The context to use in decoding the symbols.
     *
     * @param n The number of symbols to decode.
     *
     * @return True if speedup mode was used, false if not. If speedup mode
     * was used then all the decoded symbols are the same and its value is
     * returned in 'bits[0]' only (not in bits[1], bits[2], etc.).
     *
     *
     * */
    public final boolean fastDecodeSymbols(int[] bits, int ctxt, int n) {
        int q;   // LPS probability for context
        int idx; // Index of current state
        int la;  // cache for A register
        int i;   // counter

        idx = I[ctxt];
        q = qe[idx];

        // This is a first attempt to implement speedup mode, it is probably
        // not the most efficient way of doing it.

        if ((q<0x4000) && (n <= (a-(c>>>16)-1)/q) &&
            (n <= (a-0x8000)/q+1)) {
            // Q is small enough. There will be no modification of C that
            // affects decoding, and Q can be substracted from A several
            // times. We will decode all MPS.
            a -= n*q;
            if (a >= 0x8000) { // No renormalization needed
                bits[0] = mPS[ctxt];
                return true; // Done, used speedup mode
            }
            else { // renormalization needed
                I[ctxt] = nMPS[idx];
                // Renormalize (MPS: no need for while loop)
                if (cT == 0)
                    byteIn();
                a <<= 1;
                c <<= 1;
                cT--;
                // End renormalization
                bits[0] = mPS[ctxt];
                return true; // Done, used speedup mode
            }
        }
        else { // Normal mode
            la = a; // cache A register
            for (i=0; i<n; i++) {
                la -= q;
                if ((c>>>16) < la) {
                    if(la >= 0x8000){
                        bits[i] = mPS[ctxt];
                    }
                    else {
                        // -- MPS Exchange
                        if(la >= q){
                            bits[i] = mPS[ctxt];
                            idx = nMPS[idx];
                            q = qe[idx];
                            // I[ctxt] set at end of loop
                            // -- Renormalize (MPS: no need for while loop)
                            if(cT==0)
                                byteIn();
                            la<<=1;
                            c<<=1;
                            cT--;
                            // -- End renormalization
                        }
                        else{
                            bits[i] = 1-mPS[ctxt];
                            if(switchLM[idx]==1)
                                mPS[ctxt] = 1-mPS[ctxt];
                            idx =  nLPS[idx];
                            q = qe[idx];
                            // I[ctxt] set at end of loop
                            // -- Renormalize
                            do{
                                if(cT==0)
                                    byteIn();
                                la<<=1;
                                c<<=1;
                                cT--;
                            }while(la < 0x8000);
                            // -- End renormalization
                        }
                        // -- End MPS Exchange
                    }
                }
                else {
                    c -= (la<<16);
                    // -- LPS Exchange
                    if(la < q){
                        la = q;
                        bits[i] = mPS[ctxt];
                        idx = nMPS[idx];
                        q = qe[idx];
                        // I[ctxt] set at end of loop
                        // -- Renormalize (MPS: no need for while loop)
                        if(cT==0)
                            byteIn();
                        la<<=1;
                        c<<=1;
                        cT--;
                        // -- End renormalization
                    }
                    else {
                        la = q;
                        bits[i] = 1-mPS[ctxt];
                        if(switchLM[idx] == 1)
                            mPS[ctxt] = 1-mPS[ctxt];
                        idx =  nLPS[idx];
                        q = qe[idx];
                        // I[ctxt] set at end of loop
                        // -- Renormalize
                        do{
                            if(cT==0)
                                byteIn();
                            la<<=1;
                            c<<=1;
                            cT--;
                        } while (la < 0x8000);
                        // -- End renormalization
                    }
                    // -- End LPS Exchange
                }
            }
            a = la;           // save cached A register
            I[ctxt] = idx;    // save current index for context
            return false;     // done, did not use speedup mode
        } // End normal mode
    }

    /**
     * This function performs the arithmetic decoding. The function receives
     * an array in which to put the decoded symbols and an array of contexts
     * with which to decode them.
     *
     *
Each context has a current MPS and an index describing what the
     * current probability is for the LPS. Each bit is decoded and if the
     * probability of the LPS exceeds .5, the MPS and LPS are switched.
     *
     * @param bits The array where to place the decoded symbols. It should be
     * long enough to contain 'n' elements.
     *
     * @param cX The context to use in decoding each symbol.
     *
     * @param n The number of symbols to decode
     *
     *
     */
    public final void decodeSymbols(int[] bits, int[] cX, int n){
        int q;
        int ctxt;
        int la; // cache for A register value
        int index;
        int i;

        // NOTE: (a < 0x8000) is equivalent to ((a & 0x8000)==0)
        // since 'a' is always less than or equal to 0xFFFF

        // NOTE: conditional exchange guarantees that A for MPS is
        // always greater than 0x4000 (i.e. 0.375)
        // => one renormalization shift is enough for MPS
        // => no need to do a renormalization while loop for MPS

        for (i=0; i<n; i++) {
            ctxt = cX[i];

            index = I[ctxt];
            q = qe[index];

            a -= q;
            if ((c>>>16) = 0x8000){
                    bits[i] = mPS[ctxt];
                }
                else {
                    la = a;
                    // -- MPS Exchange
                    if(la >= q){
                        bits[i] = mPS[ctxt];
                        I[ctxt] = nMPS[index];
                        // -- Renormalize (MPS: no need for while loop)
                        if(cT==0)
                            byteIn();
                        la<<=1;
                        c<<=1;
                        cT--;
                        // -- End renormalization
                    }
                    else{
                        bits[i] = 1-mPS[ctxt];
                        if(switchLM[index]==1)
                            mPS[ctxt] = 1-mPS[ctxt];
                        I[ctxt] = nLPS[index];
                        // -- Renormalize
                        do{
                            if(cT==0)
                                byteIn();
                            la<<=1;
                            c<<=1;
                            cT--;
                        }while(la < 0x8000);
                        // -- End renormalization
                    }
                    // -- End MPS Exchange
                    a = la;
                }
            }
            else {
                la = a;
                c -= (la<<16);
                // -- LPS Exchange
                if(la < q){
                    la = q;
                    bits[i] = mPS[ctxt];
                    I[ctxt] = nMPS[index];
                    // -- Renormalize (MPS: no need for while loop)
                    if(cT==0)
                        byteIn();
                    la<<=1;
                    c<<=1;
                    cT--;
                    // -- End renormalization
                }
                else {
                    la = q;
                    bits[i] = 1-mPS[ctxt];
                    if(switchLM[index] == 1)
                        mPS[ctxt] = 1-mPS[ctxt];
                    I[ctxt] = nLPS[index];
                    // -- Renormalize
                    do{
                        if(cT==0)
                            byteIn();
                        la<<=1;
                        c<<=1;
                        cT--;
                    } while (la < 0x8000);
                    // -- End renormalization
                }
                // -- End LPS Exchange

                a = la;
            }
        }
    }

    /**
     * Arithmetically decodes one symbol from the bit stream with the given
     * context and returns its decoded value.
     *
     *
Each context has a current MPS and an index describing what the
     * current probability is for the LPS. Each bit is encoded and if the
     * probability of the LPS exceeds .5, the MPS and LPS are switched.
     *
     * @param context The context to use in decoding the symbol
     *
     * @return The decoded symbol, 0 or 1.
     *
     *
     */
    public final int decodeSymbol(int context){
        int q;
        int la;
        int index;
        int decision;

        index = I[context];
        q = qe[index];

        // NOTE: (a < 0x8000) is equivalent to ((a & 0x8000)==0)
        // since 'a' is always less than or equal to 0xFFFF

        // NOTE: conditional exchange guarantees that A for MPS is
        // always greater than 0x4000 (i.e. 0.375)
        // => one renormalization shift is enough for MPS
        // => no need to do a renormalization while loop for MPS

        a -= q;
        if ((c>>>16) = 0x8000){
                decision = mPS[context];
            }
            else {
                la = a;
                // -- MPS Exchange
                if(la >= q){
                    decision = mPS[context];
                    I[context] = nMPS[index];
                    // -- Renormalize (MPS: no need for while loop)
                    if(cT==0)
                        byteIn();
                    la<<=1;
                    c<<=1;
                    cT--;
                    // -- End renormalization
                }
                else{
                    decision = 1-mPS[context];
                    if(switchLM[index]==1)
                        mPS[context] = 1-mPS[context];
                    I[context] = nLPS[index];
                    // -- Renormalize
                    do{
                        if(cT==0)
                            byteIn();
                        la<<=1;
                        c<<=1;
                        cT--;
                    }while(la < 0x8000);
                    // -- End renormalization
                }
                // -- End MPS Exchange
                a = la;
            }
        }
        else {
            la = a;
            c -= (la<<16);
            // -- LPS Exchange
            if(la < q){
                la = q;
                decision = mPS[context];
                I[context] = nMPS[index];
                // -- Renormalize (MPS: no need for while loop)
                if(cT==0)
                    byteIn();
                la<<=1;
                c<<=1;
                cT--;
                // -- End renormalization
            }
            else {
                la = q;
                decision = 1-mPS[context];
                if(switchLM[index] == 1)
                    mPS[context] = 1-mPS[context];
                I[context] = nLPS[index];
                // -- Renormalize
                do{
                    if(cT==0)
                        byteIn();
                    la<<=1;
                    c<<=1;
                    cT--;
                } while (la < 0x8000);
                // -- End renormalization
            }
            // -- End LPS Exchange

            a = la;
        }
        return decision;
    }

    /**
     * Checks for past errors in the decoding process using the predictable
     * error resilient termination. This works only if the encoder used the
     * predictable error resilient MQ termination, otherwise it reports wrong
     * results. If an error is detected it means that the MQ bit stream has
     * been wrongly decoded or that the MQ terminated segment length is too
     * long. If no errors are detected it does not necessarily mean that the
     * MQ bit stream has been correctly decoded.
     *
     * @return True if errors are found, false otherwise.
     * */
    public boolean checkPredTerm() {
        int k;  // Number of bits that where added in the termination process
        int q;

        // 1) if everything has been OK, 'b' must be 0xFF if a terminating
        // marker has not yet been found
        if (b != 0xFF && !markerFound) return true;

        // 2) if cT is not 0, we must have already reached the terminating
        // marker
        if (cT != 0 && !markerFound) return true;

        // 3) If cT is 1 there where no spare bits at the encoder, this is all
        // that we can check
        if (cT == 1) return false;

        // 4) if cT is 0, then next byte must be the second byte of a
        // terminating marker (i.e. larger than 0x8F) if the terminating
        // marker has not been reached yet
        if (cT == 0) {
            if (!markerFound) {
                // Get next byte and check
                b=in.read()&0xFF;
                if (b <= 0x8F) return true;
            }
            // Adjust cT for last byte
            cT = 8;
        }

        // 5) Now we can calculate the number 'k' of bits having error
        // resilience information, which is the number of bits left to
        // normalization in the C register, minus 1.
        k = cT-1;

        // 6) The predictable termination policy is as if an LPS interval was
        // coded that caused a renormalization of 'k' bits, before the
        // termination marker started

        // We first check if an LPS is decoded, that causes a renormalization
        // of 'k' bits. Worst case is smallest LPS probability 'q' that causes
        // a renormalization of 'k' bits.
        q = 0x8000>>k;

        // Check that we can decode an LPS interval of probability 'q'
        a -= q;
        if ((c>>>16) < a) {
            // Error: MPS interval decoded
            return true;
        }
        // OK: LPS interval decoded
        c -= (a<<16);
        // -- LPS Exchange
        // Here 'a' can not be smaller than 'q' because the minimum value
        // for 'a' is 0x8000-0x4000=0x4000 and 'q' is set to a value equal
        // to or smaller than that.
        a = q;
        // -- Renormalize
        do{
            if(cT==0) byteIn();
            a<<=1;
            c<<=1;
            cT--;
        } while (a < 0x8000);
        // -- End renormalization
        // -- End LPS Exchange

        // 7) Everything seems OK, we have checked the C register for the LPS
        // symbols and ensured that it is followed by bits synthetized by the
        // termination marker.
        return false;
    }

    /**
     * This function gets one byte of compressed bits from the in-stream.
     * the byte is added to c. If the byte is 0xFF and the next byte is greater
     * than 0x8F, the byte after 0xFF is a marker.
     *
     *
     *
     */
    private void byteIn(){
        if(!markerFound){
            if(b==0xFF){
                b=in.read()&0xFF; // Convert EOFs (-1) to 0xFF

                if(b>0x8F){
                    markerFound=true;
                    // software-convention decoder: c unchanged
                    cT=8;
                }else{
                    c += 0xFE00 - (b<<9);
                    cT=7;
                }
            }else{
                b=in.read()&0xFF; // Convert EOFs (-1) to 0xFF
                c += 0xFF00 - (b<<8);
                cT=8;
            }
        }
        else{
            // software-convention decoder: c unchanged
            cT=8;
        }
    }

    /**
      * Returns the number of contexts in the arithmetic coder.
      *
      * @return The number of contexts
      *
      *
      **/
    public final int getNumCtxts(){
        return I.length;
    }

    /**
     * Resets a context to the original probability distribution.
     *
     * @param c The number of the context (it starts at 0).
     *
     *
     *
     */
    public final void resetCtxt(int c){
        I[c] = initStates[c];
        mPS[c] = 0;
    }

    /**
     * Resets a context to the original probability distribution. The
     * original probability distribution depends on the actual
     * implementation of the arithmetic coder or decoder.
     *
     * @param c The index of the context (it starts at 0).
     *
     *
     *
     */
    public final void resetCtxts(){
        System.arraycopy(initStates,0,I,0,I.length);
        ArrayUtil.intArraySet(mPS,0);
    }

    /**
     * Resets the MQ decoder to start a new segment. This is like recreating a
     * new MQDecoder object with new input data.
     *
     * @param buf The byte array containing the MQ encoded data. If null the
     * current byte array is assumed.
     *
     * @param off The index of the first element in 'buf' to be decoded. If
     * negative the byte just after the previous segment is assumed, only
     * valid if 'buf' is null.
     *
     * @param len The number of bytes in 'buf' to be decoded. Any subsequent
     * bytes are taken to be 0xFF.
     *
     *
     * */
    public final void nextSegment(byte buf[], int off, int len) {
        // Set the new input
        in.setByteArray(buf,off,len);
        // Reinitialize MQ
        init();
    }

    /**
     * Returns the underlying 'ByteInputBuffer' from where the MQ
     * coded input bytes are read.
     *
     * @return The underlying ByteInputBuffer.
     *
     * */
    public ByteInputBuffer getByteInputBuffer() {
        return in;
    }

    /**
     * Initializes the state of the MQ coder, without modifying the current
     * context states. It sets the registers (A,C,B) and the "marker found"
     * state to the initial state, to start the decoding of a new segment.
     *
     *
To have a complete reset of the MQ (as if a new MQDecoder object was
     * created) 'resetCtxts()' should be called after this method.
     *
     *
     * */
    private void init() {
        // --- INITDEC
        markerFound = false;

        // Read first byte
        b=in.read()&0xFF;

        // Software conventions decoder
        c=(b^0xFF)<<16;
        byteIn();
        c=c<<7;
        cT=cT-7;
        a=0x8000;

        // End of INITDEC ---
    }
}


text:
/*jslint jquery:true */
/**
 * playingCards is a standard card deck library
 * This can be used to play standard card games (which will be additional rule modules attached to this set)
 *
 * usage: var cardDeck = new playingCards(conf);
 * override defaults for playingCards() and for card() with
 *    playingCards.defaults
 *    playingCards.card.defaults
 *
 * @author Copyright (c) 2010 Adam Eivy (antic | atomantic)
 * @license Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

if (Array.indexOf === undefined) {
    // doens't exist in oldIE
    /* Finds the index of the first occurence of item in the array, or -1 if not found */
    Array.prototype.indexOf = function(v) {
        for (var i = 0; i < this.length; ++i) {
            if (this[i] === v) {
                return i;
            }
        }
        return - 1;
    };
}
 (function(window,document,undefined){

    /**
     * The playing card library core object
     *
     * @param obj conf Configuration option overrides
     *
     * @return obj an instance of the constructed library object (deck of cards)
     */
    var playingCards = window.playingCards = function(conf) {
        var c = objExtend(playingCards.defaults, conf);
        if (! (this instanceof playingCards)) {
            // in jquery mode
            c.el = $(this); // capture the context (this will be the cardTable/Deck element)
            return new playingCards(c);
        }
        this.conf = c;
        this.init();
        if (this.conf.startShuffled) {
            this.shuffle(5);
        }
        return this;
    };
    /**
     * initializer - builds the deck
     */
    playingCards.prototype.init = function() {
        this.cards = [];
        var o = this.conf,
            l,i,s,r,j;
        // populate draw pile
        for (i = 0; i < o.decks; i++) {
            // standard
            for (s in o.suits) {
                for (r in o.ranks) {
                    l = this.cards.length;
                    this.cards[l] = new playingCards.card(r, o.ranks[r], s, o.suits[s]);
                }
            }
            // jokers
            for (j = 0; j < o.jokers; j++) {
                l = this.cards.length;
                // suit will always be 1 or 2
                this.cards[l] = new playingCards.card("N", o.jokerText, (j % 2) + 1, '');
            }
        }
    };
    // TODO: create more methods:
    // playingCards.prototype.order (set to out-of-box ordering)
    // -- do we want other special formations (like trick deck ordering systems that deal perfect hands)?
    // -- probably going to leave this as an extension option
    /**
     * draw a card
     * @return mixed (object|null) A card object (if a card is available)
     */
    playingCards.prototype.draw = function() {
        return this.cards.length > 0 ? this.cards.pop() : null;
    };
    playingCards.prototype.flip = function() {
        console.log('hello');
        return this.cards.length > 0 ? this.cards.slice() : null;

    };
    /**
     * add a card to the top of the deck
     */
    playingCards.prototype.addCard = function(card) {
        this.cards.push(card);
    };
    /**
     * get the number of cards remaining in the deck
     * (easy enough just to call cardObject.cards.length but hey)
     */
    playingCards.prototype.count = function() {
        return this.cards.length;
    };
    /**
     * shuffle the deck
     *
     * @param int n The number of times to shuffle (defaults to 5)
     */
    playingCards.prototype.shuffle = function(n) {
        if (!n) {
            n = 5;
        }
        var l = this.cards.length,
            r,tmp,i,j;

        for (i = 0; i < n; i++) {
            for (j = 0; j < l; j++) {
                r = Math.floor(Math.random() * l);
                tmp = this.cards[j];
                this.cards[j] = this.cards[r];
                this.cards[r] = tmp;
            }
        }
    };

    playingCards.prototype.orderByRank = function() {
        this.cards.sort(compareRank);
    };

    playingCards.prototype.orderBySuit = function() {
        this.init();
    };

    /*
     * requires jquery (currently)
     * TODO: put this in a UI extension pack along with all the other demo methods
     */
    playingCards.prototype.spread = function(dest) {
        if (!this.conf.el && !dest) {
            return false;
        }
        var to = this.conf.el || dest,
            l = this.cards.length,
            i;
        to.html('');
        // clear (just a demo)
        for (i = 0; i < l; i++) {
            to.append(this.cards[i].getHTML());
        }
    };
    /**
     * configuration defaults
     */
    playingCards.defaults = {
        "decks": 1,
        // TODO: enable 'font' option -- loading cards.ttf
        "renderMode": 'css',
        // For a coustom " of "-String
        "ofString": " of ",
        "startShuffled": true,
        "jokers": 2,
        "jokerText": "Joker",
        "ranks": {
            "2": "Two",
            "3": "Three",
            "4": "Four",
            "5": "Five",
            "6": "Six",
            "7": "Seven",
            "8": "Eight",
            "9": "Nine",
            "10": "Ten",
            "J": "Jack",
            "Q": "Queen",
            "K": "King",
            "A": "Ace"
        },
        "suits": {
            "S": "Spades",
            "D": "Diamonds",
            "C": "Clubs",
            "H": "Hearts"
        }
    };

    /**
     * create a playing card
     *
     * @param string rank The numeric or letter value of the card (short value)
     * @param string rankString The full text representation of the rank (localized)
     * @param string suit The letter value of the suite (short value)
     * @param string suitString The full text representation of the suit (localized)
     * @param obj conf Overriding configuration
     *
     * @return object The card object
     */
    playingCards.card = function(rank, rankString, suit, suitString, conf) {
        if (! (this instanceof playingCards.card)) {
            return new playingCards.card(rank, rankString, suit, suitString, conf);
        }

        this.conf = objExtend(playingCards.card.defaults, conf);

        if (suit === undefined) {
            //Arguments are rank, suit
            suit = rankString;
            rankString = playingCards.defaults.ranks[rank];
            suitString = playingCards.defaults.suits[suit];
        }

        this.rank = rank;
        this.rankString = rankString;
        this.suit = suit;
        this.suitString = suitString;
        return this;
    };
    /**
     * configuration defaults
     */
    playingCards.card.defaults = {
        "singleFace": false
        // false will use a different image for each suit/face, true will use diamond image for all
    };
    /**
     * get the text representation of the card
     */
    playingCards.card.prototype.toString = function() {
        return this.suitString !== "" ? this.rankString + playingCards.defaults.ofString + this.suitString: this.rankString;
    };

    /**
     * Simple object extend to override default settings
     */
    function objExtend(o, ex) {
        if (!ex) {
            return o;
        }
        for (var p in ex) {
            o[p] = ex[p];
        }
        return o;
    }

    /**
     * Compare functions
     */
    function compareRank(a, b) {
        var intRegex = /^\d+$/;

        if (a.rank == b.rank)                       return 0;
        if (a.rank == "N")                          return 1;
        if (b.rank == "N")                          return -1;
        if (a.rank == "A")                          return 1;
        if (b.rank == "A")                          return -1;
        if (!isNaN(a.rank - b.rank))                return a.rank - b.rank;
        if (a.rank == "K" && b.rank == "J")         return 1;
        if (a.rank == "J" && b.rank == "K")         return -1;
        if (a.rank == "K" && b.rank == "Q")         return 1;
        if (a.rank == "Q" && b.rank == "K")         return -1;
        if (a.rank == "Q" && b.rank == "J")         return 1;
        if (a.rank == "J" && b.rank == "Q")         return -1;
        if (a.rank == "K" && intRegex.test(b.rank)) return 1;
        if (a.rank == "Q" && intRegex.test(b.rank)) return 1;
        if (a.rank == "J" && intRegex.test(b.rank)) return 1;
        if (intRegex.test(a.rank) && b.rank == "K") return -1;
        if (intRegex.test(a.rank) && b.rank == "Q") return -1;
        if (intRegex.test(a.rank) && b.rank == "J") return -1;
    }

})(this,this.document);


text:
#include "ide.h"

struct GatherLinksIterator : RichText::Iterator {
	Index<String> link;

	virtual bool operator()(int pos, const RichPara& para)
	{
		for(int i = 0; i < para.GetCount(); i++) {
			String l = para[i].format.link;
			if(!IsNull(l))
				link.FindAdd(l);
		}
		return false;
	}
};

void GatherLinks(Index<String>& link, const char *topic)
{
	if(link.Find(topic) < 0) {
		Topic p = GetTopic(topic);
		if(IsNull(p.text))
			return;
		link.Add(topic);
		RichText txt = ParseQTF(p.text);
		SyncTopicFile(txt, topic, ":ide:", p.title);
		GatherLinksIterator ti;
		txt.Iterate(ti);
		for(int i = 0; i < ti.link.GetCount(); i++)
			GatherLinks(link, ti.link[i]);
	}
}

Index<String> TopicCtrl::idelink;

void TopicCtrl::ScanDirForTpp(const char *dir, const String& rel,
                              Index<String>& donepackage, Index<String>& lang_list)
{
	TopicLink tl;
	for(FindFile pff(AppendFileName(dir, "*.*")); pff; pff.Next()) {
		if(pff.IsFolder() && *pff.GetName() != '.') {
			String pdir = AppendFileName(dir, pff.GetName());
			tl.package = rel + pff.GetName();
			if(donepackage.Find(tl.package) < 0) {
				donepackage.Add(tl.package);
				for(FindFile ff(AppendFileName(pdir, "*.tpp")); ff; ff.Next())
					if(ff.IsFolder()) {
						tl.group = GetFileTitle(ff.GetName());
						String dir = AppendFileName(pdir, ff.GetName());
						for(FindFile ft(AppendFileName(dir, "*.tpp")); ft; ft.Next())
							if(ft.IsFile()) {
								tl.topic = GetFileTitle(ft.GetName());
								int q = tl.topic.ReverseFind('$');
								String l;
								if(q >= 0) {
									l = ToUpper(tl.topic.Mid(q + 1));
									lang_list.FindAdd(l);
								}
								map.GetAdd(tl.package).GetAdd(tl.group).FindAdd(tl.topic);
							}
					}
			}
			ScanDirForTpp(pdir, tl.package + '/', donepackage, lang_list);
		}
	}
}

int map_serial, topic_serial;

void TopicCtrl::LoadMap()
{
	map.Clear();
	lang_list.Clear();
	Vector<String> upp = GetUppDirs();
	Index<String> donepackage, lang_list;
	for(int i = 0; i < upp.GetCount(); i++)
		ScanDirForTpp(upp[i], String(), donepackage, lang_list);
	Vector<String> l = lang_list.PickKeys();
	Sort(l);
	String lng = ~lang;
	lang.Clear();
	lang.Add("All");
	for(int i = 0; i < l.GetCount(); i++)
		lang.Add(l[i]);
	if(lng.GetCount() && lang.Find(lng))
		lang <<= lng;
	else
	if(lang.Find("EN-US"))
		lang <<= "EN-US";
	else
	if(lang.GetCount())
		lang.SetIndex(0);
}

static String sTopicHome = "\3topic://ide/app/index$en-us";
static String s_idehelp = "TheIDE help";
static String s_usedpackages = "Used packages";
static String s_otherpackages = "Other packages";
static String s_documents = "Documents";
static String s_reference = "Reference";
static String s_implementation = "Implementation";

inline int sFindN(const String& s)
{
	if(s == s_idehelp) return 0;
	if(s == s_usedpackages) return 1;
	if(s == s_otherpackages) return 2;
	if(s == s_documents) return 3;
	if(s == s_reference) return 4;
	if(s == s_implementation) return 5;
	return 6;
}

int TopicSortOrder(const Value& k1, const Value& v1, const Value& k2, const Value& v2)
{
	String s1 = v1;
	String s2 = v2;
	bool bk1 = IsNull(k1);
	bool bk2 = IsNull(k2);
	int q = (int)bk1 - (int)bk2;
	if(q) return q;
	if(bk1) {
		int q = sFindN(s1) - sFindN(s2);
		if(q) return q;
	}
	return StdValueCompare(v1, v2);
}

void TopicCtrl::SyncDocTree()
{
	if(map_serial != topic_serial) {
		LoadMap();
		map_serial = topic_serial;
	}

	Vector<String> ss = Split((String)~search, ' ');

	if(ss.GetCount() && !SyncRefsFinished) {
		SyncRefsShowProgress = true;
		return;
	}

	Vector<String> sdx;
	for(int i = 0; i < ss.GetCount(); i++)
		sdx.Add(ToUtf8(ToLower(FromUtf8(ss[i]))));

	ClearTree();

	String hdx = sTopicHome.Mid(1);
	if(idelink.GetCount() == 0)
		GatherLinks(idelink, hdx);
	int ide = 0;
	bool idefirst = true;
	if(MatchTopicLink(hdx, sdx)) {
		ide = AddTree(0, IdeImg::Package(), "\3" + hdx, s_idehelp);
		idefirst = false;
	}
	for(int i = 0; i < idelink.GetCount(); i++) {
		if(idelink[i] != hdx && MatchTopicLink(idelink[i], sdx)) {
			if(idefirst) {
				ide = AddTree(0, IdeImg::Package(), "\3" + hdx, s_idehelp);
				idefirst = false;
			}
			AddTree(ide, TopicImg::Topic(), "\3" + idelink[i], GetTopic(idelink[i]).title);
		}
	}

	Index<String> used;
	const Workspace& wspc = GetIdeWorkspace();
	for(int i = 0; i < wspc.GetCount(); i++)
		used.Add(wspc[i]);

	int usid = 0;
	bool usedfirst = true;
	int otid = 0;
	bool otherfirst = true;

	String lng = ~lang;
	for(int i = 0; i < map.GetCount(); i++) {
		TopicLink tl;
		tl.package = map.GetKey(i);
		bool packagefirst = true;
		int pid = 0;
		VectorMap<String, Index<String> >& group = map[i];
		for(int i = 0; i < group.GetCount(); i++) {
			tl.group = group.GetKey(i);
			if(all || tl.group == "src" || tl.group == "srcdoc" || tl.group == "srcimp") {
				String n = tl.group;
				if(n == "src")
					n = s_reference;
				if(n == "srcdoc")
					n = s_documents;
				if(n == "srcimp")
					n = s_implementation;
				int gid = 0;
				bool groupfirst = true;
				const Index<String>& topic = group[i];
				for(int i = 0; i < topic.GetCount(); i++) {
					tl.topic = topic[i];
					int q = tl.topic.ReverseFind('$');
					String l;
					if(q >= 0)
						l = ToUpper(tl.topic.Mid(q + 1));
					String link = TopicLinkString(tl);
					if(idelink.Find(link) < 0 && MatchTopicLink(link, sdx) && (lng == "All" || lng == l)) {
						int pd;
						if(used.Find(tl.package) >= 0) {
							if(usedfirst) {
								usid = AddTree(0, IdeImg::Package(), Null, s_usedpackages);
								usedfirst = false;
							}
							pd = usid;
						}
						else {
							if(otherfirst) {
								otid = AddTree(0, IdeImg::Package(), Null, s_otherpackages);
								otherfirst = false;
							}
							pd = otid;
						}
						if(packagefirst) {
							pid = AddTree(pd, TopicImg::Package(), Null, tl.package);
							packagefirst = false;
						}
						if(groupfirst) {
							gid = AddTree(pid, Null, Null, n);
							groupfirst = false;
						}
						String p = TopicLinkString(tl);
						String t = GetTopicTitle(p);
						AddTree(gid, TopicImg::Topic(), p, t);
					}
				}
			}
		}
	}
	SortTree(0, TopicSortOrder);
	FinishTree();
	if(sdx.GetCount()) {
		OpenDeep();
		CurrentOrHome();
	}
}

Vector<String> GetTypeRefLinks(const String& t, String &label)
{
	const char *tp[] = { "", "::struct", "::class", "::union", "::typedef", "::enum" };
	Vector<String> f;
	for(int i = 0; i < __countof(tp); i++) {
		label = t + tp[i];
		f = GetRefLinks(label);
		if(f.GetCount())
			break;
	}
	return f;
}

String recent_topic;

Topic TopicCtrl::AcquireTopic(const String& t)
{
	recent_topic = t;
	String topic = t;
	internal = (byte)*topic < 32;
	if(*topic == '\3')
		return GetTopic(topic.Mid(1));
	if(topic[0] == ':' && topic[1] == ':') {
		String lbl;
		Vector<String> link = GetTypeRefLinks(topic, lbl);
		if(link.GetCount() == 0)
			return Topic();
		if(link.GetCount() == 1)
			topic = link[0];
		else {
			WithSimpleListLayout<TopWindow> dlg;
			CtrlLayoutOKCancel(dlg, "Choose one of more link targets");
			dlg.list.AddKey();
			dlg.list.AddColumn("Topic");
			for(int i = 0; i < link.GetCount(); i++)
				dlg.list.Add(link[i], GetTopicTitle(link[i]));
			dlg.list.SetCursor(0);
			if(dlg.Run() != IDOK || !dlg.list.IsCursor())
				return Topic();
			topic = dlg.list.GetKey();
		}
		if(lbl.GetCount())
			topic << '#' << lbl;
	}
	TopicLink tl = ParseTopicLink(topic);
	if(!IsNull(tl.package)) {
		String path = AppendFileName(
						AppendFileName(PackageDirectory(tl.package), tl.group + ".tpp"),
						tl.topic + ".tpp");
		Topic t = ReadTopic(LoadFile(path));
		t.label = tl.label;
		tl.label.Clear();
		t.link = TopicLinkString(tl);
		return t;
	}
	return Topic();
}

struct HighlightWords : RichText::Iterator {
	Vector<String> words;
	struct Pos : Moveable<Pos> { int pos, len; };
	Vector<Pos>   pos;

	int FindPattern(const String& x) {
		for(int i = 0; i < words.GetCount(); i++)
			if(x.StartsWith(words[i]))
				return words[i].GetCount();
		return -1;
	}

	virtual bool operator()(int tpos, const RichPara& para) {
		WString text = para.GetText();
		const wchar *s = text;
		for(;;) {
			while(!IsAlpha(*s) && !IsDigit(*s) && *s)
				s++;
			if(*s == '\0')
				break;
			String wb;
			const wchar *b = s;
			while(IsAlpha(*s) || IsDigit(*s))
				wb.Cat(ToUpper(*s++));
			int q = FindPattern(wb);
			if(q >= 0) {
				Pos& p = pos.Add();
				p.pos = int(b - ~text) + tpos;
				p.len = q;
			}
		}
		return false;
	}
};

void TopicCtrl::FinishText(RichText& text)
{
	spos.Clear();
	if(!showwords)
		return;
	Vector<String> ss = Split((String)~search, ' ');

	if(ss.GetCount() == 0)
		return;
	HighlightWords hw;
	hw.words = ss;
	text.Iterate(hw);
	RichText::FormatInfo fi;
	fi.charvalid = RichText::PAPER|RichText::INK;
	fi.paravalid = 0;
	fi.paper = SColorHighlight();
	fi.ink = SColorHighlightText();
	for(int i = 0; i < hw.pos.GetCount(); i++) {
		text.ApplyFormatInfo(hw.pos[i].pos, fi, hw.pos[i].len);
		spos.Add(hw.pos[i].pos);
	}
}

void TopicCtrl::OpenTopic()
{
	WhenTopic();
}

struct SlideShow : TopWindow {
	virtual bool Key(dword key, int count);

	RichTextView   text;
	Vector<String> path;
	int            page;
	int            rp;

	void SetPage();

	SlideShow();
};

bool SlideShow::Key(dword key, int count)
{
	switch(key) {
	case K_ESCAPE:
		Break();
		break;
	case K_LEFT:
	case K_UP:
	case K_PAGEUP:
		page--;
		SetPage();
		break;
	case K_RIGHT:
	case K_DOWN:
	case K_PAGEDOWN:
		page++;
		SetPage();
		break;
	}
	return true;
}

void SlideShow::SetPage()
{
	page = minmax(page, 0, path.GetCount() - 1);
	if(page != rp) {
		rp = page;
		text <<= ReadTopic(LoadFile(path[page])).text;
	}
}

SlideShow::SlideShow()
{
	FullScreen();
	Add(text.SizePos());
	text.NoHyperlinkDecoration();
	text.NoSb();
	text.VCenter();
	text.SetZoom(Zoom(1, 5));
	text.Margins(8);
	rp = -1;
}

void TopicCtrl::SShow()
{
	SlideShow ss;
	TopicLink tl = ParseTopicLink(GetCurrent());
	if(IsNull(tl.package))
		return;
	String folder = AppendFileName(PackageDirectory(tl.package), tl.group + ".tpp");
	FindFile ff(AppendFileName(folder, "*.tpp"));
	Array<String> l;
	while(ff) {
		if(ff.IsFile())
			l.Add(GetFileTitle(ff.GetName()));
		ff.Next();
	}
	if(l.GetCount() == 0)
		return;
	Sort(l);
	for(int i = 0; i < l.GetCount(); i++) {
		if(tl.topic == l[i])
			ss.page = i;
		ss.path.Add(AppendFileName(folder, l[i] + ".tpp"));
	}
	ss.SetPage();
	ss.Run();
	tl.topic = l[ss.page];
	GoTo(TopicLinkString(tl));
}

void TopicCtrl::Search()
{
	int l, h;
	ClearCurrentLink();
	search.GetSelection(l, h);
	SyncDocTree();
	SetBar();
	search.SetFocus();
	search.SetSelection(l, h);
}

void TopicCtrl::SearchWord(const String& s)
{
	search <<= ToUpper(s);
	Search();
}

void TopicCtrl::ShowWords()
{
	showwords = !showwords;
	SetBar();
	GoTo(GetCurrent());
}

void TopicCtrl::All()
{
	all = !all;
	SyncDocTree();
	SetBar();
}

void TopicCtrl::Lang()
{
	SyncDocTree();
	SetBar();
}

bool TopicCtrl::Key(dword key, int count)
{
	if(key == K_ENTER && search.HasFocus()) {
		Search();
		return true;
	}
	return HelpWindow::Key(key, count);
}

void TopicCtrl::FocusSearch()
{
	search.SetFocus();
}

void TopicCtrl::Prev()
{
	if(!Up(spos))
		HelpWindow::Prev();
}

void TopicCtrl::Next()
{
	if(!Down(spos))
		HelpWindow::Next();
}

void  TopicCtrl::BarEx(Bar& bar)
{
	bar.Gap();
	bar.Add(lang, HorzLayoutZoom(60));
	bar.Add("All topics", IdeImg::HelpAll(), THISBACK(All))
	   .Check(all);
	bar.Gap(HorzLayoutZoom(30));
	bar.Add(search, HorzLayoutZoom(300));
	bar.Add(search.GetLength(), "Prev", IdeImg::GoPrev(), THISBACK(Prev));
	bar.Add(search.GetLength(), "Next", IdeImg::GoNext(), THISBACK(Next));

	bar.AddKey(K_CTRL_F, THISBACK(FocusSearch));
/*	bar.Add("Highlight search keywords in topic", IdeImg::ShowWords(), THISBACK(ShowWords))
	   .Check(showwords);*/
	bar.Add(!internal && GetCurrent().StartsWith("topic:"),
	        IdeImg::show(), THISBACK(SShow));
	bar.GapRight();
	bar.Separator();
	bar.Add(!internal && GetCurrent().StartsWith("topic:"),
	        TopicImg::Topic(), THISBACK(OpenTopic));
}

void TopicCtrl::Serialize(Stream& s)
{
	int version = 3;
	s / version;
	if(version < 3) {
		WithDropChoice<EditString> dummy;
		dummy.SerializeList(s);
	}
	if(version >= 1)
		s % showwords;
	if(version >= 2)
		s % all;
}

struct HelpDes : public IdeDesigner {
	TopicCtrl *topic;

	virtual String GetFileName() const              { return HELPNAME; }
	virtual void   Save()                           {}
	virtual void   EditMenu(Bar& menu)              {}
	virtual Ctrl&  DesignerCtrl()                   { return *topic; }
	virtual void   SetFocus()                       { topic->SetFocus(); }

	~HelpDes()                                      { topic->Remove(); }
};

bool IsHelpName(const char *path)
{
	return strcmp(path, HELPNAME) == 0;
}

struct HelpModule : public IdeModule {
	virtual Image FileIcon(const char *path) {
		return IsHelpName(path) ? IdeImg::help() : Null;
	}
	virtual IdeDesigner *CreateDesigner(Ide *ide, const char *path, byte cs) {
		if(IsHelpName(path)) {
			topic_serial++;
			GetRefLinks("");
			ide->doc.SyncDocTree();
			ide->doc.GoTo(Nvl(recent_topic, sTopicHome));
			HelpDes *d = new HelpDes;
			d->topic = &ide->doc;
			return d;
		}
		return NULL;
	}
	virtual void Serialize(Stream& s) {
		s % recent_topic;
	}
};

INITBLOCK {
	RegisterIdeModule(Single<HelpModule>());
}

int CharFilterTopicSearch(int c)
{
	if(c == ' ') return c;
	c = CharFilterDefaultToUpperAscii(c);
	return IsAlNum(c) ? c : 0;
}

TopicCtrl::TopicCtrl()
{
	showwords = true;
	all = false;
	lang <<= THISBACK(Lang);
	lang.Tip("Language"),
	search.NullText("Search", StdFont().Italic(), SColorDisabled());
	search.Tip("Full text search");
	search <<= THISBACK(Search);
	search.SetFilter(CharFilterTopicSearch);
	internal = true;
}

void Ide::ShowTopics()
{
	if(designer && designer->GetFileName() == HELPNAME) {
		CycleFiles();
		tabi = 0;
		return;
	}
	if(doc_serial != TopicEditor::GetSerial()) {
		GetRefLinks("");
		doc.SyncDocTree();
		doc.GoTo(sTopicHome);
		doc_serial = TopicEditor::GetSerial();
	}
	EditFile(HELPNAME);
}

void Ide::SearchTopics()
{
	String s = editor.GetWord();
	GetRefLinks("");
	doc.SyncDocTree();
	doc.GoTo(sTopicHome);
	EditFile(HELPNAME);
	if(s.GetLength())
		doc.SearchWord(s);
}

void Ide::RefreshBrowser()
{
	editor.SyncNavigator();
	doc.SyncDocTree();
}


text:
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'

describe :unboundmethod_to_s, shared: true do
  before :each do
    @from_module = UnboundMethodSpecs::Methods.instance_method(:from_mod)
    @from_method = UnboundMethodSpecs::Methods.new.method(:from_mod).unbind
  end

  it "returns a String" do
    @from_module.send(@method).should be_kind_of(String)
    @from_method.send(@method).should be_kind_of(String)
  end

  it "the String reflects that this is an UnboundMethod object" do
    @from_module.send(@method).should =~ /\bUnboundMethod\b/
    @from_method.send(@method).should =~ /\bUnboundMethod\b/
  end

  it "the String shows the method name, Module defined in and Module extracted from" do
    @from_module.send(@method).should =~ /\bfrom_mod\b/
    @from_module.send(@method).should =~ /\bUnboundMethodSpecs::Mod\b/
    @from_method.send(@method).should =~ /\bUnboundMethodSpecs::Methods\b/
  end
end


text:
<?php
/***************************************************
*************** DB Connection Config ***************
****************************************************
Fill your database connection info into those fields.
*/

$dbConf['user']		= 'test';
$dbConf['password'] = 'test';
$dbConf['dbName'] 	= 'test'; // Database Name
$dbConf['address'] 	= 'localhost'; // Server IP
$dbConf['port']		= '5432'; // Server Port

// The group name that this account member of(for Postgresql)
$dbConf['group']	= 'reader';

/*** DB Type ***
mysql: the test subject is MySQL.
postgre: the test subject is PostgreSQL.

(support mysql 5+, postgreSQL 9, didn't test the other version.)
*/
$dbConf['type']		= 'postgre';

/*** DB Role ***
super: super user of DB server.
replic: DB replication user.
project: individual DB project staff.
app: application user.
unknown: this program will just list the privliege it have.
*/
$dbConf['role']		= 'unknown';

?>


text:
ACCEPTED

#### According to
The Catalogue of Life, 3rd January 2011

#### Published in
Melet. bot. 33. 1832

#### Original name
null

### Remarks
null


text:
Testing for WebWhir is done through [Catch](https://github.com/philsquared/Catch/).

The provided auto-runner script should be sufficient to run the test suite, with perhaps a few modifications for a different platform if necessary.