当前位置: 首页>>代码示例>>PHP>>正文


PHP generate_name函数代码示例

本文整理汇总了PHP中generate_name函数的典型用法代码示例。如果您正苦于以下问题:PHP generate_name函数的具体用法?PHP generate_name怎么用?PHP generate_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了generate_name函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: CreateView

function CreateView($args, $targs)
{
    grokit_assert(\count($args) == 1, 'CreateView supports exactly 1 input');
    $type = $args[0];
    grokit_assert($type->is('array'), 'CreateView cannot create view on non-array type');
    $innerType = $type->get('type');
    $size = $type->get('size');
    $viewType = lookupType('BASE::FixedArrayView', ['type' => $innerType, 'size' => $size]);
    $funcname = generate_name('CreateView_');
    ?>

<?php 
    echo $viewType;
    ?>
 <?php 
    echo $funcname;
    ?>
( const <?php 
    echo $type;
    ?>
 &array ) {
	return <?php 
    echo $viewType;
    ?>
(array.data());
}

<?php 
    return ['kind' => 'FUNCTION', 'name' => $funcname, 'input' => $args, 'result' => $viewType, 'deterministic' => false];
}
开发者ID:gokulp,项目名称:grokit,代码行数:30,代码来源:CreateView.h.php

示例2: Hash

function Hash($args, array $t_args = [])
{
    $funcName = generate_name('Hash_');
    $retType = lookupType('base::BIGINT');
    echo $retType;
    ?>
 <?php 
    echo $funcName;
    ?>
( <?php 
    echo const_typed_ref_args($args);
    ?>
 ) {
    uint64_t hashVal = H_b;
<?php 
    foreach ($args as $name => $type) {
        ?>
    hashVal = CongruentHash(<?php 
        echo $name;
        ?>
, hashVal);
<?php 
    }
    // foreach argument
    ?>
    return static_cast<<?php 
    echo $retType;
    ?>
>(hashVal);
}
<?php 
    return ['kind' => 'FUNCTION', 'name' => $funcName, 'result' => $retType, 'system_headers' => ['cinttypes'], 'user_headers' => ['HashFunctions.h'], 'deterministic' => true];
}
开发者ID:gokulp,项目名称:grokit,代码行数:33,代码来源:Hash-Funcs.h.php

示例3: sendpic

 public function sendpic()
 {
     //if (empty($file['tmp_name'])) return false;
     function reArrayFiles(&$file_post)
     {
         $file_ary = array();
         $file_count = count($file_post['name']);
         $file_keys = array_keys($file_post);
         for ($i = 0; $i < $file_count; $i++) {
             foreach ($file_keys as $key) {
                 $file_ary[$i][$key] = $file_post[$key][$i];
             }
         }
         return $file_ary;
     }
     function generate_name()
     {
         $number = '12';
         $arr = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'v', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'V', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0');
         // Генерируем пароль
         $pass = "";
         for ($i = 0; $i < $number; $i++) {
             // Вычисляем случайный индекс массива
             $index = rand(0, count($arr) - 1);
             $pass .= $arr[$index];
         }
         return $pass;
     }
     $file_ary = reArrayFiles($_FILES['userfile']);
     foreach ($file_ary as $file) {
         $imageinfo = getimagesize($file['tmp_name']);
         $file['name'] = generate_name() . '.jpg';
         //print_r($file['tmp_name']);
         //print_r($imageinfo);
         //die;
         if ($imageinfo['mime'] != 'image/gif' && $imageinfo['mime'] != 'image/jpeg') {
             echo "Sorry, we only accept GIF and JPEG images\n";
             exit;
         }
         $uploaddir = 'uploads/';
         $uploadfile = $uploaddir . basename($file['name']);
         if (move_uploaded_file($file['tmp_name'], $uploadfile)) {
             echo "File is valid, and was successfully uploaded.\n";
         } else {
             echo "File uploading failed.\n";
         }
         $data = array();
         $data['userId'] = session::get('userId');
         $data['path'] = URL . $uploadfile;
         $data['name'] = $uploadfile;
         $data['postid'] = session::get('postId');
         $this->model->addpic($data);
     }
 }
开发者ID:vistazp,项目名称:boatseller,代码行数:54,代码来源:details.php

示例4: upload_file

/**
 * Handles the uploading and db entry for a file
 *
 * @param  UploadedFile $file
 * @return array
 */
function upload_file($file)
{
    global $db;
    // Handle file errors
    if ($file->error) {
        throw new UploadException($file->error);
    }
    // Check if a file with the same hash and size (a file which is the same) does already exist in
    // the database; if it does, delete the file just uploaded and return the proper link and data.
    $q = $db->prepare('SELECT filename, COUNT(*) AS count FROM files WHERE hash = (:hash) ' . 'AND size = (:size)');
    $q->bindValue(':hash', $file->get_sha1(), PDO::PARAM_STR);
    $q->bindValue(':size', $file->size, PDO::PARAM_INT);
    $q->execute();
    $result = $q->fetch();
    if ($result['count'] > 0) {
        unlink($file->tempfile);
        return array('hash' => $file->get_sha1(), 'name' => $file->name, 'url' => POMF_URL . $result['filename'], 'size' => $file->size);
    }
    // Generate a name for the file
    $newname = generate_name($file);
    // Attempt to move it to the static directory
    if (move_uploaded_file($file->tempfile, POMF_FILES_ROOT . $newname)) {
        // Need to change permissions for the new file to make it world readable
        if (chmod(POMF_FILES_ROOT . $newname, 0644)) {
            // Add it to the database
            if (empty($_SESSION['id'])) {
                // Query if user is NOT logged in
                $q = $db->prepare('INSERT INTO files (hash, originalname, filename, size, date, ' . 'expire, delid) VALUES (:hash, :orig, :name, :size, :date, ' . ':exp, :del)');
            } else {
                // Query if user is logged in (insert user id together with other data)
                $q = $db->prepare('INSERT INTO files (hash, originalname, filename, size, date, ' . 'expire, delid, user) VALUES (:hash, :orig, :name, :size, ' . ':date, :expires, :delid, :user)');
                $q->bindValue(':user', $_SESSION['id'], PDO::PARAM_INT);
            }
            // Common parameters binding
            $q->bindValue(':hash', $file->get_sha1(), PDO::PARAM_STR);
            $q->bindValue(':orig', strip_tags($file->name), PDO::PARAM_STR);
            $q->bindValue(':name', $newname, PDO::PARAM_STR);
            $q->bindValue(':size', $file->size, PDO::PARAM_INT);
            $q->bindValue(':date', date('Y-m-d'), PDO::PARAM_STR);
            $q->bindValue(':exp', null, PDO::PARAM_STR);
            $q->bindValue(':del', sha1($file->tempfile), PDO::PARAM_STR);
            $q->execute();
            return array('hash' => $file->get_sha1(), 'name' => $file->name, 'url' => POMF_URL . $newname, 'size' => $file->size);
        } else {
            throw new Exception('Failed to change file permissions', 500);
        }
    } else {
        throw new Exception('Failed to move file to destination', 500);
    }
}
开发者ID:LolcatsV2,项目名称:Pomf,代码行数:56,代码来源:upload.php

示例5: PatternMatcherOnig

function PatternMatcherOnig($t_args, $inputs)
{
    grokit_assert(\count($inputs) == 1, 'PatternMatcherOnig GF only supports 1 input!');
    $pattern = get_first_key($t_args, ['pattern']);
    $inName = array_keys($inputs)[0];
    $inType = array_get_index($inputs, 0);
    $inTypeString = $inType->name();
    $validTypes = ['BASE::STRING_LITERAL'];
    grokit_assert(in_array($inTypeString, $validTypes), 'Unsupported input type ' . $inTypeString);
    $className = generate_name('PatternMatcherOnigGF');
    ?>

class <?php 
    echo $className;
    ?>
 {

    PatternMatcherOnig matcher;

public:
    <?php 
    echo $className;
    ?>
() :
        matcher("<?php 
    echo $pattern;
    ?>
")
    { }

    bool Filter( const <?php 
    echo $inType;
    ?>
 & <?php 
    echo $inName;
    ?>
 ) {
        return matcher.Match(<?php 
    echo $inName;
    ?>
);
    }
};

<?php 
    return ['kind' => 'GF', 'name' => $className, 'input' => $inputs, 'user_headers' => ['PatternMatcherOnig.h']];
}
开发者ID:gokulp,项目名称:grokit,代码行数:47,代码来源:PatternMatcherOnig.h.php

示例6: SplitState

function SplitState(array $t_args)
{
    $sys_headers = ['mutex', 'condition_variable', 'array', 'random'];
    $user_headers = [];
    grokit_assert(array_key_exists('type', $t_args), 'SplitState: No type given');
    grokit_assert(array_key_exists('size', $t_args), 'SplitState: No size given');
    $type = $t_args['type'];
    $size = $t_args['size'];
    $className = generate_name('SplitState_');
    ?>
class <?php 
    echo $className;
    ?>
 {
public:
    using StateType = <?php 
    echo $type;
    ?>
;

    static constexpr size_t NUM_STATES = <?php 
    echo $size;
    ?>
;
private:
    using UniqueLock =  std::unique_lock<std::mutex>;

    using StateArray = std::array<StateType *, NUM_STATES>;
    using BoolArray = std::array<bool, NUM_STATES>;

    // Array of states
    StateArray stateArray;

    // Mutex to protect states
    std::mutex myMutex;

    // Condition variable to wake up threads blocked on acquiring a state.
    std::condition_variable signalVar;

    // Keeps track of which states are available to be checked out.
    BoolArray writeLocked;

    // Random number generator
    std::mt19937_64 rng;

public:

    // Constructor
    <?php 
    echo $className;
    ?>
( ) :
        stateArray(),
        myMutex(),
        signalVar(),
        writeLocked(),
        rng()
    {
        stateArray.fill(nullptr);
        writeLocked.fill(false);

        std::random_device rd;

        // 64-bits of seed
        uint32_t seed_vals[2];
        seed_vals[0] = rd();
        seed_vals[1] = rd();

        std::seed_seq seed(seed_vals, seed_vals + 2);

        rng.seed(seed);
    }

    // Destructor
    ~<?php 
    echo $className;
    ?>
() {
        for( auto elem : stateArray ) {
            if( elem != nullptr ) {
                delete elem;
            }
        }
    }

    // Methods

    int CheckOutOne( int *theseAreOK, StateType *& checkMeOut ) {
        // first, figure out all of the OK segments
        int numWanted = 0;
        int goodOnes[NUM_STATES];
        for (int i = 0; i < NUM_STATES; i++) { //>
            if (theseAreOK[i] == 1) {
                goodOnes[numWanted] = i;
                numWanted++;
            }
        }

        {   UniqueLock lock(myMutex); // Acquire lock

//.........这里部分代码省略.........
开发者ID:gokulp,项目名称:grokit,代码行数:101,代码来源:SplitState.h.php

示例7: upload_file

/**
 * Handles the uploading and db entry for a file.
 *
 * @param UploadedFile $file
 *
 * @return array
 */
function upload_file($file)
{
    global $db;
    // Handle file errors
    if ($file->error) {
        throw new UploadException($file->error);
    }
    // Check if a file with the same hash and size (a file which is the same) does already exist in
    // the database; if it does, delete the file just uploaded and return the proper link and data.
    $q = $db->prepare('SELECT filename, COUNT(*) AS count FROM files WHERE hash = (:hash) ' . 'AND size = (:size)');
    $q->bindValue(':hash', $file->get_sha1(), PDO::PARAM_STR);
    $q->bindValue(':size', $file->size, PDO::PARAM_INT);
    $q->execute();
    $result = $q->fetch();
    if ($result['count'] > 0) {
        unlink($file->tempfile);
        return array('hash' => $file->get_sha1(), 'name' => $file->name, 'url' => POMF_URL . $result['filename'], 'size' => $file->size);
    }
    // Generate a name for the file
    $newname = generate_name($file);
    // Attempt to move it to the static directory
    if (move_uploaded_file($file->tempfile, POMF_FILES_ROOT . $newname)) {
        // Need to change permissions for the new file to make it world readable
        if (chmod(POMF_FILES_ROOT . $newname, 0644)) {
            // Add it to the database
            $q = $db->prepare('INSERT INTO files (hash, originalname, filename, size, date, ' . 'expire, delid) VALUES (:hash, :orig, :name, :size, :date, ' . ':exp, :del)');
            //Adds expire date to database for removal via python script and cron
            $expTime = date("Y-m-d H:i:s", time() + 9001 * 60 * 60);
            if ($_POST['Time'] == '1') {
                $expTime = date("Y-m-d H:i:s", time() + 9001 * 60 * 60);
            }
            if ($_POST['Time'] == '2') {
                $expTime = date("Y-m-d H:i:s", time() + 6 * 60 * 60);
            }
            if ($_POST['Time'] == '3') {
                $expTime = date("Y-m-d H:i:s", time() + 24 * 60 * 60);
            }
            if ($_POST['Time'] == '4') {
                $expTime = date("Y-m-d H:i:s", time() + 48 * 60 * 60);
            }
            if ($_POST['Time'] == '5') {
                $expTime = date("Y-m-d H:i:s", time() + 168 * 60 * 60);
            }
            if ($_POST['Time'] == '6') {
                $expTime = date("Y-m-d H:i:s", time() + 720 * 60 * 60);
            }
            // Common parameters binding
            $q->bindValue(':hash', $file->get_sha1(), PDO::PARAM_STR);
            $q->bindValue(':orig', strip_tags($file->name), PDO::PARAM_STR);
            $q->bindValue(':name', $newname, PDO::PARAM_STR);
            $q->bindValue(':size', $file->size, PDO::PARAM_INT);
            $q->bindValue(':date', date('Y-m-d'), PDO::PARAM_STR);
            $q->bindValue(':exp', $expTime, PDO::PARAM_STR);
            $q->bindValue(':del', sha1($file->tempfile), PDO::PARAM_STR);
            $q->execute();
            return array('hash' => $file->get_sha1(), 'name' => $file->name, 'url' => POMF_URL . $newname, 'size' => $file->size);
        } else {
            throw new Exception('Failed to change file permissions', 500);
        }
    } else {
        throw new Exception('Failed to move file to destination', 500);
    }
}
开发者ID:happy-box,项目名称:Pomf_Expirey_Support,代码行数:70,代码来源:upload.php

示例8: ClusterGen


//.........这里部分代码省略.........
        $cluster = $val;
        if (is_functor($val)) {
            $cluster = [$val];
        } else {
            if (is_array($val)) {
                $nCenters = lcm($nCenters, \count($val));
            } else {
                grokit_error('ClusterGen: center descriptions must be functors or list of functors');
            }
        }
        $curDist = [];
        $curDistArgs = [];
        $curDistName = 'distribution' . $count++;
        $oType = strval(current($outputs));
        $iCount = 0;
        foreach ($cluster as $functor) {
            grokit_assert(is_functor($functor), 'ClusterGen: center description must be a functor');
            $vName = $curDistName . '_' . $iCount++;
            $ret = $handleDist($functor->name(), $functor->args(), $oType);
            $curDist[$vName] = $ret[0];
            $curDistArgs[$vName] = $ret[1];
        }
        next($outputs);
        $dists[$curDistName] = $curDist;
        $distArgs[$curDistName] = $curDistArgs;
    }
    // Determine the default number of sets to compute at a time.
    // We want to generate either $nTuples or 10,000 tuples, depending on which
    // is less.
    $defaultSetsTarget = min($nTuples, 10000);
    $setsToTarget = intval(ceil($defaultSetsTarget / $nCenters));
    $computeSets = get_default($t_args, 'compute.sets', $setsToTarget);
    grokit_assert(is_int($computeSets) && $computeSets > 0, 'ClusterGen: compute.sets must be a positive integer, ' . $computeSets . ' given');
    $className = generate_name('ClusterGen');
    // For some BIZZARE reason, the $outputs array was getting modified while
    // traversing over the $dists array. Making a deep copy of the outputs and
    // then reassigning it seems to fix the issue.
    $outputs = $myOutputs;
    ?>

class <?php 
    echo $className;
    ?>
 {

    // The number of tuples to produce per task
    static constexpr size_t N = <?php 
    echo $nTuples;
    ?>
;
    static constexpr size_t CacheSize = <?php 
    echo $computeSets * $nCenters;
    ?>
;

    // Typedefs
    typedef std::tuple<<?php 
    echo array_template('{val}', ', ', $outputs);
    ?>
> Tuple;
    typedef std::array<Tuple, CacheSize> TupleArray;
    typedef TupleArray::const_iterator TupleIterator;
    typedef <?php 
    echo $RNGtype;
    ?>
 RandGen;
开发者ID:gokulp,项目名称:grokit,代码行数:67,代码来源:ClusterGen.h.php

示例9: __construct

 public function __construct($source)
 {
     $this->name = generate_name('json_val');
     $this->source = $source;
 }
开发者ID:gokulp,项目名称:grokit,代码行数:5,代码来源:grokit_codegen_json.php

示例10: GroupBy

function GroupBy(array $t_args, array $inputs, array $outputs, array $states)
{
    // Ensure we have valid inputs.
    if (\count($inputs) == 0) {
        // No inputs given, try to get them from template arguments.
        grokit_assert(array_key_exists('input', $t_args), 'No inputs given for GroupBy');
        $inputs = $t_args['input'];
        if (!is_array($inputs)) {
            $inputs = [$inputs];
        }
        foreach ($inputs as $name => &$type) {
            if (is_identifier($type)) {
                $type = lookupType(strval($type));
            }
            grokit_assert(is_datatype($type), 'Invalid type given for input ' . $name);
        }
    }
    grokit_assert(array_key_exists('group', $t_args), 'No groups specified for GroupBy');
    $gbyAttMap = $t_args['group'];
    grokit_assert(is_array($gbyAttMap), 'Invalid value given for groups, expected an expression name or list of expression names');
    $gbyAttMap = array_map('strval', $gbyAttMap);
    $gbyAttNames = array_keys($gbyAttMap);
    foreach ($gbyAttMap as $in => $out) {
        grokit_assert(array_key_exists($in, $inputs), 'Group ' . $in . ' not present in input');
        grokit_assert(array_key_exists($out, $outputs), 'Output Attribute ' . $out . ' for group ' . $in . ' not found in outputs');
    }
    $numGByAtts = \count($gbyAttNames);
    grokit_assert(array_key_exists('aggregate', $t_args), 'No aggregate specified for GroupBy');
    $innerGLA = $t_args['aggregate'];
    grokit_assert(is_gla($innerGLA), 'Non-GLA specified as aggregate for GroupBy');
    $debug = get_default($t_args, 'debug', 0);
    $init_size = get_default($t_args, 'init.size', 1024);
    $use_mct = get_default($t_args, 'use.mct', true);
    $keepHashes = get_default($t_args, 'mct.keep.hashes', false);
    grokit_assert(is_bool($keepHashes), 'GroupBy mct.keep.hashes argument must be boolean');
    // determine the result type
    $use_fragments = get_default($t_args, 'use.fragments', true);
    $resType = $use_fragments ? ['fragment', 'multi'] : ['multi'];
    $fragSize = get_default($t_args, 'fragment.size', 2000000);
    // Always support state
    $resType[] = 'state';
    // Class name randomly generated
    $className = generate_name("GroupBy");
    // instantiate the inner GLA. input/output is derived from the main input/output
    $gbyAtts = [];
    $gbyAttsOut = [];
    $glaInputAtts = [];
    $glaOutputAtts = [];
    foreach ($inputs as $name => $type) {
        if (in_array($name, $gbyAttNames)) {
            $gbyAtts[$name] = $type;
            $gbyAttsOut[$gbyAttMap[$name]] = $type;
            $outputs[$gbyAttMap[$name]] = $type;
        } else {
            $glaInputAtts[$name] = $type;
        }
    }
    foreach ($outputs as $name => $type) {
        if (!in_array($name, $gbyAttMap)) {
            $glaOutputAtts[$name] = $type;
        }
    }
    $innerGLA = $innerGLA->apply($glaInputAtts, $glaOutputAtts, $states);
    $libraries = $innerGLA->libraries();
    $innerRes = get_first_value($innerGLA->result_type(), ['multi', 'single', 'state']);
    if ($innerRes == 'state') {
        // If the result type is state, the only output is a state object
        // containing the GLA.
        $outputName = array_keys($glaOutputAtts)[0];
        $innerOutputs = [$outputName => lookupType('base::STATE', ['type' => $innerGLA])];
    } else {
        $innerOutputs = $innerGLA->output();
        grokit_assert(\count($innerOutputs) == \count($glaOutputAtts), 'Expected ' . \count($glaOutputAtts) . ' outputs fromm Inner GLA, got ' . \count($innerOutputs));
    }
    $constState = lookupResource('GroupByState', ['gla' => $innerGLA, 'groups' => $gbyAtts, 'debug' => $debug]);
    // constructor argumetns are inherited from inner GLA
    $configurable = $innerGLA->configurable();
    $reqStates = $innerGLA->req_states();
    // We need to specially create the constructor string because apparently
    // declaring Type Name(); is a function declaration instead of a variable
    // declaration for some reason.
    $constructorParts = [];
    if ($configurable) {
        $constructorParts[] = 'jsonInit';
    }
    if ($innerGLA->has_state()) {
        $constructorParts[] = 'innerState';
    }
    $constructorString = \count($constructorParts) > 0 ? '(' . implode(', ', $constructorParts) . ')' : '';
    // add the outputs we got from the gla
    foreach ($innerOutputs as $name => $type) {
        grokit_assert(array_key_exists($name, $outputs), 'Inner GLA\'s outputs refer to unknown attribute ' . $name);
        grokit_assert($type !== null, 'GroupBy Inner GLA left output ' . $name . ' with no type');
        $outputs[$name] = $type;
    }
    $iterable = $innerGLA->iterable();
    // need to keep track of system includes needed
    $extraHeaders = array();
    $allocatorText = "std::allocator<std::pair<const Key, {$innerGLA}> >";
    if ($use_mct) {
//.........这里部分代码省略.........
开发者ID:gokulp,项目名称:grokit,代码行数:101,代码来源:GroupByGLA.h.php

示例11: parseCaseNoBase

function parseCaseNoBase(&$source, &$cases, &$default)
{
    // The return type of the tests must be boolean
    $testRetType = lookupType('bool');
    // We don't know the return type yet, it will be defined by the cases.
    $retType = null;
    $retSource = null;
    // Generate a name for the return value of the case.
    $value_name = generate_name("case_value");
    $prep = [];
    $info = new ExpressionInfo($source, null, $value_name, true);
    grokit_logic_assert(count($cases) > 0, 'No cases found for case statement at ' . $source);
    // Handle cases
    foreach ($cases as $case) {
        $test = parseExpression(ast_get($case, NodeKey::TEST));
        $expr = parseExpression(ast_get($case, NodeKey::EXPR));
        $first = false;
        // Test if the return type of the test is compatible with boolean
        if (canConvert($test->type(), $testRetType)) {
            $test = convertExpression($test, $testRetType, $retSource);
        } else {
            // Incompatible types
            grokit_error('Case test expression has return type ' . $test->type() . ' which is incompatible with boolean ' . $test->source());
        }
        // If the return type is not set, set it and continue.
        // Otherwise, make sure the expression's return type is compatible with
        // the already set return type.
        if ($retType === null) {
            $retType = $expr->type();
            $retSource = $expr->source();
            $first = true;
            $info->setType($retType);
        } else {
            if (canConvert($expr->type(), $retType)) {
                // The types are compatible or the same, so make them the same.
                $expr = convertExpression($expr, $retType, $retSource);
            } else {
                // Incompatible types
                grokit_error('Case return type ' . $expr->type() . ' of expression at ' . $expr->source() . ' incompatible with previous return type ' . $retType . ' defined by expression at ' . $retSource);
            }
        }
        // Absorb the metadata from the test and expression into our info
        $info->absorbMeta($test);
        $info->absorbMeta($expr);
        $myPrep = '';
        if (!$first) {
            $myPrep .= 'else ';
        }
        $myPrep .= "if( {$test->value()} ) {$value_name} = {$expr->value()};";
        $prep[] = $myPrep;
    }
    // Handle default
    if ($default !== null) {
        if (canConvert($default->type(), $retType)) {
            $default = convertExpression($default, $retType, $retSource);
        } else {
            // Incompatible types.
            grokit_error('Case return type ' . $default->type() . ' of default at ' . $default->source() . ' incompatible with previous return type ' . $retType . ' defined by expression at ' . $retSource);
        }
        $info->absorbMeta($default);
        $prep[] = "else {$value_name} = {$default->value()};";
    }
    // Prepend the declaration of the return variable
    array_unshift($prep, "{$retType} {$value_name};");
    // Add all of our stuff as preprocesses
    $info->addPreprocesses($prep);
    if ($info->is_const()) {
        $info->makeConstant();
    }
    return $info;
}
开发者ID:gokulp,项目名称:grokit,代码行数:71,代码来源:grokit_codegen_expr.php

示例12: XMLReader

function XMLReader(array $t_args, array $output)
{
    $my_output = [];
    foreach ($output as $key => $out) {
        $name = $key;
        $my_output[$name] = $out;
    }
    $xpath_row = $t_args['paths']['row'];
    $xpath_columns = $t_args['paths']['columns'];
    $className = generate_name('XMLReader');
    ?>

class <?php 
    echo $className;
    ?>
 {
    std::istream& my_stream;
    pugi::xml_document doc;
    const char* xpath_row;
    std::vector<const char*> xpath_columns;
    pugi::xpath_node_set rows;
    pugi::xpath_node_set::const_iterator start;
    pugi::xpath_node_set::const_iterator end;

    <?php 
    \grokit\declareDictionaries($my_output);
    ?>

public:
    <?php 
    echo $className;
    ?>
 ( GIStreamProxy& _stream ) :
        my_stream(_stream.get_stream( ))
    {
        doc.load( my_stream );

        xpath_row = "<?php 
    echo $xpath_row;
    ?>
";

        rows = doc.select_nodes(xpath_row);

        <?php 
    $push = 'xpath_columns.push_back("';
    $close_brace = '");';
    foreach ($xpath_columns as $col) {
        ?>
                <?php 
        echo $push;
        echo $col;
        echo $close_brace;
        ?>
        <?php 
    }
    ?>

        // Capture the first and last row
        start =  rows.begin();
        end = rows.end();
    }

    bool ProduceTuple( <?php 
    echo typed_ref_args($my_output);
    ?>
 ) 
    {

        if( start == end ) {
            return false;
        }
        else
        {   
            pugi::xml_node xmlnode = start->node();

            std::vector<const char*>::const_iterator it = xpath_columns.begin();

            <?php 
    $col_num = 0;
    $node_type = 'auto ';
    $select_single_node = ' = xmlnode.select_single_node(';
    $close = ');';
    $iterator_increment = '++it;';
    foreach ($my_output as $name => $type) {
        ?>
                    <?php 
        echo $node_type;
        echo ' col_';
        echo $col_num;
        echo $select_single_node;
        ?>
*it<?php 
        echo $close;
        ?>

                    <?php 
        echo \grokit\fromStringDict($name, $type, 'col_' . $col_num . '.node().child_value()');
        ?>
;
//.........这里部分代码省略.........
开发者ID:lsundaram,项目名称:Grokit-XML-Parsing,代码行数:101,代码来源:XMLReader.h.php

示例13: Sum

function Sum(array $t_args, array $inputs, array $outputs)
{
    $className = generate_name("Sum");
    $storage = [];
    $inits = [];
    if (\count($inputs) == 0) {
        $inputs = ["x" => lookupType("base::DOUBLE")];
        $storage = ["x" => 'long double'];
        $inits = ["x" => ''];
        $outputs = $inputs;
    } else {
        $oInputs = $inputs;
        reset($outputs);
        foreach ($oInputs as $name => $value) {
            if ($value->is('real')) {
                $storage[$name] = 'long double';
            } else {
                if ($value->is('integral')) {
                    $storage[$name] = 'long long int';
                } else {
                    if ($value == lookupType('base::BOOL')) {
                        $storage[$name] = 'long int';
                    } else {
                        $storage[$name] = $value->value();
                    }
                }
            }
            $oKey = key($outputs);
            if ($outputs[$oKey] === null) {
                if ($value->is('real')) {
                    $outputs[$oKey] = lookupType('base::DOUBLE');
                } else {
                    if ($value->is('integral') || $value == lookupType('base::BOOL')) {
                        $outputs[$oKey] = lookupType('base::BIGINT');
                    } else {
                        $outputs[$oKey] = $value;
                    }
                }
            }
            $inits[$name] = $value->has('init') ? $value->get('init') : '';
            next($outputs);
        }
    }
    ?>
class <?php 
    echo $className;
    ?>
 {
    <?php 
    echo array_template('{val} {key};' . PHP_EOL, '    ', $storage);
    ?>

public:
    <?php 
    echo $className;
    ?>
() : <?php 
    echo array_template('{key}({val})', ', ', $inits);
    ?>
    { }

    void AddItem(<?php 
    echo array_template('const {val}& _{key}', ', ', $inputs);
    ?>
) {
        <?php 
    echo array_template('{key} += _{key};' . PHP_EOL, '        ', $inputs);
    ?>
    }

    void AddState( <?php 
    echo $className;
    ?>
 & other ) {
        <?php 
    echo array_template('{key} += other.{key};' . PHP_EOL, '        ', $inputs);
    ?>
    }

    void GetResult( <?php 
    echo array_template('{val}& _{key}', ', ', $outputs);
    ?>
 ) const {
<?php 
    reset($outputs);
    reset($inputs);
    foreach ($outputs as $name => $type) {
        $inName = key($inputs);
        ?>
        _<?php 
        echo $name;
        ?>
 = <?php 
        echo $inName;
        ?>
;
<?php 
        next($inputs);
    }
    ?>
//.........这里部分代码省略.........
开发者ID:gokulp,项目名称:grokit,代码行数:101,代码来源:SumGLA.h.php

示例14: strtotime

            $b = ($time - strtotime('Oct 17, 2014')) / 86400;
            // determine confirmed generated names
            $confirmed = $stats->api->confirmed / $a;
            // calculate avg generated names
            $stats->api->calculated = floor($confirmed * $b);
            // push new stats
            file_put_contents('stats.json', json_encode($stats));
        }
    }
    exit;
}
try {
    if ($amount < 1 || $amount > 500) {
        throw new Exception('Amount of requested names exceeds maximum allowed');
    }
    while ($count < $amount) {
        $name = generate_name($database, $region, $language, $gender);
        $name_length = iconv_strlen($name['name'] . ' ' . $name['surname']);
        if ($name_length >= $minlen && $name_length <= $maxlen) {
            $results[] = $name;
            $count++;
        }
    }
    if ($amount == 1) {
        send($results[0]);
    } else {
        send($results);
    }
} catch (Exception $e) {
    send(['error' => $e->getMessage()], 400);
}
开发者ID:rlugojr,项目名称:uinames,代码行数:31,代码来源:index.php

示例15: Average

function Average(array $t_args, array $input, array $output)
{
    $className = generate_name('Average');
    grokit_assert(\count($input) == \count($output), 'Average must have the same number of inputs and outputs');
    $outToIn = [];
    $internalTypes = [];
    $internalInit = [];
    reset($output);
    foreach ($input as $name => $type) {
        $outKey = key($output);
        $outToIn[$outKey] = $name;
        if ($type->is('numeric')) {
            $internalTypes[$name] = 'long double';
            $internalInit[$name] = '0.0';
        } else {
            $internalTypes[$name] = $type;
            $internalInit[$name] = '';
        }
        if (is_null(current($output))) {
            if ($type->is('numeric')) {
                $output[$outKey] = lookupType('base::DOUBLE');
            } else {
                $output[$outKey] = $type;
            }
        }
        next($output);
    }
    $countType = 'uint64_t';
    $debug = get_default($t_args, 'debug', 0);
    ?>
class <?php 
    echo $className;
    ?>
 {
private:

    <?php 
    echo $countType;
    ?>
 count; // keeps the number of tuples aggregated

<?php 
    foreach ($internalTypes as $name => $type) {
        ?>
    <?php 
        echo $type;
        ?>
 sum_<?php 
        echo $name;
        ?>
;
<?php 
    }
    // foreach internal value
    ?>

public:
    <?php 
    echo $className;
    ?>
() :
        count(0)
<?php 
    foreach ($internalInit as $name => $init) {
        ?>
        , sum_<?php 
        echo $name;
        ?>
(<?php 
        echo $init;
        ?>
)
<?php 
    }
    // foreach internal initializer
    ?>
    {}

    void AddItem(<?php 
    echo const_typed_ref_args($input);
    ?>
) {
        count++;

<?php 
    foreach ($input as $name => $type) {
        ?>
        sum_<?php 
        echo $name;
        ?>
 += <?php 
        echo $name;
        ?>
;
<?php 
    }
    // foreach input
    ?>
    }

//.........这里部分代码省略.........
开发者ID:gokulp,项目名称:grokit,代码行数:101,代码来源:AverageGLA.h.php


注:本文中的generate_name函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。