⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ta_abstract.c

📁 股票主要技术指标源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* TA-LIB Copyright (c) 1999-2007, Mario Fortier * All rights reserved. * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following * conditions are met: * * - Redistributions of source code must retain the above copyright *   notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright *   notice, this list of conditions and the following disclaimer in *   the documentation and/or other materials provided with the *   distribution. * * - Neither name of author nor the names of its contributors *   may be used to endorse or promote products derived from this *   software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *//* List of contributors: * *  Initial  Name/description *  ------------------------------------------------------------------- *  MF       Mario Fortier *  AC       Angelo Ciceri * * * Change history: * *  MMDDYY BY   Description *  ------------------------------------------------------------------- *  020101 MF   First version. *  110302 MF   Re-design the interface related to TA_CallFunc for being *              faster and use less memory allocation. *  022904 MF   Add TA_GetLookback *  031404 MF   Some function renaming for consistency and better *              Perl integration. *  110206 AC   Change volume and open interest to double *//* Description: *   Provide a way to abstract the call of the TA functions. *//**** Headers ****/#include <stddef.h>#include <string.h>#include <ctype.h>#include "ta_common.h"#include "ta_memory.h"#include "ta_abstract.h"#include "ta_def_ui.h"#include "ta_frame_priv.h"#include <limits.h>/**** External functions declarations. ****//* None *//**** External variables declarations. ****//* The interface definition of all functions are accessible * through one of the following 26 tables. */extern const TA_FuncDef *TA_DEF_TableA, *TA_DEF_TableB, *TA_DEF_TableC,                        *TA_DEF_TableD, *TA_DEF_TableE, *TA_DEF_TableF,                        *TA_DEF_TableG, *TA_DEF_TableH, *TA_DEF_TableI,                        *TA_DEF_TableJ, *TA_DEF_TableK, *TA_DEF_TableL,                        *TA_DEF_TableM, *TA_DEF_TableN, *TA_DEF_TableO,                        *TA_DEF_TableP, *TA_DEF_TableQ, *TA_DEF_TableR,                        *TA_DEF_TableS, *TA_DEF_TableT, *TA_DEF_TableU,                        *TA_DEF_TableV, *TA_DEF_TableW, *TA_DEF_TableX,                        *TA_DEF_TableY, *TA_DEF_TableZ;extern const unsigned int TA_DEF_TableASize, TA_DEF_TableBSize,                          TA_DEF_TableCSize, TA_DEF_TableDSize,                          TA_DEF_TableESize, TA_DEF_TableFSize,                          TA_DEF_TableGSize, TA_DEF_TableHSize,                          TA_DEF_TableISize, TA_DEF_TableJSize,                          TA_DEF_TableKSize, TA_DEF_TableLSize,                          TA_DEF_TableMSize, TA_DEF_TableNSize,                          TA_DEF_TableOSize, TA_DEF_TablePSize,                          TA_DEF_TableQSize, TA_DEF_TableRSize,                          TA_DEF_TableSSize, TA_DEF_TableTSize,                          TA_DEF_TableUSize, TA_DEF_TableVSize,                          TA_DEF_TableWSize, TA_DEF_TableXSize,                          TA_DEF_TableYSize, TA_DEF_TableZSize;#ifndef TA_GEN_CODE   /* In gen_code, these value does not exist (they are generated by    * gen_code itself!)    * Consequently, the code, when being used to make the gen_code    * executable, must provide the same functionality without using    * these shortcuts.    */   extern const TA_FuncDef **TA_PerGroupFuncDef[];   extern const unsigned int TA_PerGroupSize[];#endif/**** Global variables definitions.    ****//* None *//**** Local declarations.              ****/#ifndef min   #define min(a, b)  (((a) < (b)) ? (a) : (b))#endiftypedef struct {   unsigned int magicNumber;} TA_StringTablePriv;/**** Local functions declarations.    ****/#ifdef TA_GEN_CODE   static TA_RetCode getGroupId( const char *groupString, unsigned int *groupId );   static TA_RetCode getGroupSize( TA_GroupId groupId, unsigned int *groupSize );   static TA_RetCode getFuncNameByIdx( TA_GroupId groupId,                                       unsigned int idx,                                       const char **stringPtr );#else   static TA_RetCode getGroupId( const char *groupString, unsigned int *groupId );   static TA_RetCode getGroupSize( TA_GroupId groupId, unsigned int *groupSize );   static TA_RetCode getFuncNameByIdx( TA_GroupId groupId,                                       unsigned int idx,                                       const char **stringPtr );#endif/**** Local variables definitions.     ****/static const TA_FuncDef **TA_DEF_Tables[26] ={   &TA_DEF_TableA, &TA_DEF_TableB, &TA_DEF_TableC, &TA_DEF_TableD, &TA_DEF_TableE,   &TA_DEF_TableF, &TA_DEF_TableG, &TA_DEF_TableH, &TA_DEF_TableI, &TA_DEF_TableJ,   &TA_DEF_TableK, &TA_DEF_TableL, &TA_DEF_TableM, &TA_DEF_TableN, &TA_DEF_TableO,   &TA_DEF_TableP, &TA_DEF_TableQ, &TA_DEF_TableR, &TA_DEF_TableS, &TA_DEF_TableT,   &TA_DEF_TableU, &TA_DEF_TableV, &TA_DEF_TableW, &TA_DEF_TableX, &TA_DEF_TableY,   &TA_DEF_TableZ};static const unsigned int *TA_DEF_TablesSize[26] ={   &TA_DEF_TableASize, &TA_DEF_TableBSize, &TA_DEF_TableCSize,   &TA_DEF_TableDSize, &TA_DEF_TableESize, &TA_DEF_TableFSize,   &TA_DEF_TableGSize, &TA_DEF_TableHSize, &TA_DEF_TableISize,   &TA_DEF_TableJSize, &TA_DEF_TableKSize, &TA_DEF_TableLSize,   &TA_DEF_TableMSize, &TA_DEF_TableNSize, &TA_DEF_TableOSize,   &TA_DEF_TablePSize, &TA_DEF_TableQSize, &TA_DEF_TableRSize,   &TA_DEF_TableSSize, &TA_DEF_TableTSize, &TA_DEF_TableUSize,   &TA_DEF_TableVSize, &TA_DEF_TableWSize, &TA_DEF_TableXSize,   &TA_DEF_TableYSize, &TA_DEF_TableZSize};/**** Global functions definitions.   ****/TA_RetCode TA_GroupTableAlloc( TA_StringTable **table ){   TA_StringTable *stringTable;   TA_StringTablePriv *stringTablePriv;   if( table == NULL )   {      return TA_BAD_PARAM;   }   stringTable = (TA_StringTable *)TA_Malloc( sizeof(TA_StringTable) + sizeof(TA_StringTablePriv) );   if( !stringTable )   {      *table = NULL;      return TA_ALLOC_ERR;   }   memset( stringTable, 0, sizeof(TA_StringTable) + sizeof(TA_StringTablePriv) );   stringTablePriv = (TA_StringTablePriv *)(((char *)stringTable)+sizeof(TA_StringTable));   stringTablePriv->magicNumber = TA_STRING_TABLE_GROUP_MAGIC_NB;   stringTable->size = TA_NB_GROUP_ID;   stringTable->string = &TA_GroupString[0];   stringTable->hiddenData = stringTablePriv;   /* From this point, TA_FuncTableFree can be safely called. */   /* Success. Return the table to the caller. */   *table = stringTable;   return TA_SUCCESS;}TA_RetCode TA_GroupTableFree( TA_StringTable *table ){   TA_StringTablePriv *stringTablePriv;   if( table )   {      stringTablePriv = (TA_StringTablePriv *)table->hiddenData;      if( !stringTablePriv )      {         return TA_INTERNAL_ERROR(1);      }         if( stringTablePriv->magicNumber != TA_STRING_TABLE_GROUP_MAGIC_NB )      {         return TA_BAD_OBJECT;      }      TA_Free( table );   }   return TA_SUCCESS;}/* Iterate in alphabetical order */TA_RetCode TA_ForEachFunc( TA_CallForEachFunc functionToCall, void *opaqueData ){   const TA_FuncDef **funcDefTable;   const TA_FuncDef *funcDef;   const TA_FuncInfo *funcInfo;   unsigned int i, j, funcDefTableSize;   if( functionToCall == NULL )   {      return TA_BAD_PARAM;   }      /* Iterate the tables (each table is for one letter) */   for( i=0; i < 26; i++ )   {         funcDefTable = TA_DEF_Tables[i];      /* Identify the table size. */      funcDefTableSize = *TA_DEF_TablesSize[i];      for( j=0; j < funcDefTableSize; j++ )      {         funcDef = funcDefTable[j];         if( !funcDef || !funcDef->funcInfo )            return TA_INTERNAL_ERROR(3);         funcInfo = funcDef->funcInfo;               if( !funcInfo )            return TA_INTERNAL_ERROR(4);	         (*functionToCall)( funcInfo, opaqueData );      }   }   return TA_SUCCESS;}TA_RetCode TA_FuncTableAlloc( const char *group, TA_StringTable **table ){   TA_RetCode retCode;   unsigned int i;   TA_StringTable *stringTable;   unsigned int groupId; /* TA_GroupId */   unsigned int groupSize;   const char *stringPtr;   TA_StringTablePriv *stringTablePriv;   if( (group == NULL) || (table == NULL ) )   {      return TA_BAD_PARAM;   }   *table = NULL;   stringPtr = NULL;   /* Get information on the group. */   retCode = getGroupId( group, &groupId );   if( retCode != TA_SUCCESS )   {      return retCode;   }   retCode = getGroupSize( (TA_GroupId)groupId, &groupSize );   if( retCode != TA_SUCCESS )   {      return retCode;   }   /* Allocate the table. */   stringTable = (TA_StringTable *)TA_Malloc( sizeof(TA_StringTable) + sizeof(TA_StringTablePriv) );   if( !stringTable )   {      *table = NULL;      return TA_ALLOC_ERR;   }   memset( stringTable, 0, sizeof(TA_StringTable) + sizeof(TA_StringTablePriv) );   stringTablePriv = (TA_StringTablePriv *)(((char *)stringTable)+sizeof(TA_StringTable));   stringTablePriv->magicNumber = TA_STRING_TABLE_FUNC_MAGIC_NB;   stringTable->hiddenData = stringTablePriv;   /* From this point, TA_FuncTableFree can be safely called. */   stringTable->size = groupSize;   if( groupSize != 0 )   {      stringTable->string = (const char **)TA_Malloc( (stringTable->size) *                                                      sizeof(const char *) );      if( stringTable->string == NULL )      {         *table = NULL;         TA_FuncTableFree( stringTable );         return TA_ALLOC_ERR;      }      memset( (void *)stringTable->string, 0,              (stringTable->size) * sizeof(const char *) );      for( i=0; i < stringTable->size; i++ )      {         retCode = getFuncNameByIdx( (TA_GroupId)groupId, i, &stringPtr );         if( retCode != TA_SUCCESS )         {            *table = NULL;            TA_FuncTableFree( stringTable );            return TA_ALLOC_ERR;         }         (stringTable->string)[i] = stringPtr;      }   }   /* Return the table to the caller. */   *table = stringTable;   return TA_SUCCESS;}TA_RetCode TA_FuncTableFree( TA_StringTable *table ){   TA_StringTablePriv *stringTablePriv;   if( table )   {      stringTablePriv = (TA_StringTablePriv *)table->hiddenData;      if( !stringTablePriv )      {         return TA_INTERNAL_ERROR(3);      }         if( stringTablePriv->magicNumber != TA_STRING_TABLE_FUNC_MAGIC_NB )      {         return TA_BAD_OBJECT;      }      if( table->string )         TA_Free( (void *)table->string );      TA_Free( table );   }   return TA_SUCCESS;}TA_RetCode TA_GetFuncHandle( const char *name, const TA_FuncHandle **handle ){   char firstChar, tmp;   const TA_FuncDef **funcDefTable;   const TA_FuncDef *funcDef;   const TA_FuncInfo *funcInfo;   unsigned int i, funcDefTableSize;   /* A TA_FuncHandle is internally a TA_FuncDef. Let's find it    * by using the alphabetical tables.    */   if( (name == NULL) || (handle == NULL) )   {      return TA_BAD_PARAM;   }   *handle = NULL;   firstChar = name[0];   if( firstChar == '\0' )   {      return TA_BAD_PARAM;   }   tmp = (char)tolower( firstChar );   if( (tmp < 'a') || (tmp > 'z') )   {      return TA_FUNC_NOT_FOUND;   }   /* Identify the table. */   tmp -= (char)'a';   funcDefTable = TA_DEF_Tables[(int)tmp];   /* Identify the table size. */   funcDefTableSize = *TA_DEF_TablesSize[(int)tmp];   if( funcDefTableSize < 1 )   {      return TA_FUNC_NOT_FOUND;   }   /* Iterate all entries of the table and return as soon as found. */   for( i=0; i < funcDefTableSize; i++ )   {      funcDef = funcDefTable[i];      if( !funcDef || !funcDef->funcInfo )         return TA_INTERNAL_ERROR(3);      funcInfo = funcDef->funcInfo;            if( !funcInfo )         return TA_INTERNAL_ERROR(4);            if( strcmp( funcInfo->name, name ) == 0 )      {         *handle = (TA_FuncHandle *)funcDef;         return TA_SUCCESS;      }   }   return TA_FUNC_NOT_FOUND;}TA_RetCode TA_GetFuncInfo(  const TA_FuncHandle *handle,                            const TA_FuncInfo **funcInfo ){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -