我正在丢失我的大理石。 [英] I'm losing my marble.
问题描述
今天不是一个好日子,集中精力。我正在尝试做一些真正应该简单的事情,但是我找不到办法。
我有一堆位图图像,各种大小,每个都有自己的静态
缓冲区。我想要一个静态结构,让我将名称
与缓冲区相关联,这样我就可以访问文件了。通过名字。
我确定这是非常明显的,而且我看到它不是因为它不是因为b
流感。在此期间,我可以买一条线索吗?
-
#include< standard.disclaimer>
_
Kevin D Quitt USA 91387-4454所有统计数据的96.37%组成
根据FCA,此地址可能不会添加到任何商业邮件列表中
Today is not a good day, concentration-wise. I''m trying to do something
that really ought to be simple, but I can''t find a way.
I have a bunch of bit-map images, of various sizes, each in its own static
buffer. I want to have a static structure that lets me associate the name
with the buffers, so I can access the "files" by name.
I''m sure it''s blindingly obvious, and that I''d see it were it not for the
flu. In the meantime, though, can I buy a clue?
--
#include <standard.disclaimer>
_
Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
Per the FCA, this address may not be added to any commercial mail list
推荐答案
Kevin D Quitt写道:
Kevin D Quitt wrote:
我有一堆各种尺寸的位图图像,每个图像都有自己的静态
缓冲。我希望有一个静态结构,让我将名称
与缓冲区相关联,这样我就可以访问文件了。按名称。
I have a bunch of bit-map images, of various sizes, each in its own static
buffer. I want to have a static structure that lets me associate the name
with the buffers, so I can access the "files" by name.
静态结构{
const char * name;
const char * bitmap;
} bitmaps [] = {
{" first",first_buffer},
{" second",second_buffer},
};
static struct {
const char *name;
const char *bitmap;
} bitmaps[] = {
{"first", first_buffer},
{"second", second_buffer},
};
2003年12月11日星期四,Kevin D. Quitt写道:
On Thu, 11 Dec 2003, Kevin D. Quitt wrote:
今天不是一个好日子,集中精力。我正在努力做一些真的应该很简单的事情,但我找不到办法。
我有一堆各种尺寸的位图图像,每个都在自己的静态缓冲区。我希望有一个静态结构,让我将名称
与缓冲区相关联,这样我就可以访问文件了。按名称。
Today is not a good day, concentration-wise. I''m trying to do something
that really ought to be simple, but I can''t find a way.
I have a bunch of bit-map images, of various sizes, each in its own static
buffer. I want to have a static structure that lets me associate the name
with the buffers, so I can access the "files" by name.
听起来有人'再次编程太多Perl,或者说是
Lisp,或其他什么。 :-)无论如何,我认为*你想要的是
类似于[UNTESTED CODE]的东西:
struct Bitmap;
struct LookupEntry {
char * name;
struct Bitmap * file;
};
struct LookupTable {
int ntable;
struct LookupEntry table [100];
};
struct LookupEntry * add(struct LookupTable * tab,char * name,
struct Bitmap * file)
{
char * tmp;
if(tab-> ntable> = 100)返回NULL;
tmp = malloc(strlen(name)+ 1);
如果(tmp == NULL)返回NULL;
strcpy(tmp,name);
tab-> table [ tab-> ntable] .name = tmp;
tab-> table [tab-> ntable] .file = file;
++ tab-> ntable;
return& tab-> table [tab-> ntable - 1];
}
struct LookupEntry * find(struct LookupTable * tab,char * name)
{
int i;
for(i = 0;我<制表> ntable; ++ i){
char * tmp = tab-> table [tab-> ntable] .name;
if(tmp == NULL)continue;
if(0 == strcmp(tmp,name))
return& tab-> table [i];
}
返回NULL;
}
int delete(struct LookupTable * tab,struct LookupEntry * entry)
{
int idx =(entry - tab-> table);
free(entry-> name);
- tab-> ntable;
for(i = idx; i< tab-> ntable; ++ i){
tab-> table [i] = tab-> table [i + 1];
}
返回0; / *成功删除* /
}
int main()
{
struct LookupTable mytab = {0 };
struct LookupEntry * ent;
add(& mytab," foo.bmp",NULL);
ent = find (& mytab," bar.bmp");
if(ent)
delete(& mytab,ent);
返回0;
}
用二叉树或哈希表或其他东西替换线性表,如果你想要更好的渐近性能,可以用
。并检查错误。 ;-)
HTH,
-Arthur
Sounds like someone''s been programming too much Perl again, or
Lisp, or something. :-) Anyway, I *think* what you''re wanting is
something along the lines of [UNTESTED CODE]:
struct Bitmap;
struct LookupEntry {
char *name;
struct Bitmap *file;
};
struct LookupTable {
int ntable;
struct LookupEntry table[100];
};
struct LookupEntry *add(struct LookupTable *tab, char *name,
struct Bitmap *file)
{
char *tmp;
if (tab->ntable >= 100) return NULL;
tmp = malloc(strlen(name)+1);
if (tmp == NULL) return NULL;
strcpy(tmp, name);
tab->table[tab->ntable].name = tmp;
tab->table[tab->ntable].file = file;
++tab->ntable;
return &tab->table[tab->ntable - 1];
}
struct LookupEntry *find(struct LookupTable *tab, char *name)
{
int i;
for (i=0; i < tab->ntable; ++i) {
char *tmp = tab->table[tab->ntable].name;
if (tmp == NULL) continue;
if (0 == strcmp(tmp, name))
return &tab->table[i];
}
return NULL;
}
int delete(struct LookupTable *tab, struct LookupEntry *entry)
{
int idx = (entry - tab->table);
free(entry->name);
--tab->ntable;
for (i=idx; i < tab->ntable; ++i) {
tab->table[i] = tab->table[i+1];
}
return 0; /* successful deletion */
}
int main()
{
struct LookupTable mytab = {0};
struct LookupEntry *ent;
add(&mytab, "foo.bmp", NULL);
ent = find(&mytab, "bar.bmp");
if (ent)
delete(&mytab, ent);
return 0;
}
Replace the linear table by a binary tree or a hash table or something,
if you want better asymptotic performance. And check for bugs. ;-)
HTH,
-Arthur
2003年12月11日星期四15: 42:59 -0500(EST),Arthur J. O'Dwyer
< aj*@nospam.andrew.cmu.edu>写道:
On Thu, 11 Dec 2003 15:42:59 -0500 (EST), "Arthur J. O''Dwyer"
<aj*@nospam.andrew.cmu.edu> wrote:
听起来像某人'再次编程太多Perl,或者说Lisp,或者其他什么。 : - )
Sounds like someone''s been programming too much Perl again, or
Lisp, or something. :-)
对他们中的任何一个都太长了。感谢两位(快速)响应者。
这是嵌入式系统的帮助屏幕。我想定义一个定义每个屏幕的
层次结构,包括带有多个表示的按钮
(例如按下)和一个函数
与每个按钮相关联。
这不是操纵它的代码,我只是无法获得一切
声明。幸运的是,我的那部分愚蠢已经消失了。如果有人感兴趣的话,这就是我想出来的。
------- 8< ---- ---
#ifndef _BUTTON_H_
#define _BUTTON_H_
typedef unsigned char uchar;
typedef enum
{SC_EXIT,SC_Main,SC_Wireless,SC_DotQuad,SC_ESSID}屏幕;
//按钮定义尺寸和哪个,可能4,要显示的图像
typedef struct
{
size_t cols,rows; //像素
int current; //如果有多个图像集,哪个?
int active; //使用主动而非空闲
uchar * idle [2]; //小学和初级备用闲置视图
uchar * actv [2]; //小学和初级替代活动视图
}按钮;
// ButtonOp定义给定按钮的操作:它位于
//屏幕上,其中活动触摸值,要调用的函数,以及用于它的图像。
typedef struct _ButtonOp
{
int tp,lp; //左上角像素
int tt,lt,bt,rt; //左上角,右下角触摸
SCREEN(* touchFunc)(struct _ButtonOp *,int,int,int);
按钮*按钮;
} ButtonOp;
// MenuScreen定义整个屏幕。
typedef struct
{
SCREEN theScreen;
int bcolor;
int tf,tb;
void(* initFunc)(void);
int按钮;
ButtonOp *按钮[20];
} MenuScreen;
extern MenuScreen MainScreen;
#endif
----> 8 ----
这里是一个精简的屏幕定义版本:
---- 8< ----
#include< stdio.h>
#include< ; stdlib.h>
#include" button.h"
static void sc1_initFunc(void);
static SCREEN sc1_bf1(ButtonOp * theBop,int ht,int vt,int up);
extern uchar sc1_b1i [],sc1_b1a [];
静态按钮sc1_b1 = {100,40,0,0,{sc1_b1i},{sc1_b1a}};
静态ButtonOp SC1_BB1 = {20,20,1,1, 2,5,sc1_bf1,& sc1_b1};
MenuScreen MainScreen =
{
SC_Main,0,0,0 ,sc1_initFunc,1,{& SC1_BB1}
};
static void sc1_initFunc(void)
{
返回;
}
静态SCREEN sc1_bf1(ButtonOp * theBop,int ht,int vt,int up)
{
(void)theBop;(void)ht;(void)vt;(void)up;
返回SC_DotQuad;
}
//在现实世界中,这些不是字符串,而是原始位图。
static uchar sc1_b1i [] =" sc1_b1i";
static uchar sc1_b1a [] =" sc1_b1a";
----> 8 ----
- -
#include< standard.disclaimer>
_
Kevin D Quitt USA 91387-4454所有统计数据的96.37%组成
根据FCA,此地址可能不会添加到任何商业邮件列表中
Been too long for either of them. Thanks to both (quick) responders.
This is to be help screens for an embedded system. I want to define a
hierarchical set of structures that define each screen, including buttons
with multiple representations (being pressed, e.g.), and a function
associated with each button.
It wasn''t the code for manipulating it, I just couldn''t get everything
declared. Fortunately, that part of my stupidity has cleared. Here''s
what I came up with in case anybody''s interested.
-------8<-------
#ifndef _BUTTON_H_
#define _BUTTON_H_
typedef unsigned char uchar;
typedef enum
{ SC_EXIT, SC_Main, SC_Wireless, SC_DotQuad, SC_ESSID } SCREEN;
// Button defines size and which, of possibly 4, image to display
typedef struct
{
size_t cols, rows; // Pixels
int current; // If more than one set of images, which?
int active; // Use active rather than idle
uchar *idle[ 2 ]; // Primary & alternate idle view
uchar *actv[ 2 ]; // Primary & alternate active view
} Button;
// ButtonOp defines the operation of a given button: where it is on
// screen, its active touch values, the function to be called, and the
// images to use for it.
typedef struct _ButtonOp
{
int tp, lp; // Top left pixel
int tt, lt, bt, rt; // Top left, bottom right touch
SCREEN (*touchFunc)(struct _ButtonOp *, int, int, int);
Button *button;
} ButtonOp;
// MenuScreen defines the entire screen.
typedef struct
{
SCREEN theScreen;
int bcolor;
int tf, tb;
void (*initFunc)(void);
int buttons;
ButtonOp *button[ 20 ];
} MenuScreen;
extern MenuScreen MainScreen;
#endif
---->8----
And here''s a stripped-down version of a screen definition:
----8<----
#include <stdio.h>
#include <stdlib.h>
#include "button.h"
static void sc1_initFunc( void );
static SCREEN sc1_bf1( ButtonOp *theBop, int ht, int vt, int up );
extern uchar sc1_b1i[], sc1_b1a[];
static Button sc1_b1 = { 100, 40, 0, 0, {sc1_b1i}, {sc1_b1a}};
static ButtonOp SC1_BB1 = { 20, 20, 1, 1, 2, 5, sc1_bf1, &sc1_b1 };
MenuScreen MainScreen =
{
SC_Main, 0, 0, 0, sc1_initFunc, 1, { &SC1_BB1 }
};
static void sc1_initFunc( void )
{
return;
}
static SCREEN sc1_bf1( ButtonOp *theBop, int ht, int vt, int up )
{
(void)theBop;(void)ht;(void)vt;(void)up;
return SC_DotQuad;
}
// In the real world, these are not strings, but raw bitmaps.
static uchar sc1_b1i[] = "sc1_b1i";
static uchar sc1_b1a[] = "sc1_b1a";
---->8----
--
#include <standard.disclaimer>
_
Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
Per the FCA, this address may not be added to any commercial mail list
这篇关于我正在丢失我的大理石。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!